Enhance Channel Numbering system

This commit is contained in:
deathbybandaid 2020-12-10 14:32:10 -05:00
parent ec1591f8a8
commit ce07510586
11 changed files with 98 additions and 54 deletions

View File

@ -25,9 +25,15 @@ class Channels():
self.get_channels() self.get_channels()
def get_channel_obj(self, keyfind, valfind): 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): 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())] return [self.list[x].dict[keyfind] for x in list(self.list.keys())]
def set_channel_status(self, keyfind, valfind, updatedict): def set_channel_status(self, keyfind, valfind, updatedict):

View File

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

View File

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

View File

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

View File

@ -84,7 +84,12 @@ class Channels():
if key in ["name", "callsign", "thumbnail"]: if key in ["name", "callsign", "thumbnail"]:
updatedict[key] = str(request.form.get(key)) updatedict[key] = str(request.form.get(key))
elif key in ["number"]: 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"]: elif key in ["enabled"]:
confvalue = request.form.get(key) confvalue = request.form.get(key)
if str(confvalue).lower() in ["false"]: if str(confvalue).lower() in ["false"]:

View File

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

View File

@ -43,12 +43,12 @@ class xmlTV():
epgdict = epgdict.copy() epgdict = epgdict.copy()
for c in list(epgdict.keys()): for c in list(epgdict.keys()):
chan_obj = self.fhdhr.device.channels.get_channel_obj("origin_id", epgdict[c]["id"]) 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.number] = epgdict.pop(c)
epgdict[chan_obj.dict["number"]]["name"] = chan_obj.dict["name"] epgdict[chan_obj.number]["name"] = chan_obj.dict["name"]
epgdict[chan_obj.dict["number"]]["callsign"] = chan_obj.dict["callsign"] epgdict[chan_obj.number]["callsign"] = chan_obj.dict["callsign"]
epgdict[chan_obj.dict["number"]]["number"] = chan_obj.dict["number"] epgdict[chan_obj.number]["number"] = chan_obj.number
epgdict[chan_obj.dict["number"]]["id"] = chan_obj.dict["origin_id"] epgdict[chan_obj.number]["id"] = chan_obj.dict["origin_id"]
epgdict[chan_obj.dict["number"]]["thumbnail"] = chan_obj.thumbnail epgdict[chan_obj.number]["thumbnail"] = chan_obj.thumbnail
xmltv_xml = self.create_xmltv(base_url, epgdict, source) 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"]]: if source in ["origin", "blocks", self.fhdhr.config.dict["main"]["dictpopname"]]:
for c in list(epgdict.keys()): for c in list(epgdict.keys()):
chan_obj = self.fhdhr.device.channels.get_channel_obj("origin_id", epgdict[c]["id"]) 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.number] = epgdict.pop(c)
epgdict[chan_obj.dict["number"]]["name"] = chan_obj.dict["name"] epgdict[chan_obj.number]["name"] = chan_obj.dict["name"]
epgdict[chan_obj.dict["number"]]["callsign"] = chan_obj.dict["callsign"] epgdict[chan_obj.number]["callsign"] = chan_obj.dict["callsign"]
epgdict[chan_obj.dict["number"]]["number"] = chan_obj.dict["number"] epgdict[chan_obj.number]["number"] = chan_obj.number
epgdict[chan_obj.dict["number"]]["id"] = chan_obj.dict["origin_id"] epgdict[chan_obj.number]["id"] = chan_obj.dict["origin_id"]
epgdict[chan_obj.dict["number"]]["thumbnail"] = chan_obj.thumbnail epgdict[chan_obj.number]["thumbnail"] = chan_obj.thumbnail
for c in list(epgdict.keys()): 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()): for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
channel_obj = self.fhdhr.device.channels.list[fhdhr_id] channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
channel_dict = channel_obj.dict.copy() 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 channel_dict["play_url"] = channel_obj.play_url
channelslist.append(channel_dict) channelslist.append(channel_dict)
return render_template('channels_editor.html', request=request, fhdhr=self.fhdhr, channelslist=channelslist) 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()): for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
channel_obj = self.fhdhr.device.channels.list[fhdhr_id] channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
channel_dict = channel_obj.dict.copy() 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 channel_dict["play_url"] = channel_obj.play_url
channelslist.append(channel_dict) channelslist.append(channel_dict)
if channel_dict["enabled"]: if channel_dict["enabled"]:
channels_dict["Enabled"] += 1 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_obj = self.fhdhr.device.channels.get_channel_obj("origin_id", channel["id"])
chan_dict["name"] = chan_obj.dict["name"] 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["chan_thumbnail"] = chan_obj.thumbnail
chan_dict["enabled"] = chan_obj.dict["enabled"] chan_dict["enabled"] = chan_obj.dict["enabled"]
chan_dict["play_url"] = chan_obj.play_url chan_dict["play_url"] = chan_obj.play_url

View File

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