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

Enhance Channel Numbering system

This commit is contained in:
deathbybandaid 2020-12-10 14:27:08 -05:00
parent d5c7a1ea47
commit a8972371c2
11 changed files with 98 additions and 54 deletions

View File

@ -25,9 +25,15 @@ class Channels():
self.get_channels()
def get_channel_obj(self, keyfind, valfind):
return next(self.list[fhdhr_id] for fhdhr_id in list(self.list.keys()) if self.list[fhdhr_id].dict[keyfind] == valfind)
if keyfind == "number":
return next(self.list[fhdhr_id] for fhdhr_id in list(self.list.keys()) if self.list[fhdhr_id].number == valfind) or None
else:
return next(self.list[fhdhr_id] for fhdhr_id in list(self.list.keys()) if self.list[fhdhr_id].dict[keyfind] == valfind) or None
def get_channel_list(self, keyfind):
if keyfind == "number":
return [self.list[x].number for x in list(self.list.keys())]
else:
return [self.list[x].dict[keyfind] for x in list(self.list.keys())]
def set_channel_status(self, keyfind, valfind, updatedict):

View File

@ -14,11 +14,19 @@ class Channel():
else:
channel_id = id_system.assign()
self.channel_id = channel_id
self.dict = self.fhdhr.db.get_channel_value(str(channel_id), "dict") or self.default_dict
self.verify_dict()
self.fhdhr.db.set_channel_value(self.dict["id"], "dict", self.dict)
@property
def number(self):
if self.dict["subnumber"]:
return "%s.%s" % (self.dict["number"], self.dict["subnumber"])
else:
return self.dict["number"]
@property
def thumbnail(self):
if str(self.dict["thumbnail"]).lower() in ["none"]:
@ -35,9 +43,9 @@ class Channel():
return {
"callsign": self.dict["callsign"],
"name": self.dict["name"],
"number": self.dict["number"],
"number": self.number,
"id": self.dict["origin_id"],
"thumbnail": self.dict["thumbnail"],
"thumbnail": self.thumbnail,
"listing": [],
}
@ -49,6 +57,10 @@ class Channel():
for key in list(default_dict.keys()):
if key not in list(self.dict.keys()):
self.dict[key] = default_dict[key]
if self.dict["number"]:
if "." in self.dict["number"]:
self.dict["subnumber"] = self.dict["number"].split(".")[1]
self.dict["number"] = self.dict["number"].split(".")[0]
def basics(self, channel_info):
"""Some Channel Information is Critical"""
@ -77,9 +89,17 @@ class Channel():
if "number" not in list(channel_info.keys()):
channel_info["number"] = self.id_system.get_number(channel_info["id"])
self.dict["origin_number"] = str(float(channel_info["number"]))
self.dict["origin_number"] = str(channel_info["number"])
if not self.dict["number"]:
self.dict["number"] = self.dict["origin_number"]
self.dict["number"] = self.dict["origin_number"].split(".")[0]
try:
self.dict["subnumber"] = self.dict["origin_number"].split(".")[1]
except IndexError:
self.dict["subnumber"] = None
else:
if "." in self.dict["number"]:
self.dict["subnumber"] = self.dict["number"].split(".")[1]
self.dict["number"] = self.dict["number"].split(".")[0]
if "thumbnail" not in list(channel_info.keys()):
channel_info["thumbnail"] = None
@ -106,7 +126,7 @@ class Channel():
"id": str(self.channel_id), "origin_id": None,
"name": None, "origin_name": None,
"callsign": None, "origin_callsign": None,
"number": None, "origin_number": None,
"number": None, "subnumber": None, "origin_number": None,
"tags": [], "origin_tags": [],
"thumbnail": None, "origin_thumbnail": None,
"enabled": True, "favorite": 0,
@ -123,14 +143,14 @@ class Channel():
def set_status(self, updatedict):
for key in list(updatedict.keys()):
if key == "number":
updatedict[key] = str(float(updatedict[key]))
updatedict[key] = str(updatedict[key])
self.dict[key] = updatedict[key]
self.fhdhr.db.set_channel_value(self.dict["id"], "dict", self.dict)
@property
def lineup_dict(self):
return {
'GuideNumber': self.dict['number'],
'GuideNumber': self.number,
'GuideName': self.dict['name'],
'Tags': ",".join(self.dict['tags']),
'URL': self.stream_url,
@ -140,15 +160,15 @@ class Channel():
@property
def generic_image_url(self):
return "/api/images?method=generate&type=channel&message=%s" % self.dict["number"]
return "/api/images?method=generate&type=channel&message=%s" % self.number
@property
def stream_url(self):
return '/auto/v%s' % self.dict['number']
return '/auto/v%s' % self.number
@property
def play_url(self):
return '/api/m3u?method=get&channel=%s' % self.dict['number']
return '/api/m3u?method=get&channel=%s' % self.number
def set_favorite(self, enablement):
if enablement == "+":

View File

@ -60,15 +60,18 @@ class EPG():
self.fhdhr.db.delete_fhdhr_value("epg_dict", method)
def whats_on_now(self, channel, method=None):
epgdict = self.get_epg(method)
listings = epgdict[channel]["listing"]
for listing in listings:
def whats_on_now(self, channel_number, method=None):
nowtime = datetime.datetime.utcnow()
epgdict = self.get_epg(method)
try:
listings = epgdict[channel_number]["listing"]
except KeyError:
listings = []
for listing in listings:
start_time = datetime.datetime.strptime(listing["time_start"], '%Y%m%d%H%M%S +0000')
end_time = datetime.datetime.strptime(listing["time_end"], '%Y%m%d%H%M%S +0000')
if start_time <= nowtime <= end_time:
epgitem = epgdict[channel].copy()
epgitem = epgdict[channel_number].copy()
epgitem["listing"] = [listing]
return epgitem
return None
@ -83,9 +86,18 @@ class EPG():
channel_guide_list = []
epgdict = self.get_epg(method)
channels = list(epgdict.keys())
for channel in channels:
whatson = self.whats_on_now(epgdict[channel]["number"], method)
if method in ["blocks", "origin", self.fhdhr.config.dict["main"]["dictpopname"]]:
epgdict = epgdict.copy()
for c in list(epgdict.keys()):
chan_obj = self.channels.get_channel_obj("origin_id", epgdict[c]["id"])
epgdict[chan_obj.number] = epgdict.pop(c)
epgdict[chan_obj.number]["name"] = chan_obj.dict["name"]
epgdict[chan_obj.number]["callsign"] = chan_obj.dict["callsign"]
epgdict[chan_obj.number]["number"] = chan_obj.number
epgdict[chan_obj.number]["id"] = chan_obj.dict["origin_id"]
epgdict[chan_obj.number]["thumbnail"] = chan_obj.thumbnail
for channel_number in list(epgdict.keys()):
whatson = self.whats_on_now(channel_number, method)
if whatson:
channel_guide_list.append(whatson)
return channel_guide_list
@ -121,17 +133,15 @@ class EPG():
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)
channel_list = [epgdict[x] for x in list(epgdict.keys())]
return next(item for item in channel_list if item["id"] == channel_id) or None
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)
return next(item for item in event_list if item["id"] == event_id) or None
def epg_method_selfadd(self):
self.fhdhr.logger.info("Checking for Alternative EPG methods.")
@ -166,11 +176,6 @@ class EPG():
else:
programguide = self.epg_handling[method].update_epg()
for chan in list(programguide.keys()):
floatnum = str(float(chan))
programguide[floatnum] = programguide.pop(chan)
programguide[floatnum]["number"] = floatnum
programguide = OrderedDict(sorted(programguide.items()))
for cnum in programguide:

View File

@ -16,12 +16,12 @@ class blocksEPG():
for fhdhr_id in list(self.channels.list.keys()):
chan_obj = self.channels.list[fhdhr_id]
if str(chan_obj.dict["number"]) not in list(programguide.keys()):
programguide[str(chan_obj.dict["number"])] = chan_obj.epgdict
if str(chan_obj.number) not in list(programguide.keys()):
programguide[str(chan_obj.number)] = chan_obj.epgdict
clean_prog_dicts = self.empty_channel_epg(timestamps, chan_obj)
for clean_prog_dict in clean_prog_dicts:
programguide[str(chan_obj.dict["number"])]["listing"].append(clean_prog_dict)
programguide[str(chan_obj.number)]["listing"].append(clean_prog_dict)
return programguide

View File

@ -84,7 +84,12 @@ class Channels():
if key in ["name", "callsign", "thumbnail"]:
updatedict[key] = str(request.form.get(key))
elif key in ["number"]:
updatedict[key] = float(request.form.get(key))
number = str(request.form.get(key))
if "." in number:
updatedict["subnumber"] = number.split(".")[1]
updatedict["number"] = number.split(".")[0]
else:
updatedict["number"] = number
elif key in ["enabled"]:
confvalue = request.form.get(key)
if str(confvalue).lower() in ["false"]:

View File

@ -32,12 +32,12 @@ class EPG():
epgdict = epgdict.copy()
for c in list(epgdict.keys()):
chan_obj = self.fhdhr.device.channels.get_channel_obj("origin_id", epgdict[c]["id"])
epgdict[chan_obj.dict["number"]] = epgdict.pop(c)
epgdict[chan_obj.dict["number"]]["name"] = chan_obj.dict["name"]
epgdict[chan_obj.dict["number"]]["callsign"] = chan_obj.dict["callsign"]
epgdict[chan_obj.dict["number"]]["number"] = chan_obj.dict["number"]
epgdict[chan_obj.dict["number"]]["id"] = chan_obj.dict["origin_id"]
epgdict[chan_obj.dict["number"]]["thumbnail"] = chan_obj.thumbnail
epgdict[chan_obj.number] = epgdict.pop(c)
epgdict[chan_obj.number]["name"] = chan_obj.dict["name"]
epgdict[chan_obj.number]["callsign"] = chan_obj.dict["callsign"]
epgdict[chan_obj.number]["number"] = chan_obj.number
epgdict[chan_obj.number]["id"] = chan_obj.dict["origin_id"]
epgdict[chan_obj.number]["thumbnail"] = chan_obj.thumbnail
epg_json = json.dumps(epgdict, indent=4)

View File

@ -43,12 +43,12 @@ class xmlTV():
epgdict = epgdict.copy()
for c in list(epgdict.keys()):
chan_obj = self.fhdhr.device.channels.get_channel_obj("origin_id", epgdict[c]["id"])
epgdict[chan_obj.dict["number"]] = epgdict.pop(c)
epgdict[chan_obj.dict["number"]]["name"] = chan_obj.dict["name"]
epgdict[chan_obj.dict["number"]]["callsign"] = chan_obj.dict["callsign"]
epgdict[chan_obj.dict["number"]]["number"] = chan_obj.dict["number"]
epgdict[chan_obj.dict["number"]]["id"] = chan_obj.dict["origin_id"]
epgdict[chan_obj.dict["number"]]["thumbnail"] = chan_obj.thumbnail
epgdict[chan_obj.number] = epgdict.pop(c)
epgdict[chan_obj.number]["name"] = chan_obj.dict["name"]
epgdict[chan_obj.number]["callsign"] = chan_obj.dict["callsign"]
epgdict[chan_obj.number]["number"] = chan_obj.number
epgdict[chan_obj.number]["id"] = chan_obj.dict["origin_id"]
epgdict[chan_obj.number]["thumbnail"] = chan_obj.thumbnail
xmltv_xml = self.create_xmltv(base_url, epgdict, source)
@ -100,12 +100,12 @@ class xmlTV():
if source in ["origin", "blocks", self.fhdhr.config.dict["main"]["dictpopname"]]:
for c in list(epgdict.keys()):
chan_obj = self.fhdhr.device.channels.get_channel_obj("origin_id", epgdict[c]["id"])
epgdict[chan_obj.dict["number"]] = epgdict.pop(c)
epgdict[chan_obj.dict["number"]]["name"] = chan_obj.dict["name"]
epgdict[chan_obj.dict["number"]]["callsign"] = chan_obj.dict["callsign"]
epgdict[chan_obj.dict["number"]]["number"] = chan_obj.dict["number"]
epgdict[chan_obj.dict["number"]]["id"] = chan_obj.dict["origin_id"]
epgdict[chan_obj.dict["number"]]["thumbnail"] = chan_obj.thumbnail
epgdict[chan_obj.number] = epgdict.pop(c)
epgdict[chan_obj.number]["name"] = chan_obj.dict["name"]
epgdict[chan_obj.number]["callsign"] = chan_obj.dict["callsign"]
epgdict[chan_obj.number]["number"] = chan_obj.number
epgdict[chan_obj.number]["id"] = chan_obj.dict["origin_id"]
epgdict[chan_obj.number]["thumbnail"] = chan_obj.thumbnail
for c in list(epgdict.keys()):

View File

@ -17,7 +17,11 @@ class Channels_Editor_HTML():
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
channel_dict = channel_obj.dict.copy()
channel_dict["number"] = channel_obj.number
channel_dict["chan_thumbnail"] = channel_obj.thumbnail
channel_dict["play_url"] = channel_obj.play_url
channelslist.append(channel_dict)
return render_template('channels_editor.html', request=request, fhdhr=self.fhdhr, channelslist=channelslist)

View File

@ -22,7 +22,11 @@ class Channels_HTML():
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
channel_dict = channel_obj.dict.copy()
channel_dict["number"] = channel_obj.number
channel_dict["chan_thumbnail"] = channel_obj.thumbnail
channel_dict["play_url"] = channel_obj.play_url
channelslist.append(channel_dict)
if channel_dict["enabled"]:
channels_dict["Enabled"] += 1

View File

@ -42,7 +42,7 @@ class Guide_HTML():
chan_obj = self.fhdhr.device.channels.get_channel_obj("origin_id", channel["id"])
chan_dict["name"] = chan_obj.dict["name"]
chan_dict["number"] = chan_obj.dict["number"]
chan_dict["number"] = chan_obj.number
chan_dict["chan_thumbnail"] = chan_obj.thumbnail
chan_dict["enabled"] = chan_obj.dict["enabled"]
chan_dict["play_url"] = chan_obj.play_url

View File

@ -27,10 +27,10 @@ class RMG_Devices_DeviceKey_Channels():
if channel_obj.enabled:
sub_el(out, 'Channel',
drm="0",
channelIdentifier="id://%s" % channel_obj.dict["number"],
channelIdentifier="id://%s" % channel_obj.number,
name=channel_obj.dict["name"],
origin=channel_obj.dict["callsign"],
number=str(channel_obj.dict["number"]),
number=str(channel_obj.number),
type="tv",
# TODO param
signalStrength="100",