From 3aa29a788dd1a3dd31e1bafe6ae1af91d770835b Mon Sep 17 00:00:00 2001 From: DYefremov Date: Wed, 1 May 2019 17:21:51 +0300 Subject: [PATCH] added groups support by export to m3u --- app/eparser/iptv.py | 14 +++++++++----- app/ui/main_app_window.py | 14 +++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/eparser/iptv.py b/app/eparser/iptv.py index 42573d9a..93860f29 100644 --- a/app/eparser/iptv.py +++ b/app/eparser/iptv.py @@ -57,17 +57,21 @@ def parse_m3u(path, profile): def export_to_m3u(path, bouquet): pattern = re.compile(".*:(http.*):.*") lines = ["#EXTM3U\n"] + current_grp = None for s in bouquet.services: - bq_type = s.type - if bq_type is BqServiceType.IPTV: + s_type = s.type + if s_type is BqServiceType.IPTV: res = re.match(pattern, s.data) if not res: continue data = res.group(1) - lines.append("#EXTINF:-1,{}\n{}\n".format(s.name, urllib.request.unquote(data.strip()))) - elif bq_type is BqServiceType.MARKER: - pass + lines.append("#EXTINF:-1,{}\n".format(s.name)) + if current_grp: + lines.append(current_grp) + lines.append("{}\n".format(urllib.request.unquote(data.strip()))) + elif s_type is BqServiceType.MARKER: + current_grp = "#EXTGRP:{}\n".format(s.name) with open(path + "{}.m3u".format(bouquet.name), "w", encoding="utf-8") as file: file.writelines(lines) diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index 707ec628..0dbc8e00 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -1357,7 +1357,7 @@ class Application(Gtk.Application): return bq = self._bouquets.get(self._bq_selected) - EpgDialog(self._main_window, self._options.get(self._profile), self._services, bq, self._fav_model).show() + EpgDialog(self._main_window, self._options.get(self._profile), self._services, bq, self._fav_model).show() # ***************** Import ********************# @@ -1397,8 +1397,16 @@ class Application(Gtk.Application): self.show_error_dialog("This list does not contains IPTV streams!") return - path = self._options.get(self._profile).get("data_dir_path", "") - export_to_m3u(path, Bouquet(self._current_bq_name, None, bq_services, None, None)) + response = show_dialog(DialogType.CHOOSER, self._main_window, options=self._options.get(self._profile)) + if response in (Gtk.ResponseType.CANCEL, Gtk.ResponseType.DELETE_EVENT): + return + + try: + export_to_m3u(response, Bouquet(self._current_bq_name, None, bq_services, None, None)) + except Exception as e: + self.show_error_dialog(str(e)) + else: + show_dialog(DialogType.INFO, self._main_window, "Done!") def on_import_bouquet(self, item): profile = Profile(self._profile)