added groups support by export to m3u

This commit is contained in:
DYefremov
2019-05-01 17:21:51 +03:00
parent 55b0dccc80
commit 3aa29a788d
2 changed files with 20 additions and 8 deletions

View File

@@ -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)

View File

@@ -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)