Пример #1
0
 def get_service(self, fav_id, data_id, transponder):
     freq, rate, pol, fec, system, pos = self.get_transponder_values()
     return Service(
         flags_cas=self.get_flags(),
         transponder_type=self._old_service.transponder_type,
         coded=CODED_ICON if self._cas_entry.get_text() else None,
         service=self._name_entry.get_text(),
         locked=self._old_service.locked,
         hide=HIDE_ICON if self._hide_check_button.get_active() else None,
         package=self._package_entry.get_text(),
         service_type=SERVICE_TYPE.get(self._srv_type_entry.get_text(),
                                       SERVICE_TYPE["3"]),
         picon=self._old_service.picon,
         picon_id=self._reference_entry.get_text().replace(":", "_") +
         ".png",
         ssid="{:04x}".format(int(self._sid_entry.get_text())),
         freq=freq,
         rate=rate,
         pol=pol,
         fec=fec,
         system=system,
         pos=pos,
         data_id=data_id,
         fav_id=fav_id,
         transponder=transponder)
Пример #2
0
    def parse_sat_transponder(self, sat, sat_pos, tr_elem):
        tr_attr = get_xml_attributes(tr_elem)
        tr = SP.join("{}{}{}".format(k, KSP, v) for k, v in tr_attr.items())
        tr_id = tr_attr.get("id", "0").lstrip("0")
        on = tr_attr.get("on", "0")
        freq = tr_attr.get("frq", "0")
        rate = tr_attr.get("sr", "0")
        fec = tr_attr.get("fec", "0")

        pol = POLARIZATION.get(tr_attr.get("pol", "0"))
        # Formatting displayed values.
        try:
            freq = "{}".format(int(freq) // 1000)
            rate = "{}".format(int(rate) // 1000)
        except ValueError as e:
            log("Neutrino parsing error [parse_transponder]: {}".format(e))

        for srv_elem in tr_elem.getElementsByTagName("S"):
            if srv_elem.hasAttributes():
                at = get_xml_attributes(srv_elem)
                at["api"] = self._api
                ssid, name, s_type, sys = at.get("i", "0"), at.get(
                    "n", ""), at.get("t", "3"), at.get("s", "0")
                data_id = SP.join("{}{}{}".format(k, KSP, v)
                                  for k, v in at.items())
                fav_id = "{}:{}:{}".format(tr_id, on.lstrip("0"),
                                           ssid.lstrip("0"))
                picon_id = "{}{}{}.png".format(tr_id, on, ssid)
                prv = PROVIDER.get(int(on, 16), "")
                st = SERVICE_TYPE.get(str(int(s_type, 16)),
                                      SERVICE_TYPE.get("-2"))

                srv = Service(sat, TrType.Satellite.value, None, name, None,
                              None, prv, st, None, picon_id,
                              ssid, freq, rate, pol, FEC.get(fec),
                              SYSTEM.get(sys), sat_pos, data_id, fav_id, tr)
                self._services.append(srv)
Пример #3
0
    def parse_ct_transponder(self, terr, tr_elem, tr_type):
        attrs = get_xml_attributes(tr_elem)
        tr = SP.join("{}{}{}".format(k, KSP, v) for k, v in attrs.items())
        tr_id, on, freq = attrs.get("id", "0").lstrip("0"), attrs.get(
            "on", "0"), attrs.get("frq", "0")

        for srv_elem in tr_elem.getElementsByTagName("S"):
            if srv_elem.hasAttributes():
                s_at = get_xml_attributes(srv_elem)
                s_at["api"] = self._api
                ssid, name, s_type, sys = s_at.get("i", "0"), s_at.get(
                    "n", ""), s_at.get("t", "3"), s_at.get("s", "0")
                data_id = SP.join("{}{}{}".format(k, KSP, v)
                                  for k, v in s_at.items())
                fav_id = "{}:{}:{}".format(tr_id, on.lstrip("0"),
                                           ssid.lstrip("0"))
                picon_id = "{}{}{}.png".format(tr_id, on, ssid)
                prv = PROVIDER.get(int(on, 16), "")
                st = SERVICE_TYPE.get(str(int(s_type, 16)),
                                      SERVICE_TYPE.get("-2"))

                if tr_type is TrType.Terrestrial:
                    sys = T_SYSTEM.get(sys)
                    pos = "T"
                elif tr_type is TrType.Cable:
                    sys = SystemCable(sys).name
                    pos = "C"
                else:
                    log("Parse transponder error: Not supported type [{}]".
                        format(tr_type))
                    break

                srv = Service(terr, tr_type.value, None, name, None, None, prv,
                              st, None, picon_id, ssid, freq, "0", None, None,
                              sys, pos, data_id, fav_id, tr)
                self._services.append(srv)
Пример #4
0
    def get_transponder_services(self,
                                 tr_url,
                                 sat_position=None,
                                 use_pids=False):
        """ Returns services for given transponder.

            @param tr_url: transponder URL.
            @param sat_position: custom satellite position. Sometimes required to adjust the namespace.
            @param use_pids: if possible use additional pids [video, audio].
        """
        services = []
        try:
            self.init_data(tr_url)
        except ValueError as e:
            log(e)
        else:
            pos, freq, sr, fec, pol, namespace, tid, nid = sat_position or 0, 0, 0, 0, 0, 0, 0, 0
            sys = "DVB-S"
            pos_found = False
            tr = None
            # Transponder
            for r in filter(lambda x: x and 6 < len(x) < 9, self._rows):
                if not pos_found:
                    pos_tr = re.match(self._POS_PAT, r[0].text)
                    if not pos_tr:
                        continue

                    if not sat_position:
                        pos = int(
                            SatellitesParser.get_position("".join(
                                c for c in pos_tr.group(1)
                                if c.isdigit() or c.isalpha())))

                    pos_found = True

                if pos_found:
                    text = " ".join(c.text for c in r[1:])
                    td = re.match(self._TR_PAT, text)
                    if td:
                        freq, pol = int(td.group(1)), get_key_by_value(
                            POLARIZATION, td.group(2))
                        if td.group(5):
                            log("Detected T2-MI transponder!")
                            continue

                        sys, mod, sr, _fec, = td.group(3), td.group(
                            4), td.group(6), td.group(7)
                        nid, tid = td.group(8), td.group(9)

                        neg_pos = False  # POS = W
                        # For negative (West) positions: 3600 - numeric position value!!!
                        namespace = "{:04x}0000".format(
                            3600 - pos if neg_pos else pos)
                        inv = 2  # Default
                        fec = get_key_by_value(FEC, _fec)
                        sys = get_key_by_value(SYSTEM, sys)
                        tr_flag = 1
                        mod = get_key_by_value(MODULATION, mod)
                        roll_off = 0  # 35% DVB-S2/DVB-S (default)
                        pilot = 2  # Auto
                        s2_flags = "" if sys == "DVB-S" else self._S2_TR.format(
                            tr_flag, mod or 0, roll_off, pilot)
                        nid, tid = int(nid), int(tid)
                        tr = self._TR.format(freq, sr, pol, fec, pos, inv, sys,
                                             s2_flags)

            if not tr:
                msg = "ServicesParser error [get transponder services]: {}"
                er = "Transponder [{}] not found or its type [T2-MI, etc] not supported yet.".format(
                    freq)
                log(msg.format(er))
                return []

            # Services
            for r in filter(
                    lambda x: x and len(x) == 12 and (x[0].text.isdigit()),
                    self._rows):
                sid, name, s_type, v_pid, a_pid, cas, pkg = r[0].text, r[
                    2].text, r[4].text, r[5].text.strip(), r[6].text.split(
                    ), r[9].text, r[10].text.strip()

                try:
                    s_type = self._S_TYPES.get(s_type, "3")  # 3 = Data
                    _s_type = SERVICE_TYPE.get(
                        s_type, SERVICE_TYPE.get("3"))  # str repr
                    sid = int(sid)
                    data_id = "{:04x}:{}:{:04x}:{:04x}:{}:0:0".format(
                        sid, namespace, tid, nid, s_type)
                    fav_id = "{}:{}:{}:{}".format(sid, tid, nid, namespace)
                    picon_id = "1_0_{:X}_{}_{}_{}_{}_0_0_0.png".format(
                        int(s_type), sid, tid, nid, namespace)
                    # Flags.
                    flags = "p:{}".format(pkg)
                    cas = ",".join(
                        get_key_by_value(CAS, c) or "C:0000"
                        for c in cas.split()) if cas else None
                    if use_pids:
                        v_pid = "c:00{:04x}".format(
                            int(v_pid)) if v_pid else None
                        a_pid = ",".join(
                            ["c:01{:04x}".format(int(p))
                             for p in a_pid]) if a_pid else None
                        flags = ",".join(
                            filter(None, (flags, v_pid, a_pid, cas)))
                    else:
                        flags = ",".join(filter(None, (flags, cas)))

                    services.append(
                        Service(flags, "s", None, name, None, None, pkg,
                                _s_type, r[1].img, picon_id, sid, freq, sr,
                                pol, fec, sys, pos, data_id, fav_id, tr))
                except ValueError as e:
                    log("ServicesParser error [get transponder services]: {}".
                        format(e))

        return services
Пример #5
0
    def get_kingofsat_services(self, sat_position=None, use_pids=False):
        services = []
        # Transponder
        tr = list(
            filter(
                lambda r: len(r) == 13 and r[4].url and r[4].url.startswith(
                    "tp.php?tp="), self._rows))
        if not tr:
            log(f"ServicesParser error [get transponder services]: Transponder [{self._t_url}] not found!"
                )
            return services

        tr, multi_tr, tid, nid, nsp = None, None, None, None, None
        freq, sr, pol, fec, sys, pos = None, None, None, None, None, None

        for r in filter(lambda x: len(x) > 12, self._rows):
            r_size = len(r)
            if r_size == 13 and r[4].url and r[4].url.startswith("tp.php?tp="):
                res = re.match(self._KING_TR_PAT, f"{r[6].text} {r[7].text}")
                if not res:
                    continue

                sys, mod = res.group(1), res.group(5)
                s_pos, freq, pol, sr_fec = r[0].text, r[2].text, r[3].text, r[
                    8].text
                nid, tid = r[10].text, r[11].text

                pos = sat_position
                if not sat_position:
                    pos_tr = re.match(self._POS_PAT, s_pos)
                    if pos_tr:
                        pos = self.get_position(pos_tr.group(1))

                sr, fec = sr_fec.split()
                pol = get_key_by_value(POLARIZATION, pol)
                sys, mod, fec, nsp, s2_flags, roll_off, pilot, inv = self.get_transponder_data(
                    pos, fec, sys, mod)
                freq, nid, tid = int(float(freq)), int(nid), int(tid)
                tr = self._TR.format(freq, sr, pol, fec, pos, inv, sys,
                                     s2_flags)

                pls_mode, is_code, is_id = self._pls_modes.get(
                    res.group(3), None), res.group(4), res.group(6)
                multi_tr = f"{tr}:{is_id}:{is_code}:{pls_mode}" if all(
                    (pls_mode, is_code, is_id)) else None
                tid = int(is_id) if multi_tr else tid

                if res.group(2):
                    log(f"Detected T2-MI transponder! [{freq} {sr}]")

                if multi_tr:
                    log(f"Detected multi-stream transponder! [{freq} {sr}]")

            if tr and r_size == 14 and not r[1].text and r[7].text and r[
                    7].text.isdigit():
                if r[1].img == "/radio.gif":
                    s_type = ""
                elif r[8].img == "/hd.gif":
                    s_type = "HEVC HD"
                elif r[1].img == "/data.gif":
                    s_type = "Data"
                else:
                    s_type = "SD"

                s_type = self._S_TYPES.get(s_type, "3")
                _s_type = SERVICE_TYPE.get(s_type, SERVICE_TYPE.get("3"))

                name, pkg, cas, sid, v_pid, a_pid = r[2].text, r[5].text, r[
                    6].text, r[7].text, None, None
                flags, sid, fav_id, picon_id, data_id = self.get_service_data(
                    s_type, pkg, sid, tid, nid, nsp, v_pid, a_pid, cas,
                    use_pids)
                services.append(
                    Service(flags, "s", None, name,
                            None, None, pkg, _s_type, None, picon_id, sid,
                            str(freq), sr, pol, fec, sys, pos, data_id, fav_id,
                            multi_tr or tr))

        return services
Пример #6
0
    def get_lyngsat_services(self, sat_position=None, use_pids=False):
        services = []
        pos, freq, sr, fec, pol, nsp, tid, nid = sat_position or 0, 0, 0, 0, 0, 0, 0, 0
        sys = "DVB-S"
        pos_found = False
        tr = None
        # Multi-stream.
        multi_tr = None
        multi = False
        # Transponder.
        for r in filter(lambda x: x and 6 < len(x) < 9, self._rows):
            if not pos_found:
                pos_tr = re.match(self._POS_PAT, r[0].text)
                if not pos_tr:
                    continue

                if not sat_position:
                    pos = self.get_position(pos_tr.group(1))
                pos_found = True

            if pos_found:
                text = " ".join(c.text for c in r[1:])
                td = re.match(self._TR_PAT, text)
                if td:
                    freq, pol = int(td.group(1)), get_key_by_value(
                        POLARIZATION, td.group(2))
                    sys, mod, sr, _fec, = td.group(3), td.group(4), td.group(
                        7), td.group(8)
                    nid, tid = td.group(9), td.group(10)
                    sys, mod, fec, nsp, s2_flags, roll_off, pilot, inv = self.get_transponder_data(
                        pos, _fec, sys, mod)
                    nid, tid = int(nid), int(tid)

                    if td.group(5):
                        log(f"Detected T2-MI transponder! [{freq} {sr} {pol}]")

                    if td.group(6):
                        log(f"Detected multi-stream transponder! [{freq} {sr} {pol}]"
                            )
                        multi = True

                    tr = self._TR.format(freq, sr, pol, fec, pos, inv, sys,
                                         s2_flags)

        if not tr:
            er = f"Transponder [{self._t_url}] not found or its type [T2-MI, etc] not supported yet."
            log(f"ServicesParser error [get transponder services]: {er}")
            return services

        # Services.
        for r in filter(None, self._rows):
            if multi and r[0].url:
                res = re.match(self._MULTI_PAT, r[0].url)
                if res:
                    pls_mode, is_code, is_id = self._pls_modes.get(
                        res.group(1), None), res.group(2), res.group(3)
                    multi_tr = f"{tr}:{is_id}:{is_code}:{pls_mode}" if all(
                        (pls_mode, is_code, is_id)) else None
                    tid = int(is_id) if multi_tr else tid

            if len(r) == 12 and r[0].text.isdigit():
                sid, name, s_type, v_pid, a_pid, cas, pkg = r[0].text, r[
                    2].text, r[4].text, r[5].text.strip(), r[6].text.split(
                    ), r[9].text, r[10].text.strip()
                try:
                    s_type = self._S_TYPES.get(s_type, "3")  # 3 = Data
                    _s_type = SERVICE_TYPE.get(
                        s_type, SERVICE_TYPE.get("3"))  # str repr
                    flags, sid, fav_id, picon_id, data_id = self.get_service_data(
                        s_type, pkg, sid, tid, nid, nsp, v_pid, a_pid, cas,
                        use_pids)
                    services.append(
                        Service(flags, "s", None, name, None, None, pkg,
                                _s_type, r[1].img, picon_id, sid, freq, sr,
                                pol, fec, sys, pos, data_id, fav_id, multi_tr
                                or tr))
                except ValueError as e:
                    log(f"ServicesParser error [get transponder services]: {e}"
                        )

        return services