Пример #1
0
def get_enigma2_bouquet(path):
    path, sep, f_name = path.rpartition("userbouquet.")
    name, sep, suf = f_name.rpartition(".")
    bq = BouquetsReader.get_bouquet(path, name, suf)
    bouquet = Bouquet(name=bq[0],
                      type=BqType(suf).value,
                      services=bq[1],
                      locked=None,
                      hidden=None)
    return bouquet
Пример #2
0
    def write(self):
        line = []

        for bqs in self._bouquets:
            line.clear()
            line.append(f"#NAME {bqs.name}\n")
            bq_file_names = {b.file for b in bqs.bouquets}
            count = 1
            m_count = 0

            for bq in bqs.bouquets:
                bq_name = bq.file
                if not bq_name:
                    if self._force_bq_names:
                        bq_name = re.sub(self._NAME_PATTERN, "_", bq.name)
                    else:
                        bq_name = f"de{count:02d}"
                        while bq_name in bq_file_names:
                            count += 1
                            bq_name = f"de{count:02d}"
                        bq_file_names.add(bq_name)

                bq_type = BqType(bq.type)
                if bq_type is BqType.MARKER:
                    m_data = bq.file.split(":") if bq.file else None
                    b_name = m_data[-1].strip() if m_data else bq.name.lstrip(
                        _MARKER_PREFIX)
                    line.append(self._MARKER.format(m_count, b_name))
                    m_count += 1
                else:
                    if bq_type is BqType.BOUQUET:
                        bq_name = re.sub(self._NAME_PATTERN, "_", bq.name)
                        self.write_sub_bouquet(self._path, bq_name, bq,
                                               bqs.type)
                    else:
                        self.write_bouquet(
                            f"{self._path}userbouquet.{bq_name}.{bqs.type}",
                            bq.name, bq.services)
                    line.append(
                        self._SERVICE.format(
                            2 if bqs.type == BqType.RADIO.value else 1,
                            bq_name, bqs.type))

            with open(f"{self._path}bouquets.{bqs.type}",
                      "w",
                      encoding="utf-8",
                      newline="\n") as file:
                file.writelines(line)
Пример #3
0
def import_bouquet(transient,
                   model,
                   path,
                   settings,
                   services,
                   appender,
                   file_path=None):
    """ Import of single bouquet """
    itr = model.get_iter(path)
    bq_type = BqType(model.get(itr, Column.BQ_TYPE)[0])
    pattern, f_pattern = None, None
    profile = settings.setting_type

    if profile is SettingsType.ENIGMA_2:
        pattern = ".{}".format(bq_type.value)
        f_pattern = "userbouquet.*{}".format(pattern)
    elif profile is SettingsType.NEUTRINO_MP:
        pattern = "webtv.xml" if bq_type is BqType.WEBTV else "bouquets.xml"
        f_pattern = "bouquets.xml"
        if bq_type is BqType.TV:
            f_pattern = "ubouquets.xml"
        elif bq_type is BqType.WEBTV:
            f_pattern = "webtv.xml"

    file_path = file_path or get_chooser_dialog(transient, settings,
                                                "bouquet files", (f_pattern, ))
    if file_path == Gtk.ResponseType.CANCEL:
        return

    if not str(file_path).endswith(pattern):
        show_dialog(DialogType.ERROR,
                    transient,
                    text="No bouquet file is selected!")
        return

    if profile is SettingsType.ENIGMA_2:
        bq = get_enigma2_bouquet(file_path)
        imported = list(
            filter(
                lambda x: x.data in services or x.type is BqServiceType.IPTV,
                bq.services))

        if len(imported) == 0:
            show_dialog(
                DialogType.ERROR,
                transient,
                text="The main list does not contain services for this bouquet!"
            )
            return

        if model.iter_n_children(itr):
            appender(bq, itr)
        else:
            p_itr = model.iter_parent(itr)
            appender(bq, p_itr) if p_itr else appender(bq, itr)
    elif profile is SettingsType.NEUTRINO_MP:
        if bq_type is BqType.WEBTV:
            bqs = parse_webtv(file_path, "WEBTV", bq_type.value)
        else:
            bqs = get_neutrino_bouquets(file_path, "", bq_type.value)
        file_path = "{}/".format(Path(file_path).parent)
        ImportDialog(transient, file_path, settings, services.keys(),
                     lambda b, s: appender(b), (bqs, )).show()