Пример #1
0
    def get_services(self):
        dom = XmlHandler.parse(self._path)

        for root in dom.getElementsByTagName("zapit"):
            if root.hasAttributes():
                api = root.attributes["api"]
                self._api = api.value if api else self._api

            for elem in root.getElementsByTagName("sat"):
                if elem.hasAttributes():
                    sat_attrs = get_xml_attributes(elem)
                    sat_pos = 0
                    try:
                        sat_pos = int(sat_attrs.get("position", "0"))
                        sat_pos = "{:0.1f}{}".format(
                            abs(sat_pos / 10), "W" if sat_pos < 0 else "E")
                    except ValueError as e:
                        log("Neutrino parsing error [parse sat position]: {}".
                            format(e))
                    sat = SP.join("{}{}{}".format(k, KSP, v)
                                  for k, v in sat_attrs.items())
                    for tr_elem in elem.getElementsByTagName("TS"):
                        if tr_elem.hasAttributes():
                            self.parse_sat_transponder(sat, sat_pos, tr_elem)

            # Terrestrial DVB-T[2].
            for elem in root.getElementsByTagName("terrestrial"):
                if elem.hasAttributes():
                    terr_attrs = get_xml_attributes(elem)
                    terr = SP.join("{}{}{}".format(k, KSP, v)
                                   for k, v in terr_attrs.items())

                    for tr_elem in elem.getElementsByTagName("TS"):
                        if tr_elem.hasAttributes():
                            self.parse_ct_transponder(terr, tr_elem,
                                                      TrType.Terrestrial)

            # Cable.
            for elem in root.getElementsByTagName("cable"):
                if elem.hasAttributes():
                    cable_attrs = get_xml_attributes(elem)
                    cable = SP.join("{}{}{}".format(k, KSP, v)
                                    for k, v in cable_attrs.items())

                    for tr_elem in elem.getElementsByTagName("TS"):
                        if tr_elem.hasAttributes():
                            self.parse_ct_transponder(cable, tr_elem,
                                                      TrType.Cable)

        return self._services
Пример #2
0
 def get_flags(self):
     if self._s_type is SettingsType.ENIGMA_2:
         return self.get_enigma2_flags()
     elif self._s_type is SettingsType.NEUTRINO_MP:
         flags = get_attributes(self._old_service.flags_cas)
         flags["position"] = self.get_sat_position()
         return SP.join("{}{}{}".format(k, KSP, v)
                        for k, v in flags.items())
Пример #3
0
    def get_satellite_transponder_data(self):
        sys = self._sys_combo_box.get_active_id()
        freq = "{}000".format(self._freq_entry.get_text())
        rate = "{}000".format(self._rate_entry.get_text())
        pol = self.get_value_from_combobox_id(self._pol_combo_box,
                                              POLARIZATION)
        fec = self.get_value_from_combobox_id(self._fec_combo_box, FEC_DEFAULT)
        sat_pos = self.get_sat_position()

        inv = get_value_by_name(Inversion,
                                self._invertion_combo_box.get_active_id())
        srv_sys = "0"  # !!!

        if self._s_type is SettingsType.ENIGMA_2:
            dvb_s_tr = self._ENIGMA2_TRANSPONDER_DATA.format(
                "s", freq, rate, pol, fec, sat_pos, inv, srv_sys)
            if sys == "DVB-S":
                return dvb_s_tr
            if sys == "DVB-S2":
                flag = self._tr_flag_entry.get_text()
                mod = self.get_value_from_combobox_id(self._mod_combo_box,
                                                      MODULATION)
                roll_off = self.get_value_from_combobox_id(
                    self._rolloff_combo_box, ROLL_OFF)
                pilot = get_value_by_name(
                    Pilot, self._pilot_combo_box.get_active_id())
                pls_mode = self.get_value_from_combobox_id(
                    self._pls_mode_combo_box, PLS_MODE)
                pls_code = self._pls_code_entry.get_text()
                st_id = self._stream_id_entry.get_text()
                pls = ":{}:{}:{}".format(
                    st_id, pls_code,
                    pls_mode) if pls_mode and pls_code and st_id else ""

                return "{}:{}:{}:{}:{}{}".format(dvb_s_tr, flag, mod, roll_off,
                                                 pilot, pls)
        elif self._s_type is SettingsType.NEUTRINO_MP:
            tr_data = get_attributes(self._old_service.transponder)
            tr_data["frq"] = freq
            tr_data["sr"] = rate
            tr_data["pol"] = pol
            tr_data["fec"] = fec
            tr_data["on"] = "{:04x}".format(
                int(self._network_id_entry.get_text()))
            tr_data["id"] = "{:04x}".format(
                int(self._transponder_id_entry.get_text()))
            tr_data["inv"] = inv

            return SP.join("{}{}{}".format(k, KSP, v)
                           for k, v in tr_data.items())
Пример #4
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)
Пример #5
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)
Пример #6
0
def parse_bouquets(file, name, bq_type):
    bouquets = Bouquets(name=name, type=bq_type, bouquets=[])
    if not os.path.exists(file):
        return bouquets

    dom = XmlHandler.parse(file)

    for elem in dom.getElementsByTagName("Bouquet"):
        if elem.hasAttributes():
            bq_attrs = get_xml_attributes(elem)
            bq_name = bq_attrs.get("name", "")
            hidden = bq_attrs.get("hidden", "0")
            locked = bq_attrs.get("locked", "0")
            services = []
            for srv_elem in elem.getElementsByTagName("S"):
                if srv_elem.hasAttributes():
                    s_attrs = get_xml_attributes(srv_elem)
                    ssid = s_attrs.get("i", "0")
                    on = s_attrs.get("on", "0")
                    tr_id = s_attrs.get("t", "0")
                    fav_id = "{}:{}:{}".format(tr_id, on, ssid)
                    services.append(
                        BouquetService(None, BqServiceType.DEFAULT, fav_id, 0))
            bouquets[2].append(
                Bouquet(name=bq_name,
                        type=bq_type,
                        services=services,
                        locked=LOCKED_ICON if locked == "1" else None,
                        hidden=HIDE_ICON if hidden == "1" else None,
                        file=SP.join("{}{}{}".format(k, KSP, v)
                                     for k, v in bq_attrs.items())))

    if BqType(bq_type) is BqType.BOUQUET:
        for bq in bouquets.bouquets:
            if bq.services:
                key = int(bq.services[0].data.split(":")[1], 16)
                if key not in PROVIDER:
                    pos, sep, name = bq.name.partition("]")
                    PROVIDER[key] = name

    return bouquets
Пример #7
0
    def get_srv_data(self):
        ssid = int(self._sid_entry.get_text())
        net_id, tr_id = int(self._network_id_entry.get_text()), int(
            self._transponder_id_entry.get_text())
        service_type = self._srv_type_entry.get_text()

        if self._s_type is SettingsType.ENIGMA_2:
            namespace = int(self._namespace_entry.get_text())
            data_id = self._ENIGMA2_DATA_ID.format(ssid, namespace, tr_id,
                                                   net_id, service_type, 0)
            fav_id = self._ENIGMA2_FAV_ID.format(ssid, tr_id, net_id,
                                                 namespace)
            return fav_id, data_id
        elif self._s_type is SettingsType.NEUTRINO_MP:
            data = get_attributes(self._old_service.data_id)
            data["n"] = self._name_entry.get_text()
            data["t"] = "{:x}".format(int(service_type))
            data["i"] = "{:04x}".format(ssid)
            fav_id = self._NEUTRINO_FAV_ID.format(tr_id, net_id, ssid)
            return fav_id, SP.join("{}{}{}".format(k, KSP, v)
                                   for k, v in data.items())
Пример #8
0
    def update_transponder_services(self, transponder, sat_pos):
        for itr in self._transponder_services_iters:
            srv = self._current_model[itr][:]
            srv[Column.SRV_FREQ], srv[Column.SRV_RATE], srv[
                Column.SRV_POL], srv[Column.SRV_FEC], srv[
                    Column.SRV_SYSTEM], srv[
                        Column.SRV_POS] = self.get_transponder_values()
            srv[Column.SRV_TRANSPONDER] = transponder

            fav_id = srv[Column.SRV_FAV_ID]
            old_srv = self._services.pop(fav_id, None)
            if not old_srv:
                log("Update transponder services error: No service found for ID {}"
                    .format(srv[Column.SRV_FAV_ID]))
                continue

            if self._s_type is SettingsType.NEUTRINO_MP:
                flags = get_attributes(srv[Column.SRV_CAS_FLAGS])
                flags["position"] = sat_pos
                srv[Column.SRV_CAS_FLAGS] = SP.join("{}{}{}".format(k, KSP, v)
                                                    for k, v in flags.items())

            self._services[fav_id] = Service(*srv[:Column.SRV_TOOLTIP])
            self._current_model.set_row(itr, srv)