1
0
mirror of https://github.com/fHDHR/fHDHR_NextPVR.git synced 2025-12-06 12:26:57 -05:00

Enhance EPG system

This commit is contained in:
deathbybandaid 2020-09-30 08:20:27 -04:00
parent 8df57591b2
commit 1fee52e975
4 changed files with 248 additions and 245 deletions

View File

@ -1,12 +1,12 @@
import os import os
import sys import sys
import time import time
import datetime
from io import BytesIO from io import BytesIO
import json import json
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from . import zap2it from . import zap2it
from . import emptyepg
def sub_el(parent, name, text=None, **kwargs): def sub_el(parent, name, text=None, **kwargs):
@ -28,15 +28,13 @@ class EPGhandler():
self.config = config.config self.config = config.config
self.serviceproxy = serviceproxy self.serviceproxy = serviceproxy
self.zapepg = zap2it.ZapEPG(config) self.zapepg = zap2it.ZapEPG(config)
self.emptyepg = emptyepg.EmptyEPG(config)
self.epg_cache = None self.epg_cache = None
self.empty_cache_dir = config.config["main"]["empty_cache"]
self.empty_cache_file = config.config["main"]["empty_cache_file"]
def get_epg(self): def get_epg(self):
if self.config["fakehdhr"]["epg_method"] == "empty": if self.config["fakehdhr"]["epg_method"] == "empty":
epgdict = self.epg_cache_open() epgdict = self.emptyepg.EmptyEPG()
elif self.config["fakehdhr"]["epg_method"] == "proxy": elif self.config["fakehdhr"]["epg_method"] == "proxy":
epgdict = self.serviceproxy.epg_cache_open() epgdict = self.serviceproxy.epg_cache_open()
elif self.config["fakehdhr"]["epg_method"] == "zap2it": elif self.config["fakehdhr"]["epg_method"] == "zap2it":
@ -63,39 +61,53 @@ class EPGhandler():
out.set('generator-info-name', 'FAKEHDHR') out.set('generator-info-name', 'FAKEHDHR')
out.set('generator-info-url', 'FAKEHDHR/FakeHDHR_NextPVR') out.set('generator-info-url', 'FAKEHDHR/FakeHDHR_NextPVR')
for channel in list(epgdict.keys()): for c in list(epgdict.keys()):
c_out = sub_el(out, 'channel', id=epgdict[channel]['id'])
c_out = sub_el(out, 'channel', id=str(epgdict[c]['number']))
sub_el(c_out, 'display-name', sub_el(c_out, 'display-name',
text='%s %s' % (epgdict[channel]['number'], epgdict[channel]['callsign'])) text='%s %s' % (epgdict[c]['number'], epgdict[c]['callsign']))
sub_el(c_out, 'display-name', text=epgdict[channel]['number']) sub_el(c_out, 'display-name',
sub_el(c_out, 'display-name', text=epgdict[channel]['callsign']) text='%s %s %s' % (epgdict[c]['number'], epgdict[c]['callsign'], str(epgdict[c]['id'])))
sub_el(c_out, 'display-name', text=epgdict[c]['number'])
sub_el(c_out, 'display-name',
text='%s %s fcc' % (epgdict[c]['number'], epgdict[c]['callsign']))
sub_el(c_out, 'display-name', text=epgdict[c]['callsign'])
sub_el(c_out, 'display-name', text=epgdict[c]['callsign'])
sub_el(c_out, 'display-name', text=epgdict[c]['name'])
if epgdict[c]["thumbnail"] is not None:
if epg_method == "empty": if epg_method == "empty":
sub_el(c_out, 'icon', src=("http://" + str(base_url) + str(epgdict[channel]['thumbnail']))) sub_el(c_out, 'icon', src=("http://" + str(base_url) + str(epgdict[c]['thumbnail'])))
elif epg_method == "proxy": elif epg_method == "proxy":
sub_el(c_out, 'icon', src=("http://" + str(base_url) + str(epgdict[channel]['thumbnail']))) sub_el(c_out, 'icon', src=("http://" + str(base_url) + str(epgdict[c]['thumbnail'])))
elif epg_method == "zap2it": elif epg_method == "zap2it":
sub_el(c_out, 'icon', src=(str(epgdict[channel]['thumbnail']))) sub_el(c_out, 'icon', src=(str(epgdict[c]['thumbnail'])))
else: else:
sub_el(c_out, 'icon', src=(str(epgdict[channel]['thumbnail']))) sub_el(c_out, 'icon', src=(str(epgdict[c]['thumbnail'])))
else:
sub_el(c_out, 'icon', src=("http://" + str(base_url) + "/images?source=empty&type=channel&id=empty"))
for channel in list(epgdict.keys()): for progitem in list(epgdict.keys()):
channel_listing = epgdict[channel]['listing']
channel_listing = epgdict[progitem]['listing']
for program in channel_listing: for program in channel_listing:
prog_out = sub_el(out, 'programme', prog_out = sub_el(out, 'programme',
start=program['time_start'], start=program['time_start'],
stop=program['time_end'], stop=program['time_end'],
channel=epgdict[channel]["id"]) channel=str(progitem))
if program['title']:
sub_el(prog_out, 'title', lang='en', text=program['title']) sub_el(prog_out, 'title', lang='en', text=program['title'])
if 'movie' in program['genres'] and program['releaseyear']: sub_el(prog_out, 'desc', lang='en', text=program['description'])
if ('movie' in program["genres"] or 'Movie' in program["genres"]) and program['releaseyear']:
sub_el(prog_out, 'sub-title', lang='en', text='Movie: ' + program['releaseyear']) sub_el(prog_out, 'sub-title', lang='en', text='Movie: ' + program['releaseyear'])
elif program['episodetitle']: elif 'episodetitle' in program.keys():
sub_el(prog_out, 'sub-title', lang='en', text=program['episodetitle']) sub_el(prog_out, 'sub-title', lang='en', text=program['episodetitle'])
else:
sub_el(prog_out, 'sub-title', lang='en', text='Movie: ' + program['sub-title'])
sub_el(prog_out, 'length', units='minutes', text=str(int(program['duration_minutes']))) sub_el(prog_out, 'length', units='minutes', text=str(int(program['duration_minutes'])))
@ -103,6 +115,18 @@ class EPGhandler():
sub_el(prog_out, 'category', lang='en', text=f) sub_el(prog_out, 'category', lang='en', text=f)
sub_el(prog_out, 'genre', lang='en', text=f) sub_el(prog_out, 'genre', lang='en', text=f)
if program['seasonnumber'] and program['episodenumber']:
s_ = int(str(program['seasonnumber']), 10)
e_ = int(str(program['episodenumber']), 10)
sub_el(prog_out, 'episode-num', system='dd_progid',
text=str(program['id']))
sub_el(prog_out, 'episode-num', system='common',
text='S%02dE%02d' % (s_, e_))
sub_el(prog_out, 'episode-num', system='xmltv_ns',
text='%d.%d.' % (int(s_)-1, int(e_)-1))
sub_el(prog_out, 'episode-num', system='SxxExx">S',
text='S%02dE%02d' % (s_, e_))
if program["thumbnail"] is not None: if program["thumbnail"] is not None:
if epg_method == "empty": if epg_method == "empty":
sub_el(prog_out, 'icon', src=("http://" + str(base_url) + str(program['thumbnail']))) sub_el(prog_out, 'icon', src=("http://" + str(base_url) + str(program['thumbnail'])))
@ -112,24 +136,15 @@ class EPGhandler():
sub_el(prog_out, 'icon', src=(str(program['thumbnail']))) sub_el(prog_out, 'icon', src=(str(program['thumbnail'])))
else: else:
sub_el(prog_out, 'icon', src=(str(program['thumbnail']))) sub_el(prog_out, 'icon', src=(str(program['thumbnail'])))
else:
sub_el(prog_out, 'icon', src=("http://" + str(base_url) + "/images?source=empty&type=content&id=empty"))
if program['rating']: if program['rating']:
r = ET.SubElement(prog_out, 'rating') rating_out = sub_el(prog_out, 'rating', system="MPAA")
sub_el(r, 'value', text=program['rating']) sub_el(rating_out, 'value', text=program['rating'])
if 'seasonnumber' in list(program.keys()) and 'episodenumber' in list(program.keys()): if program['isnew']:
if program['seasonnumber'] and program['episodenumber']: sub_el(prog_out, 'new')
s_ = int(program['seasonnumber'], 10)
e_ = int(program['episodenumber'], 10)
sub_el(prog_out, 'episode-num', system='common',
text='S%02dE%02d' % (s_, e_))
sub_el(prog_out, 'episode-num', system='xmltv_ns',
text='%d.%d.' % (int(s_)-1, int(e_)-1))
sub_el(prog_out, 'episode-num', system='SxxExx">S',
text='S%02dE%02d' % (s_, e_))
# if 'New' in event['flag'] and 'live' not in event['flag']:
# sub_el(prog_out, 'new')
fakefile = BytesIO() fakefile = BytesIO()
fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n') fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
@ -148,85 +163,9 @@ class EPGhandler():
fakefile.write(ET.tostring(out, encoding='UTF-8')) fakefile.write(ET.tostring(out, encoding='UTF-8'))
return fakefile.getvalue() return fakefile.getvalue()
def update_epg(self):
print('Updating Empty EPG cache file.')
programguide = {}
timestamps = []
todaydate = datetime.date.today()
for x in range(0, 6):
xdate = todaydate + datetime.timedelta(days=x)
xtdate = xdate + datetime.timedelta(days=1)
for hour in range(0, 24):
time_start = datetime.datetime.combine(xdate, datetime.time(hour, 0))
if hour + 1 < 24:
time_end = datetime.datetime.combine(xdate, datetime.time(hour + 1, 0))
else:
time_end = datetime.datetime.combine(xtdate, datetime.time(0, 0))
timestampdict = {
"time_start": str(time_start.strftime('%Y%m%d%H%M%S')) + " +0000",
"time_end": str(time_end.strftime('%Y%m%d%H%M%S')) + " +0000",
}
timestamps.append(timestampdict)
for c in self.serviceproxy.get_channels():
if str(c["number"]) not in list(programguide.keys()):
programguide[str(c["number"])] = {}
channel_thumb_path = ("/images?source=empty&type=channel&id=%s" % (str(c['number'])))
programguide[str(c["number"])]["thumbnail"] = channel_thumb_path
if "name" not in list(programguide[str(c["number"])].keys()):
programguide[str(c["number"])]["name"] = c["name"]
if "callsign" not in list(programguide[str(c["number"])].keys()):
programguide[str(c["number"])]["callsign"] = c["name"]
if "id" not in list(programguide[str(c["number"])].keys()):
programguide[str(c["number"])]["id"] = c["id"]
if "number" not in list(programguide[str(c["number"])].keys()):
programguide[str(c["number"])]["number"] = c["number"]
if "listing" not in list(programguide[str(c["number"])].keys()):
programguide[str(c["number"])]["listing"] = []
for timestamp in timestamps:
clean_prog_dict = {}
clean_prog_dict["time_start"] = timestamp['time_start']
clean_prog_dict["time_end"] = timestamp['time_end']
clean_prog_dict["duration_minutes"] = 60.0
content_thumb = ("/images?source=empty&type=content&id=%s" % (str(c['number'])))
clean_prog_dict["thumbnail"] = content_thumb
clean_prog_dict["title"] = "Unavailable"
clean_prog_dict["genres"] = []
clean_prog_dict["sub-title"] = "Unavailable"
clean_prog_dict['releaseyear'] = ""
clean_prog_dict["episodetitle"] = "Unavailable"
clean_prog_dict["description"] = "Unavailable"
clean_prog_dict['rating'] = "N/A"
programguide[str(c["number"])]["listing"].append(clean_prog_dict)
self.epg_cache = programguide
with open(self.empty_cache_file, 'w') as epgfile:
epgfile.write(json.dumps(programguide, indent=4))
print('Wrote updated Empty EPG cache file.')
return programguide
def update(self): def update(self):
if self.config["fakehdhr"]["epg_method"] == "empty": if self.config["fakehdhr"]["epg_method"] == "empty":
self.update_epg() self.emptyepg.update_epg()
elif self.config["fakehdhr"]["epg_method"] == "proxy": elif self.config["fakehdhr"]["epg_method"] == "proxy":
self.serviceproxy.update_epg() self.serviceproxy.update_epg()
elif self.config["fakehdhr"]["epg_method"] == "zap2it": elif self.config["fakehdhr"]["epg_method"] == "zap2it":

85
epghandler/emptyepg.py Normal file
View File

@ -0,0 +1,85 @@
import os
import json
import datetime
class EmptyEPG():
def __init__(self, config):
self.config = config.config
self.postalcode = None
self.epg_cache = None
self.cache_dir = config.config["main"]["empty_cache"]
self.epg_cache_file = config.config["main"]["empty_cache_file"]
self.epg_cache = self.epg_cache_open()
def epg_cache_open(self):
epg_cache = None
if os.path.isfile(self.epg_cache_file):
with open(self.epg_cache_file, 'r') as epgfile:
epg_cache = json.load(epgfile)
return epg_cache
def update_epg(self):
print('Updating Empty EPG cache file.')
programguide = {}
timestamps = []
todaydate = datetime.date.today()
for x in range(0, 6):
xdate = todaydate + datetime.timedelta(days=x)
xtdate = xdate + datetime.timedelta(days=1)
for hour in range(0, 24):
time_start = datetime.datetime.combine(xdate, datetime.time(hour, 0))
if hour + 1 < 24:
time_end = datetime.datetime.combine(xdate, datetime.time(hour + 1, 0))
else:
time_end = datetime.datetime.combine(xtdate, datetime.time(0, 0))
timestampdict = {
"time_start": str(time_start.strftime('%Y%m%d%H%M%S')) + " +0000",
"time_end": str(time_end.strftime('%Y%m%d%H%M%S')) + " +0000",
}
timestamps.append(timestampdict)
for c in self.serviceproxy.get_channels():
if str(c["number"]) not in list(programguide.keys()):
programguide[str(c["number"])] = {
"callsign": c["callsign"],
"name": c["name"],
"number": c["number"],
"id": c["id"],
"thumbnail": ("/images?source=empty&type=channel&id=%s" % (str(c['number']))),
"listing": [],
}
for timestamp in timestamps:
clean_prog_dict = {
"time_start": timestamp['time_start'],
"time_end": timestamp['time_end'],
"duration_minutes": 60,
"thumbnail": ("/images?source=empty&type=content&id=%s" % (str(c['number']))),
"title": "Unavailable",
"sub-title": "Unavailable",
"description": "Unavailable",
"rating": "N/A",
"episodetitle": None,
"releaseyear": None,
"genres": [],
"seasonnumber": None,
"episodenumber": None,
"isnew": False,
"id": timestamp['time_start'],
}
programguide[str(c["number"])]["listing"].append(clean_prog_dict)
self.epg_cache = programguide
with open(self.empty_cache_file, 'w') as epgfile:
epgfile.write(json.dumps(programguide, indent=4))
print('Wrote updated Empty EPG cache file.')
return programguide

View File

@ -14,8 +14,22 @@ def xmltimestamp_zap(inputtime):
return xmltime return xmltime
def duration_nextpvr_minutes(starttime, endtime): def xmldictmaker(inputdict, req_items, list_items=[], str_items=[]):
return ((int(endtime) - int(starttime))/1000/60) xml_dict = {}
for origitem in list(inputdict.keys()):
xml_dict[origitem] = inputdict[origitem]
for req_item in req_items:
if req_item not in list(inputdict.keys()):
xml_dict[req_item] = None
if not xml_dict[req_item]:
if req_item in list_items:
xml_dict[req_item] = []
elif req_item in str_items:
xml_dict[req_item] = ""
return xml_dict
class ZapEPG(): class ZapEPG():
@ -125,79 +139,54 @@ class ZapEPG():
for c in d['channels']: for c in d['channels']:
if str(c['channelNo']) not in list(programguide.keys()): cdict = xmldictmaker(c, ["callSign", "name", "channelNo", "channelId", "thumbnail"])
programguide[str(c['channelNo'])] = {}
channel_thumb = str(c['thumbnail']).replace("//", "https://").split("?")[0] if str(cdict['channelNo']) not in list(programguide.keys()):
programguide[str(c["channelNo"])]["thumbnail"] = channel_thumb
if "name" not in list(programguide[str(c["channelNo"])].keys()): programguide[str(cdict['channelNo'])] = {
programguide[str(c["channelNo"])]["name"] = c["callSign"] "callsign": cdict["callSign"],
"name": cdict["name"] or cdict["callSign"], # TODO
if "callsign" not in list(programguide[str(c["channelNo"])].keys()): "number": cdict["channelNo"],
programguide[str(c["channelNo"])]["callsign"] = c["callSign"] "id": cdict["channelId"],
"thumbnail": str(cdict['thumbnail']).replace("//", "https://").split("?")[0],
if "id" not in list(programguide[str(c["channelNo"])].keys()): "listing": [],
programguide[str(c["channelNo"])]["id"] = c["channelId"] }
if "number" not in list(programguide[str(c["channelNo"])].keys()):
programguide[str(c["channelNo"])]["number"] = c["channelNo"]
if "listing" not in list(programguide[str(c["channelNo"])].keys()):
programguide[str(c["channelNo"])]["listing"] = []
for event in c['events']: for event in c['events']:
clean_prog_dict = {}
prog_in = event['program'] eventdict = xmldictmaker(event, ["startTime", "endTime", "duration", "rating", "flag"], list_items=["filter", "flag"])
progdict = xmldictmaker(event['program'], ["title", "sub-title", "releaseYear", "episodeTitle", "shortDesc", "season", "episode", "id"])
clean_prog_dict["time_start"] = xmltimestamp_zap(event['startTime']) clean_prog_dict = {
clean_prog_dict["time_end"] = xmltimestamp_zap(event['endTime']) "time_start": xmltimestamp_zap(eventdict['startTime']),
clean_prog_dict["duration_minutes"] = event['duration'] "time_end": xmltimestamp_zap(eventdict['endTime']),
"duration_minutes": eventdict['duration'],
"thumbnail": str("https://zap2it.tmsimg.com/assets/" + str(eventdict['thumbnail']) + ".jpg"),
"title": progdict['title'] or "Unavailable",
"sub-title": progdict['sub-title'] or "Unavailable",
"description": progdict['shortDesc'] or "Unavailable",
"rating": eventdict['rating'] or "N/A",
"episodetitle": progdict['episodeTitle'],
"releaseyear": progdict['releaseYear'],
"genres": [],
"seasonnumber": progdict['season'],
"episodenumber": progdict['episode'],
"isnew": False,
"id": progdict['id'] or xmltimestamp_zap(eventdict['startTime']),
}
content_thumb = str("https://zap2it.tmsimg.com/assets/" + str(event['thumbnail']) + ".jpg") for f in eventdict['filter']:
clean_prog_dict["thumbnail"] = content_thumb
if 'title' not in list(prog_in.keys()):
prog_in["title"] = "Unavailable"
elif not prog_in["title"]:
prog_in["title"] = "Unavailable"
clean_prog_dict["title"] = prog_in["title"]
clean_prog_dict["genres"] = []
if 'filter' in list(event.keys()):
for f in event['filter']:
clean_prog_dict["genres"].append(f.replace('filter-', '')) clean_prog_dict["genres"].append(f.replace('filter-', ''))
if 'filter-movie' in event['filter'] and prog_in['releaseYear']: if 'movie' in clean_prog_dict['genres'] and clean_prog_dict['releaseyear']:
clean_prog_dict["sub-title"] = 'Movie: ' + prog_in['releaseYear'] clean_prog_dict["sub-title"] = 'Movie: ' + clean_prog_dict['releaseyear']
elif prog_in['episodeTitle']: elif clean_prog_dict['episodetitle']:
clean_prog_dict["sub-title"] = prog_in['episodeTitle'] clean_prog_dict["sub-title"] = clean_prog_dict['episodetitle']
else:
clean_prog_dict["sub-title"] = "Unavailable"
clean_prog_dict['releaseyear'] = prog_in['releaseYear'] if 'New' in eventdict['flag'] and 'live' not in eventdict['flag']:
if prog_in['shortDesc'] is None:
prog_in['shortDesc'] = "Unavailable"
clean_prog_dict["description"] = prog_in['shortDesc']
if 'rating' not in list(event.keys()):
event['rating'] = "N/A"
clean_prog_dict['rating'] = event['rating']
if 'season' in list(prog_in.keys()) and 'episode' in list(prog_in.keys()):
clean_prog_dict["seasonnumber"] = prog_in['season']
clean_prog_dict["episodenumber"] = prog_in['episode']
clean_prog_dict["episodetitle"] = clean_prog_dict["sub-title"]
else:
if "movie" not in clean_prog_dict["genres"]:
clean_prog_dict["episodetitle"] = clean_prog_dict["sub-title"]
if 'New' in event['flag'] and 'live' not in event['flag']:
clean_prog_dict["isnew"] = True clean_prog_dict["isnew"] = True
programguide[str(c["channelNo"])]["listing"].append(clean_prog_dict) programguide[str(cdict["channelNo"])]["listing"].append(clean_prog_dict)
self.epg_cache = programguide self.epg_cache = programguide
with open(self.epg_cache_file, 'w') as epgfile: with open(self.epg_cache_file, 'w') as epgfile:

View File

@ -8,6 +8,24 @@ import urllib.parse
import urllib.request import urllib.request
def xmldictmaker(inputdict, req_items, list_items=[], str_items=[]):
xml_dict = {}
for origitem in list(inputdict.keys()):
xml_dict[origitem] = inputdict[origitem]
for req_item in req_items:
if req_item not in list(inputdict.keys()):
xml_dict[req_item] = None
if not xml_dict[req_item]:
if req_item in list_items:
xml_dict[req_item] = []
elif req_item in str_items:
xml_dict[req_item] = ""
return xml_dict
class NextPVR_Auth(): class NextPVR_Auth():
config = { config = {
'npvrURL': '', 'npvrURL': '',
@ -128,6 +146,7 @@ class proxyserviceFetcher():
channel_dict = eval(dString) channel_dict = eval(dString)
clean_station_item = { clean_station_item = {
"name": channel_dict["name"], "name": channel_dict["name"],
"callsign": channel_dict["name"],
"number": channel_dict["formatted-number"], "number": channel_dict["formatted-number"],
"id": channel_dict["id"], "id": channel_dict["id"],
} }
@ -202,32 +221,25 @@ class proxyserviceFetcher():
programguide = {} programguide = {}
for c in self.get_channels(): for c in self.get_channels():
if str(c["number"]) not in list(programguide.keys()):
programguide[str(c["number"])] = {}
channel_thumb_path = ("/images?source=proxy&type=channel&id=%s" % (str(c['id']))) cdict = xmldictmaker(c, ["callsign", "name", "number", "id"])
programguide[str(c["number"])]["thumbnail"] = channel_thumb_path
if "name" not in list(programguide[str(c["number"])].keys()): if str(cdict['number']) not in list(programguide.keys()):
programguide[str(c["number"])]["name"] = c["name"]
if "callsign" not in list(programguide[str(c["number"])].keys()): programguide[str(cdict['number'])] = {
programguide[str(c["number"])]["callsign"] = c["name"] "callsign": cdict["callsign"],
"name": cdict["name"] or cdict["callsign"],
if "id" not in list(programguide[str(c["number"])].keys()): "number": cdict["number"],
programguide[str(c["number"])]["id"] = c["id"] "id": cdict["id"],
"thumbnail": ("/images?source=proxy&type=channel&id=%s" % (str(cdict['id']))),
if "number" not in list(programguide[str(c["number"])].keys()): "listing": [],
programguide[str(c["number"])]["number"] = c["number"] }
if "listing" not in list(programguide[str(c["number"])].keys()):
programguide[str(c["number"])]["listing"] = []
epg_url = ('%s%s:%s/service?method=channel.listings&channel_id=%s' % epg_url = ('%s%s:%s/service?method=channel.listings&channel_id=%s' %
("https://" if self.config["nextpvr"]["ssl"] else "http://", ("https://" if self.config["nextpvr"]["ssl"] else "http://",
self.config["nextpvr"]["address"], self.config["nextpvr"]["address"],
str(self.config["nextpvr"]["port"]), str(self.config["nextpvr"]["port"]),
str(c["id"]), str(cdict["id"]),
)) ))
epg_req = urllib.request.urlopen(epg_url) epg_req = urllib.request.urlopen(epg_url)
epg_dict = xmltodict.parse(epg_req) epg_dict = xmltodict.parse(epg_req)
@ -235,60 +247,38 @@ class proxyserviceFetcher():
for program_listing in epg_dict["rsp"]["listings"]: for program_listing in epg_dict["rsp"]["listings"]:
for program_item in epg_dict["rsp"]["listings"][program_listing]: for program_item in epg_dict["rsp"]["listings"][program_listing]:
if not isinstance(program_item, str): if not isinstance(program_item, str):
dirty_prog_dict = {}
for programkey in list(program_item.keys()):
dirty_prog_dict[programkey] = program_item[programkey]
clean_prog_dict = {} progdict = xmldictmaker(program_item, ["start", "end", "title", "name", "subtitle", "rating", "description", "season", "episode", "id", "episodeTitle"])
clean_prog_dict["time_start"] = xmltimestamp_nextpvr(dirty_prog_dict["start"]) clean_prog_dict = {
clean_prog_dict["time_end"] = xmltimestamp_nextpvr(dirty_prog_dict["end"]) "time_start": xmltimestamp_nextpvr(progdict["start"]),
clean_prog_dict["duration_minutes"] = duration_nextpvr_minutes(dirty_prog_dict["start"], dirty_prog_dict["end"]) "time_end": xmltimestamp_nextpvr(progdict["end"]),
"duration_minutes": duration_nextpvr_minutes(progdict["start"], progdict["end"]),
"thumbnail": ("/images?source=proxy&type=content&id=%s" % (str(progdict['id']))),
"title": progdict['name'] or "Unavailable",
"sub-title": progdict['subtitle'] or "Unavailable",
"description": progdict['description'] or "Unavailable",
"rating": progdict['rating'] or "N/A",
"episodetitle": progdict['episodeTitle'],
"releaseyear": None,
"genres": [],
"seasonnumber": progdict['season'],
"episodenumber": progdict['episode'],
"isnew": False,
"id": progdict['id'] or xmltimestamp_nextpvr(progdict["start"]),
}
item_thumb_path = ("/images?source=proxy&type=content&id=%s" % (str(dirty_prog_dict['id']))) if 'genre' in list(progdict.keys()):
clean_prog_dict["thumbnail"] = item_thumb_path clean_prog_dict["genres"] = progdict['genre'].split(",")
if 'name' not in list(dirty_prog_dict.keys()): if clean_prog_dict['sub-title'].startswith("Movie:"):
dirty_prog_dict["name"] = "Unavailable" clean_prog_dict['releaseyear'] = clean_prog_dict['sub-title'].split("Movie: ")[-1]
elif not dirty_prog_dict["name"]: clean_prog_dict['sub-title'] = "Unavailable"
dirty_prog_dict["name"] = "Unavailable" clean_prog_dict["genres"].append("Movie")
clean_prog_dict["title"] = dirty_prog_dict["name"]
if 'genre' not in list(dirty_prog_dict.keys()):
clean_prog_dict["genres"] = []
else:
clean_prog_dict["genres"] = dirty_prog_dict['genre'].split(",")
if 'subtitle' not in list(dirty_prog_dict.keys()):
dirty_prog_dict["subtitle"] = "Unavailable"
clean_prog_dict["sub-title"] = dirty_prog_dict["subtitle"]
if dirty_prog_dict['subtitle'].startswith("Movie:"):
clean_prog_dict['releaseyear'] = dirty_prog_dict['subtitle'].split("Movie:")[-1]
else:
clean_prog_dict['releaseyear'] = None
if 'description' not in list(dirty_prog_dict.keys()):
dirty_prog_dict["description"] = "Unavailable"
elif dirty_prog_dict['description']:
dirty_prog_dict["description"] = "Unavailable"
clean_prog_dict["description"] = dirty_prog_dict["description"]
if 'rating' not in list(dirty_prog_dict.keys()):
dirty_prog_dict['rating'] = "N/A"
clean_prog_dict['rating'] = dirty_prog_dict['rating']
if 'season' in list(dirty_prog_dict.keys()) and 'episode' in list(dirty_prog_dict.keys()):
clean_prog_dict["seasonnumber"] = dirty_prog_dict['season']
clean_prog_dict["episodenumber"] = dirty_prog_dict['episode']
clean_prog_dict["episodetitle"] = clean_prog_dict["sub-title"]
else:
if "movie" not in clean_prog_dict["genres"]:
clean_prog_dict["episodetitle"] = clean_prog_dict["sub-title"]
# TODO isNEW # TODO isNEW
programguide[str(c["number"])]["listing"].append(clean_prog_dict) programguide[str(cdict["number"])]["listing"].append(clean_prog_dict)
self.epg_cache = programguide self.epg_cache = programguide
with open(self.epg_cache_file, 'w') as epgfile: with open(self.epg_cache_file, 'w') as epgfile: