Ejemplo n.º 1
0
def get_bouquet(path, name, bq_type):
    """ Parsing services ids from bouquet file """
    with open(path + "userbouquet.{}.{}".format(name, bq_type),
              encoding="utf-8",
              errors="replace") as file:
        chs_list = file.read()
        services = []
        srvs = list(filter(None,
                           chs_list.split("\n#SERVICE")))  # filtering ['']
        for ch in srvs[1:]:
            ch_data = ch.strip().split(":")
            if ch_data[1] == "64":
                services.append(
                    BouquetService(ch_data[-1].split("\n")[0],
                                   BqServiceType.MARKER, ch, ch_data[2]))
            elif "http" in ch:
                services.append(
                    BouquetService(ch_data[-1].split("\n")[0],
                                   BqServiceType.IPTV, ch, 0))
            else:
                fav_id = "{}:{}:{}:{}".format(ch_data[3], ch_data[4],
                                              ch_data[5], ch_data[6])
                name = None
                if len(ch_data) == 12:
                    name, desc = str(ch_data[-1]).split("\n#DESCRIPTION")
                services.append(
                    BouquetService(name, BqServiceType.DEFAULT, fav_id, 0))

    return srvs[0].lstrip("#NAME").strip(), services
Ejemplo n.º 2
0
    def get_bouquet(path, bq_name, bq_type, prefix="userbouquet"):
        """ Parsing services ids from bouquet file. """
        with open(path + "{}.{}.{}".format(prefix, bq_name, bq_type),
                  encoding="utf-8",
                  errors="replace") as file:
            chs_list = file.read()
            services = []
            srvs = list(filter(None,
                               chs_list.split("\n#SERVICE")))  # filtering ['']
            # May come across empty[wrong] files!
            if not srvs:
                log("Bouquet file 'userbouquet.{}.{}' is empty or wrong!".
                    format(bq_name, bq_type))
                return "{} [empty]".format(bq_name), services

            bq_name = srvs.pop(0)

            for num, srv in enumerate(srvs, start=1):
                srv_data = srv.strip().split(":")
                s_type = srv_data[1]
                if s_type == "64":
                    m_data, sep, desc = srv.partition("#DESCRIPTION")
                    services.append(
                        BouquetService(desc.strip() if desc else "",
                                       BqServiceType.MARKER, srv, num))
                elif s_type == "832":
                    m_data, sep, desc = srv.partition("#DESCRIPTION")
                    services.append(
                        BouquetService(desc.strip() if desc else "",
                                       BqServiceType.SPACE, srv, num))
                elif s_type == "134":
                    alt = re.match(BouquetsReader._ALT_PAT, srv)
                    if alt:
                        alt_name, alt_type = alt.group(1), alt.group(2)
                        alt_bq_name, alt_srvs = BouquetsReader.get_bouquet(
                            path, alt_name, alt_type, "alternatives")
                        services.append(
                            BouquetService(alt_bq_name, BqServiceType.ALT,
                                           alt_name, tuple(alt_srvs)))
                elif srv_data[0].strip(
                ) in BouquetsReader._STREAM_TYPES or srv_data[10].startswith(
                    ("http", "rtsp")):
                    stream_data, sep, desc = srv.partition("#DESCRIPTION")
                    desc = desc.lstrip(
                        ":").strip() if desc else srv_data[-1].strip()
                    services.append(
                        BouquetService(desc, BqServiceType.IPTV, srv, num))
                else:
                    fav_id = "{}:{}:{}:{}".format(srv_data[3], srv_data[4],
                                                  srv_data[5], srv_data[6])
                    name = None
                    if len(srv_data) == 12:
                        name, sep, desc = str(
                            srv_data[-1]).partition("\n#DESCRIPTION")
                    services.append(
                        BouquetService(name, BqServiceType.DEFAULT,
                                       fav_id.upper(), num))

        return bq_name.lstrip("#NAME").strip(), services
Ejemplo n.º 3
0
def append_bouquets(bq_type,
                    bq_view,
                    callback,
                    fav_id_index,
                    index,
                    model,
                    names,
                    s_type,
                    wait_dialog=None):
    bq_index = 0 if s_type is SettingsType.ENIGMA_2 else 1
    bq_view.expand_row(Gtk.TreePath(bq_index), 0)
    bqs_model = bq_view.get_model()
    bouquets_names = get_bouquets_names(bqs_model)

    for pos, name in enumerate(sorted(names)):
        if name not in bouquets_names:
            services = [
                BouquetService(None, BqServiceType.DEFAULT, row[fav_id_index],
                               0) for row in model if row[index] == name
            ]
            callback(
                Bouquet(name=name,
                        type=bq_type,
                        services=services,
                        locked=None,
                        hidden=None), bqs_model.get_iter(bq_index))

    if wait_dialog is not None:
        wait_dialog.destroy()
Ejemplo n.º 4
0
    def get_refs_from_xml(path):
        """ Returns tuple from references and description. """
        refs = []
        dom = parse(path)
        description = "".join(n.data + "\n" for n in dom.childNodes if n.nodeType == Node.COMMENT_NODE)

        for elem in dom.getElementsByTagName("channels"):
            c_count = 0
            comment_count = 0
            current_data = ""

            if elem.hasChildNodes():
                for n in elem.childNodes:
                    if n.nodeType == Node.COMMENT_NODE:
                        c_count += 1
                        comment_count += 1
                        txt = n.data.strip()
                        if comment_count:
                            comment_count -= 1
                        else:
                            ref_data = current_data.split(":")
                            refs.append(BouquetService(name=txt,
                                                       type=BqServiceType.DEFAULT,
                                                       data="{}:{}:{}:{}".format(*ref_data[3:7]).upper(),
                                                       num="{}:{}:{}".format(*ref_data[3:6]).upper()))

                    if n.hasChildNodes():
                        for s_node in n.childNodes:
                            if s_node.nodeType == Node.TEXT_NODE:
                                comment_count -= 1
                                current_data = s_node.data
        return refs, description
Ejemplo n.º 5
0
def get_bouquet(path, bq_name, bq_type):
    """ Parsing services ids from bouquet file. """
    with open(path + "userbouquet.{}.{}".format(bq_name, bq_type),
              encoding="utf-8",
              errors="replace") as file:
        chs_list = file.read()
        services = []
        srvs = list(filter(None,
                           chs_list.split("\n#SERVICE")))  # filtering ['']
        # May come across empty[wrong] files!
        if not srvs:
            log("Bouquet file 'userbouquet.{}.{}' is empty or wrong!".format(
                bq_name, bq_type))
            return "{} [empty]".format(bq_name), services

        bq_name = srvs.pop(0)

        for num, srv in enumerate(srvs, start=1):
            srv_data = srv.strip().split(":")
            if srv_data[1] == "64":
                m_data, sep, desc = srv.partition("#DESCRIPTION")
                services.append(
                    BouquetService(desc.strip() if desc else "",
                                   BqServiceType.MARKER, srv, num))
            elif srv_data[1] == "832":
                m_data, sep, desc = srv.partition("#DESCRIPTION")
                services.append(
                    BouquetService(desc.strip() if desc else "",
                                   BqServiceType.SPACE, srv, num))
            elif "http" in srv or srv_data[0] == "8193":
                stream_data, sep, desc = srv.partition("#DESCRIPTION")
                desc = desc.lstrip(
                    ":").strip() if desc else srv_data[-1].strip()
                services.append(
                    BouquetService(desc, BqServiceType.IPTV, srv, num))
            else:
                fav_id = "{}:{}:{}:{}".format(srv_data[3], srv_data[4],
                                              srv_data[5], srv_data[6])
                name = None
                if len(srv_data) == 12:
                    name, sep, desc = str(
                        srv_data[-1]).partition("\n#DESCRIPTION")
                services.append(
                    BouquetService(name, BqServiceType.DEFAULT, fav_id.upper(),
                                   num))

    return bq_name.lstrip("#NAME").strip(), services
Ejemplo n.º 6
0
def gen_bouquets(view, bq_view, transient, gen_type, s_type, callback):
    """ Auto-generate and append list of bouquets. """
    model, paths = view.get_selection().get_selected_rows()
    single_types = (BqGenType.SAT, BqGenType.PACKAGE, BqGenType.TYPE)
    if gen_type in single_types:
        if not is_only_one_item_selected(paths, transient):
            return

    fav_id_index = Column.SRV_FAV_ID
    index = Column.SRV_TYPE
    if gen_type in (BqGenType.PACKAGE, BqGenType.EACH_PACKAGE):
        index = Column.SRV_PACKAGE
    elif gen_type in (BqGenType.SAT, BqGenType.EACH_SAT):
        index = Column.SRV_POS

    # Splitting services [caching] by column value.
    s_data = defaultdict(list)
    for row in model:
        s_data[row[index]].append(
            BouquetService(None, BqServiceType.DEFAULT, row[fav_id_index], 0))

    bq_type = BqType.BOUQUET.value if s_type is SettingsType.NEUTRINO_MP else BqType.TV.value
    bq_index = 0 if s_type is SettingsType.ENIGMA_2 else 1
    bq_root_iter = bq_view.get_model().get_iter(bq_index)
    srv = Service(*model[paths][:Column.SRV_TOOLTIP])
    cond = srv.package if gen_type is BqGenType.PACKAGE else srv.pos if gen_type is BqGenType.SAT else srv.service_type
    bq_view.expand_row(Gtk.TreePath(bq_index), 0)

    bq_names = get_bouquets_names(bq_view.get_model())

    if gen_type in single_types:
        if cond in bq_names:
            show_dialog(DialogType.ERROR, transient,
                        "A bouquet with that name exists!")
        else:
            callback(Bouquet(cond, bq_type, s_data.get(cond)), bq_root_iter)
    else:
        # We add a bouquet only if the given name is missing [keys - names]!
        for name in sorted(s_data.keys() - bq_names):
            callback(Bouquet(name, BqType.TV.value, s_data.get(name)),
                     bq_root_iter)
Ejemplo n.º 7
0
    def on_save_to_xml(self, item):
        response = show_dialog(DialogType.CHOOSER,
                               self._dialog,
                               settings=self._settings)
        if response in (Gtk.ResponseType.CANCEL,
                        Gtk.ResponseType.DELETE_EVENT):
            return

        services = []
        iptv_types = (BqServiceType.IPTV.value, BqServiceType.MARKER.value)
        for r in self._bouquet_model:
            srv_type = r[Column.FAV_TYPE]
            if srv_type in iptv_types:
                srv = BouquetService(name=r[Column.FAV_SERVICE],
                                     type=BqServiceType(srv_type),
                                     data=r[Column.FAV_ID],
                                     num=r[Column.FAV_NUM])
                services.append(srv)

        ChannelsParser.write_refs_to_xml(
            "{}{}.xml".format(response, self._bouquet_name), services)
        self.show_info_message(get_message("Done!"), Gtk.MessageType.INFO)
Ejemplo n.º 8
0
    def get_bouquet(path, bq_name, bq_type, prefix="userbouquet"):
        """ Parsing services ids from bouquet file. """
        with open(f"{path}{prefix}.{bq_name}.{bq_type}",
                  encoding="utf-8",
                  errors="replace") as file:
            chs_list = file.read()
            services = []
            srvs = list(filter(None,
                               chs_list.split("\n#SERVICE")))  # filtering ['']
            # May come across empty[wrong] files!
            if not srvs:
                log(f"Bouquet file 'userbouquet.{bq_name}.{bq_type}' is empty or wrong!"
                    )
                return f"{bq_name} [empty]", services

            bq_name = srvs.pop(0)

            for num, srv in enumerate(srvs, start=1):
                srv_data = srv.strip().split(":")
                data_len = len(srv_data)
                if data_len < 10:
                    log(f"The bouquet [{bq_name}] service [{num}] has the wrong data format: [{srv}]"
                        )
                    continue

                s_type = ServiceType(srv_data[1])
                if s_type is ServiceType.MARKER:
                    m_data, sep, desc = srv.partition("#DESCRIPTION")
                    services.append(
                        BouquetService(desc.strip() if desc else "",
                                       BqServiceType.MARKER, srv, num))
                elif s_type is ServiceType.SPACE:
                    m_data, sep, desc = srv.partition("#DESCRIPTION")
                    services.append(
                        BouquetService(desc.strip() if desc else "",
                                       BqServiceType.SPACE, srv, num))
                elif s_type is ServiceType.ALT:
                    alt = re.match(BouquetsReader._ALT_PAT, srv)
                    if alt:
                        alt_name, alt_type = alt.group(1), alt.group(2)
                        alt_bq_name, alt_srvs = BouquetsReader.get_bouquet(
                            path, alt_name, alt_type, "alternatives")
                        services.append(
                            BouquetService(alt_bq_name, BqServiceType.ALT,
                                           alt_name, tuple(alt_srvs)))
                elif s_type is ServiceType.BOUQUET:
                    sub = re.match(BouquetsReader._SUB_BQ_PAT, srv)
                    if sub:
                        sub_name, sub_type = sub.group(1), sub.group(2)
                        sub_bq_name, sub_srvs = BouquetsReader.get_bouquet(
                            path, sub_name, sub_type, "subbouquet")
                        bq = Bouquet(sub_bq_name, sub_type, tuple(sub_srvs),
                                     None, None, sub_name)
                        services.append(
                            BouquetService(sub_bq_name, BqServiceType.BOUQUET,
                                           bq, num))
                elif srv_data[0].strip(
                ) in BouquetsReader._STREAM_TYPES or srv_data[10].startswith(
                    ("http", "rtsp")):
                    stream_data, sep, desc = srv.partition("#DESCRIPTION")
                    desc = desc.lstrip(
                        ":").strip() if desc else srv_data[-1].strip()
                    services.append(
                        BouquetService(desc, BqServiceType.IPTV, srv, num))
                else:
                    fav_id = f"{srv_data[3]}:{srv_data[4]}:{srv_data[5]}:{srv_data[6]}"
                    name = None
                    if data_len == 12:
                        name, sep, desc = str(
                            srv_data[-1]).partition("\n#DESCRIPTION")
                    services.append(
                        BouquetService(name, BqServiceType.DEFAULT,
                                       fav_id.upper(), num))

        return bq_name.lstrip("#NAME").strip(), services