# -*- coding: utf-8 -*- from Screens.Screen import Screen from Components.Label import Label from Components.ActionMap import ActionMap from Plugins.Plugin import PluginDescriptor from Screens.MessageBox import MessageBox from enigma import eDVBDB, getDesktop import requests import json import shutil import re sz_w = getDesktop(0).size().width() class C3vocScreen (Screen): if sz_w == 1920: skin = """ """ else: skin = """ """ def __init__ (self, session): self.session = session Screen.__init__(self, session) self["myText"] = Label(_("Update the c3voc stream bouquet?")) self["myRedBtn"] = Label(_("Cancel")) self["myGreenBtn"] = Label(_("OK")) self["myActionsMap"] = ActionMap(["SetupActions", "ColorActions"], { "ok": self.getinput, "green": self.getinput, "red": self.close, "cancel": self.close, }, -1) def getinput(self): try: req = requests.session() page = req.get("https://streaming.media.ccc.de/streams/v2.json", headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36'}) if page.status_code == 404: self.session.open(MessageBox, _("c3voc stream information file not found"), MessageBox.TYPE_INFO, timeout=4) data = json.loads(page.content) with open("/tmp/c3voc.tv", "w") as myfile: myfile.write("#NAME c3voc (TV)\n") myfile.close() for conference in data: conference_name = conference["conference"] for group in conference["groups"]: rooms = group["rooms"] if not rooms: continue for room in rooms: hlsstreams = room["streams"] for stream in hlsstreams: if not stream["slug"].startswith("hd-"): continue url = stream["urls"]["hls"]["url"] display_name = stream["display"] page = req.get(url, headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36'}) if page.status_code == 404: self.session.open(MessageBox, _("%s is not sending this moment. please try later") % str(display_name), MessageBox.TYPE_INFO, timeout=4) page.content streamurl = None streamurl = re.findall('#EXT-X-STREAM-INF.*?\n(.*?)\n', page.content, re.S) if streamurl: if not streamurl[0].startswith('http'): if "/" in streamurl[0]: streamurl = url.rsplit('/',1)[0]+'/'+streamurl[0] else: streamurl = url.rsplit('/',1)[0]+'/'+url.rsplit('/',1)[1].split('_',1)[0]+'/'+streamurl[0] else: streamurl = streamurl[0] with open("/tmp/c3voc.tv", "a") as myfile: myfile.write("#SERVICE 4097:0:1:0:0:0:0:0:0:0:%s\n#DESCRIPTION %s, %s\n" % (streamurl.replace(":", "%3a"), conference_name, display_name)) myfile.close() if 'c3voc' not in open('/etc/enigma2/bouquets.tv').read(): with open("/etc/enigma2/bouquets.tv", "a") as mybouquets: mybouquets.write("#SERVICE 1:7:1:0:0:0:0:0:0:0:FROM BOUQUET \"userbouquet.c3voc__tv_.tv\" ORDER BY bouquet") mybouquets.close() shutil.move("/tmp/c3voc.tv","/etc/enigma2/userbouquet.c3voc__tv_.tv") eDVBDB.getInstance().reloadBouquets() self.session.open(MessageBox, _("c3voc stream bouquet updated"), MessageBox.TYPE_INFO, timeout=4) except: pass self.close() def main(session, **kwargs): session.open(C3vocScreen) def Plugins(**kwargs): return PluginDescriptor(name="C3vocUpdater rC3", description="update the c3voc stream bouquet", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)