mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 13:36:59 -05:00
commit
ce92e23373
@ -30,18 +30,28 @@ class EPGTypes():
|
|||||||
return epgdict
|
return epgdict
|
||||||
|
|
||||||
def get_thumbnail(self, itemtype, itemid):
|
def get_thumbnail(self, itemtype, itemid):
|
||||||
epgdict = self.get_epg()
|
|
||||||
if itemtype == "channel":
|
if itemtype == "channel":
|
||||||
for channel in list(epgdict.keys()):
|
chandict = self.find_channel_dict(itemid)
|
||||||
if epgdict[channel]["id"] == itemid:
|
return chandict["thumbnail"]
|
||||||
return epgdict[channel]["thumbnail"]
|
|
||||||
elif itemtype == "content":
|
elif itemtype == "content":
|
||||||
for channel in list(epgdict.keys()):
|
progdict = self.find_program_dict(itemid)
|
||||||
for progitem in epgdict[channel]["listing"]:
|
return progdict["thumbnail"]
|
||||||
if progitem["id"] == itemid:
|
|
||||||
return progitem["thumbnail"]
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def find_channel_dict(self, channel_id):
|
||||||
|
epgdict = self.get_epg()
|
||||||
|
channel_list = []
|
||||||
|
for channel in list(epgdict.keys()):
|
||||||
|
channel_list.append(epgdict[channel])
|
||||||
|
return next(item for item in channel_list if item["id"] == channel_id)
|
||||||
|
|
||||||
|
def find_program_dict(self, event_id):
|
||||||
|
epgdict = self.get_epg()
|
||||||
|
event_list = []
|
||||||
|
for channel in list(epgdict.keys()):
|
||||||
|
event_list.extend(epgdict[channel]["listing"])
|
||||||
|
return next(item for item in event_list if item["id"] == event_id)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
||||||
print("Updating " + self.epgtypename + " EPG cache file.")
|
print("Updating " + self.epgtypename + " EPG cache file.")
|
||||||
|
|||||||
@ -77,8 +77,8 @@ class ZapEPG():
|
|||||||
programguide[str(cdict['channelNo'])] = {
|
programguide[str(cdict['channelNo'])] = {
|
||||||
"callsign": cdict["callSign"],
|
"callsign": cdict["callSign"],
|
||||||
"name": cdict["name"] or cdict["callSign"], # TODO
|
"name": cdict["name"] or cdict["callSign"], # TODO
|
||||||
"number": cdict["channelNo"],
|
"number": str(cdict["channelNo"]),
|
||||||
"id": cdict["channelId"],
|
"id": str(cdict["channelId"]),
|
||||||
"thumbnail": str(cdict['thumbnail']).replace("//", "https://").split("?")[0],
|
"thumbnail": str(cdict['thumbnail']).replace("//", "https://").split("?")[0],
|
||||||
"listing": [],
|
"listing": [],
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ class ZapEPG():
|
|||||||
"seasonnumber": progdict['season'],
|
"seasonnumber": progdict['season'],
|
||||||
"episodenumber": progdict['episode'],
|
"episodenumber": progdict['episode'],
|
||||||
"isnew": False,
|
"isnew": False,
|
||||||
"id": progdict['id'] or self.xmltimestamp_zap(eventdict['startTime']),
|
"id": str(progdict['id'] or self.xmltimestamp_zap(eventdict['startTime'])),
|
||||||
}
|
}
|
||||||
|
|
||||||
for f in eventdict['filter']:
|
for f in eventdict['filter']:
|
||||||
|
|||||||
@ -65,6 +65,9 @@ class HDHR_Hub():
|
|||||||
def post_lineup_scan_start(self):
|
def post_lineup_scan_start(self):
|
||||||
self.station_scan.scan()
|
self.station_scan.scan()
|
||||||
|
|
||||||
|
def get_image(self, request_args):
|
||||||
|
return self.images.get_image(request_args)
|
||||||
|
|
||||||
|
|
||||||
hdhr = HDHR_Hub()
|
hdhr = HDHR_Hub()
|
||||||
|
|
||||||
@ -139,35 +142,8 @@ class HDHR_HTTP_Server():
|
|||||||
|
|
||||||
@app.route('/images', methods=['GET'])
|
@app.route('/images', methods=['GET'])
|
||||||
def images():
|
def images():
|
||||||
|
image, imagetype = hdhr.get_image(request.args)
|
||||||
if 'source' not in list(request.args.keys()):
|
return Response(image, content_type=imagetype, direct_passthrough=True)
|
||||||
image = hdhr.images.generate_image("content", "Unknown Request")
|
|
||||||
else:
|
|
||||||
|
|
||||||
itemtype = 'content'
|
|
||||||
if 'type' in list(request.args.keys()):
|
|
||||||
itemtype = request.args["type"]
|
|
||||||
|
|
||||||
if request.args['source'] == 'epg':
|
|
||||||
if 'id' in list(request.args.keys()):
|
|
||||||
req_dict = {
|
|
||||||
"source": request.args["source"],
|
|
||||||
"type": request.args["type"],
|
|
||||||
"id": request.args["id"],
|
|
||||||
}
|
|
||||||
image = hdhr.images.get_image(req_dict)
|
|
||||||
else:
|
|
||||||
itemmessage = "Unknown Request"
|
|
||||||
image = hdhr.images.generate_image(itemtype, itemmessage)
|
|
||||||
elif request.args['source'] == 'generate':
|
|
||||||
itemmessage = "Unknown Request"
|
|
||||||
if 'message' in list(request.args.keys()):
|
|
||||||
itemmessage = request.args["message"]
|
|
||||||
image = hdhr.images.generate_image(itemtype, itemmessage)
|
|
||||||
else:
|
|
||||||
itemmessage = "Unknown Request"
|
|
||||||
image = hdhr.images.generate_image(itemtype, itemmessage)
|
|
||||||
return Response(image, content_type=hdhr.images.get_image_type(image), direct_passthrough=True)
|
|
||||||
|
|
||||||
@app.route('/watch', methods=['GET'])
|
@app.route('/watch', methods=['GET'])
|
||||||
def watch():
|
def watch():
|
||||||
|
|||||||
@ -11,6 +11,31 @@ class imageHandler():
|
|||||||
self.config = settings
|
self.config = settings
|
||||||
self.epghandling = epghandling
|
self.epghandling = epghandling
|
||||||
|
|
||||||
|
def get_image(self, request_args):
|
||||||
|
|
||||||
|
if 'source' not in list(request_args.keys()):
|
||||||
|
image = self.generate_image("content", "Unknown Request")
|
||||||
|
|
||||||
|
elif request_args["source"] == "epg":
|
||||||
|
image = self.get_epg_image(request_args)
|
||||||
|
elif request_args["source"] == "generate":
|
||||||
|
image = self.generate_image(request_args["type"], request_args["message"])
|
||||||
|
else:
|
||||||
|
image = self.generate_image("content", "Unknown Request")
|
||||||
|
|
||||||
|
imagetype = self.get_image_type(image)
|
||||||
|
|
||||||
|
return image, imagetype
|
||||||
|
|
||||||
|
def get_epg_image(self, request_args):
|
||||||
|
imageUri = self.epghandling.get_thumbnail(request_args["type"], request_args["id"])
|
||||||
|
if not imageUri:
|
||||||
|
return self.generate_image(request_args["type"], request_args["id"])
|
||||||
|
|
||||||
|
req = requests.get(imageUri)
|
||||||
|
return req.content
|
||||||
|
# return self.generate_image(request_args["type"], request_args["id"])
|
||||||
|
|
||||||
def getSize(self, txt, font):
|
def getSize(self, txt, font):
|
||||||
testImg = PIL.Image.new('RGB', (1, 1))
|
testImg = PIL.Image.new('RGB', (1, 1))
|
||||||
testDraw = PIL.ImageDraw.Draw(testImg)
|
testDraw = PIL.ImageDraw.Draw(testImg)
|
||||||
@ -42,19 +67,6 @@ class imageHandler():
|
|||||||
img.save(s, 'png')
|
img.save(s, 'png')
|
||||||
return s.getvalue()
|
return s.getvalue()
|
||||||
|
|
||||||
def get_image(self, req_args):
|
|
||||||
|
|
||||||
imageUri = self.epghandling.get_thumbnail(req_args["type"], req_args["id"])
|
|
||||||
if not imageUri:
|
|
||||||
return self.generate_image(req_args["type"], req_args["id"])
|
|
||||||
|
|
||||||
try:
|
|
||||||
req = requests.get(imageUri)
|
|
||||||
return req.content
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
return self.generate_image(req_args["type"], req_args["id"])
|
|
||||||
|
|
||||||
def get_image_type(self, image_data):
|
def get_image_type(self, image_data):
|
||||||
header_byte = image_data[0:3].hex().lower()
|
header_byte = image_data[0:3].hex().lower()
|
||||||
if header_byte == '474946':
|
if header_byte == '474946':
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class xmlTV_XML():
|
|||||||
self.config = settings
|
self.config = settings
|
||||||
self.epghandling = epghandling
|
self.epghandling = epghandling
|
||||||
|
|
||||||
def get_xmltv_xml(self, base_url):
|
def get_xmltv_xml(self, base_url, force_update=False):
|
||||||
|
|
||||||
epgdict = self.epghandling.epgtypes.get_epg()
|
epgdict = self.epghandling.epgtypes.get_epg()
|
||||||
return self.create_xmltv(base_url, epgdict)
|
return self.create_xmltv(base_url, epgdict)
|
||||||
@ -58,9 +58,9 @@ class xmlTV_XML():
|
|||||||
sub_el(c_out, 'display-name', text=epgdict[c]['name'])
|
sub_el(c_out, 'display-name', text=epgdict[c]['name'])
|
||||||
|
|
||||||
if epgdict[c]["thumbnail"] is not None:
|
if epgdict[c]["thumbnail"] is not None:
|
||||||
sub_el(c_out, 'icon', src=("http://" + str(base_url) + "/images?source=epg&type=channel&id=" + epgdict[c]['id']))
|
sub_el(c_out, 'icon', src=("http://" + str(base_url) + "/images?source=epg&type=channel&id=" + str(epgdict[c]['id'])))
|
||||||
else:
|
else:
|
||||||
sub_el(c_out, 'icon', src=("http://" + str(base_url) + "/images?source=generate&message=" + epgdict[c]['number']))
|
sub_el(c_out, 'icon', src=("http://" + str(base_url) + "/images?source=generate&message=" + str(epgdict[c]['number'])))
|
||||||
|
|
||||||
for channelnum in list(epgdict.keys()):
|
for channelnum in list(epgdict.keys()):
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ class xmlTV_XML():
|
|||||||
text='S%02dE%02d' % (s_, e_))
|
text='S%02dE%02d' % (s_, e_))
|
||||||
|
|
||||||
if program["thumbnail"]:
|
if program["thumbnail"]:
|
||||||
sub_el(prog_out, 'icon', src=("http://" + str(base_url) + "/images?source=epg&type=content&id=" + program['id']))
|
sub_el(prog_out, 'icon', src=("http://" + str(base_url) + "/images?source=epg&type=content&id=" + str(program['id'])))
|
||||||
else:
|
else:
|
||||||
sub_el(prog_out, 'icon', src=("http://" + str(base_url) + "/images?source=generate&message=" + program['title'].replace(" ", "")))
|
sub_el(prog_out, 'icon', src=("http://" + str(base_url) + "/images?source=generate&message=" + program['title'].replace(" ", "")))
|
||||||
|
|
||||||
|
|||||||
@ -137,7 +137,7 @@ class fHDHRservice():
|
|||||||
"callsign": cdict["callsign"],
|
"callsign": cdict["callsign"],
|
||||||
"name": cdict["name"] or cdict["callsign"],
|
"name": cdict["name"] or cdict["callsign"],
|
||||||
"number": cdict["number"],
|
"number": cdict["number"],
|
||||||
"id": cdict["id"],
|
"id": str(cdict["id"]),
|
||||||
"thumbnail": self.get_channel_thumbnail(cdict['id']),
|
"thumbnail": self.get_channel_thumbnail(cdict['id']),
|
||||||
"listing": [],
|
"listing": [],
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ class fHDHRservice():
|
|||||||
"seasonnumber": progdict['season'],
|
"seasonnumber": progdict['season'],
|
||||||
"episodenumber": progdict['episode'],
|
"episodenumber": progdict['episode'],
|
||||||
"isnew": False,
|
"isnew": False,
|
||||||
"id": progdict['id'] or self.xmltimestamp_nextpvr(progdict["start"]),
|
"id": str(progdict['id'] or self.xmltimestamp_nextpvr(progdict["start"])),
|
||||||
}
|
}
|
||||||
|
|
||||||
if 'genre' in list(progdict.keys()):
|
if 'genre' in list(progdict.keys()):
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import sys
|
|||||||
import ast
|
import ast
|
||||||
import requests
|
import requests
|
||||||
import xml.etree.ElementTree
|
import xml.etree.ElementTree
|
||||||
|
import m3u8
|
||||||
|
|
||||||
UNARY_OPS = (ast.UAdd, ast.USub)
|
UNARY_OPS = (ast.UAdd, ast.USub)
|
||||||
BINARY_OPS = (ast.Add, ast.Sub, ast.Mult, ast.Div, ast.Mod)
|
BINARY_OPS = (ast.Add, ast.Sub, ast.Mult, ast.Div, ast.Mod)
|
||||||
@ -14,6 +15,26 @@ def clean_exit():
|
|||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def m3u8_beststream(m3u8_url):
|
||||||
|
bestStream = None
|
||||||
|
videoUrlM3u = m3u8.load(m3u8_url)
|
||||||
|
if len(videoUrlM3u.playlists) > 0:
|
||||||
|
for videoStream in videoUrlM3u.playlists:
|
||||||
|
if bestStream is None:
|
||||||
|
bestStream = videoStream
|
||||||
|
elif ((videoStream.stream_info.resolution[0] > bestStream.stream_info.resolution[0]) and
|
||||||
|
(videoStream.stream_info.resolution[1] > bestStream.stream_info.resolution[1])):
|
||||||
|
bestStream = videoStream
|
||||||
|
elif ((videoStream.stream_info.resolution[0] == bestStream.stream_info.resolution[0]) and
|
||||||
|
(videoStream.stream_info.resolution[1] == bestStream.stream_info.resolution[1]) and
|
||||||
|
(videoStream.stream_info.bandwidth > bestStream.stream_info.bandwidth)):
|
||||||
|
bestStream = videoStream
|
||||||
|
if bestStream is not None:
|
||||||
|
return bestStream.absolute_uri
|
||||||
|
else:
|
||||||
|
return m3u8_url
|
||||||
|
|
||||||
|
|
||||||
def sub_el(parent, name, text=None, **kwargs):
|
def sub_el(parent, name, text=None, **kwargs):
|
||||||
el = xml.etree.ElementTree.SubElement(parent, name, **kwargs)
|
el = xml.etree.ElementTree.SubElement(parent, name, **kwargs)
|
||||||
if text:
|
if text:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user