From 95069bbf24547d6c9a4f9c2fe1bc6953c39092be Mon Sep 17 00:00:00 2001 From: DYefremov Date: Sun, 23 Jun 2019 23:25:03 +0300 Subject: [PATCH] refactoring of getting fav id --- app/eparser/iptv.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/eparser/iptv.py b/app/eparser/iptv.py index 4f5a3c89..2c67a53f 100644 --- a/app/eparser/iptv.py +++ b/app/eparser/iptv.py @@ -27,7 +27,7 @@ def parse_m3u(path, profile): groups = set() counter = 0 name = None - fav_id = None + for line in file.readlines(): if line.startswith("#EXTINF"): name = line[1 + line.index(","):].strip() @@ -41,12 +41,7 @@ def parse_m3u(path, profile): services.append(mr) elif not line.startswith("#"): url = line.strip() - if profile is Profile.ENIGMA_2: - url = urllib.request.quote(line.strip()) - stream_type = StreamType.NONE_TS.value - fav_id = ENIGMA2_FAV_ID_FORMAT.format(stream_type, 1, 0, 0, 0, 0, url, name, name, None) - elif profile is Profile.NEUTRINO_MP: - fav_id = NEUTRINO_FAV_ID_FORMAT.format(url, "", 0, None, None, None, None, "", "", 1) + fav_id = get_fav_id(url, name, profile) if name and url: srv = Service(None, None, IPTV_ICON, name, *aggr[0:3], BqServiceType.IPTV.name, *aggr, fav_id, None) services.append(srv) @@ -77,5 +72,15 @@ def export_to_m3u(path, bouquet, profile): file.writelines(lines) +def get_fav_id(url, service_name, profile): + """ Returns fav id depending on the profile. """ + if profile is Profile.ENIGMA_2: + url = urllib.request.quote(url) + stream_type = StreamType.NONE_TS.value + return ENIGMA2_FAV_ID_FORMAT.format(stream_type, 1, 0, 0, 0, 0, url, service_name, service_name, None) + elif profile is Profile.NEUTRINO_MP: + return NEUTRINO_FAV_ID_FORMAT.format(url, "", 0, None, None, None, None, "", "", 1) + + if __name__ == "__main__": pass