From b5dabf65c78cc89825cdefefe5c09adaf11b92f5 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Fri, 16 Nov 2018 23:08:40 +0300 Subject: [PATCH] added groups import support for m3u --- app/eparser/iptv.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/eparser/iptv.py b/app/eparser/iptv.py index ff104b9c..f0328ccc 100644 --- a/app/eparser/iptv.py +++ b/app/eparser/iptv.py @@ -8,6 +8,7 @@ from .ecommons import BqServiceType, Service # url, description, urlkey, account, usrname, psw, s_type, iconsrc, iconsrc_b, group NEUTRINO_FAV_ID_FORMAT = "{}::{}::{}::{}::{}::{}::{}::{}::{}::{}" ENIGMA2_FAV_ID_FORMAT = " {}:0:{}:{:X}:{:X}:{:X}:{:X}:0:0:0:{}:{}\n#DESCRIPTION: {}\n" +MARKER_FORMAT = " 1:64:{}:0:0:0:0:0:0:0::{}\n#DESCRIPTION {}\n" class StreamType(Enum): @@ -18,12 +19,22 @@ class StreamType(Enum): def parse_m3u(path, profile): with open(path) as file: aggr = [None] * 10 - channels = [] + services = [] + groups = set() + counter = 0 name = None fav_id = None for line in file.readlines(): if line.startswith("#EXTINF"): name = line[1 + line.index(","):].strip() + elif line.startswith("#EXTGRP") and profile is Profile.ENIGMA_2: + grp_name = line.strip("#EXTGRP:").strip() + if grp_name not in groups: + groups.add(grp_name) + fav_id = MARKER_FORMAT.format(counter, grp_name, grp_name) + counter += 1 + mr = Service(None, None, None, grp_name, *aggr[0:3], BqServiceType.MARKER.name, *aggr, fav_id, None) + services.append(mr) elif not line.startswith("#"): if profile is Profile.ENIGMA_2: fav_id = ENIGMA2_FAV_ID_FORMAT.format(StreamType.NONE_TS.value, 1, 0, 0, 0, 0, @@ -31,9 +42,9 @@ def parse_m3u(path, profile): elif profile is Profile.NEUTRINO_MP: fav_id = NEUTRINO_FAV_ID_FORMAT.format(line.strip(), "", 0, None, None, None, None, "", "", 1) srv = Service(None, None, IPTV_ICON, name, *aggr[0:3], BqServiceType.IPTV.name, *aggr, fav_id, None) - channels.append(srv) + services.append(srv) - return channels + return services if __name__ == "__main__":