Files
DemonEditor/app/eparser/iptv.py

41 lines
1.4 KiB
Python
Raw Normal View History

2018-03-12 22:47:43 +03:00
""" Module for IPTV and streams support """
from enum import Enum
2018-02-12 13:34:00 +03:00
from app.properties import Profile
from app.ui.uicommons import IPTV_ICON
2018-01-01 23:42:40 +03:00
from .ecommons import BqServiceType, Service
2017-12-08 18:32:28 +03:00
2018-02-12 13:34:00 +03:00
# url, description, urlkey, account, usrname, psw, s_type, iconsrc, iconsrc_b, group
NEUTRINO_FAV_ID_FORMAT = "{}::{}::{}::{}::{}::{}::{}::{}::{}::{}"
2018-04-10 16:03:36 +03:00
ENIGMA2_FAV_ID_FORMAT = " {}:0:{}:{:X}:{:X}:{:X}:{:X}:0:0:0:{}:{}\n#DESCRIPTION: {}\n"
2018-03-12 22:47:43 +03:00
class StreamType(Enum):
DVB_TS = "1"
NONE_TS = "4097"
2017-12-08 18:32:28 +03:00
2018-02-12 13:34:00 +03:00
def parse_m3u(path, profile):
2017-12-08 18:32:28 +03:00
with open(path) as file:
2018-01-31 00:13:42 +03:00
aggr = [None] * 10
2017-12-08 18:32:28 +03:00
channels = []
name = None
2018-02-12 13:34:00 +03:00
fav_id = None
2017-12-08 18:32:28 +03:00
for line in file.readlines():
if line.startswith("#EXTINF"):
name = line[1 + line.index(","):].strip()
2018-11-16 22:35:47 +03:00
elif not line.startswith("#"):
2018-02-12 13:34:00 +03:00
if profile is Profile.ENIGMA_2:
2018-09-21 10:16:30 +03:00
fav_id = ENIGMA2_FAV_ID_FORMAT.format(StreamType.NONE_TS.value, 1, 0, 0, 0, 0,
2018-03-12 22:47:43 +03:00
line.strip().replace(":", "%3a"), name, name, None)
2018-02-12 13:34:00 +03:00
elif profile is Profile.NEUTRINO_MP:
fav_id = NEUTRINO_FAV_ID_FORMAT.format(line.strip(), "", 0, None, None, None, None, "", "", 1)
2018-02-12 14:27:21 +03:00
srv = Service(None, None, IPTV_ICON, name, *aggr[0:3], BqServiceType.IPTV.name, *aggr, fav_id, None)
2018-01-31 00:13:42 +03:00
channels.append(srv)
2017-12-08 18:32:28 +03:00
return channels
if __name__ == "__main__":
pass