mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 08:56:57 -05:00
Enhance Channel Loading
This commit is contained in:
parent
77f941c08a
commit
39649a11f8
@ -1,7 +1,6 @@
|
|||||||
import datetime
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from fHDHR.tools import hours_between_datetime, humanized_time
|
from fHDHR.tools import humanized_time
|
||||||
|
|
||||||
from .channel import Channel
|
from .channel import Channel
|
||||||
from .chan_ident import Channel_IDs
|
from .chan_ident import Channel_IDs
|
||||||
@ -17,27 +16,26 @@ class Channels():
|
|||||||
self.id_system = Channel_IDs(fhdhr)
|
self.id_system = Channel_IDs(fhdhr)
|
||||||
|
|
||||||
self.list = {}
|
self.list = {}
|
||||||
self.list_update_time = None
|
|
||||||
|
|
||||||
self.get_db_channels()
|
self.get_db_channels()
|
||||||
|
|
||||||
def get_channel_obj(self, keyfind, valfind):
|
def get_channel_obj(self, keyfind, valfind):
|
||||||
if keyfind == "number":
|
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
|
return next(self.list[fhdhr_id] for fhdhr_id in [x["id"] for x in self.get_channels()] if self.list[fhdhr_id].number == valfind) or None
|
||||||
else:
|
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
|
return next(self.list[fhdhr_id] for fhdhr_id in [x["id"] for x in self.get_channels()] 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":
|
if keyfind == "number":
|
||||||
return [self.list[x].number for x in list(self.list.keys())]
|
return [self.list[x].number for x in [x["id"] for x in self.get_channels()]]
|
||||||
else:
|
else:
|
||||||
return [self.list[x].dict[keyfind] for x in list(self.list.keys())]
|
return [self.list[x].dict[keyfind] for x in [x["id"] for x in self.get_channels()]]
|
||||||
|
|
||||||
def set_channel_status(self, keyfind, valfind, updatedict):
|
def set_channel_status(self, keyfind, valfind, updatedict):
|
||||||
self.get_channel_obj(keyfind, valfind).set_status(updatedict)
|
self.get_channel_obj(keyfind, valfind).set_status(updatedict)
|
||||||
|
|
||||||
def set_channel_enablement_all(self, enablement):
|
def set_channel_enablement_all(self, enablement):
|
||||||
for fhdhr_id in list(self.list.keys()):
|
for fhdhr_id in [x["id"] for x in self.get_channels()]:
|
||||||
self.list[fhdhr_id].set_enablement(enablement)
|
self.list[fhdhr_id].set_enablement(enablement)
|
||||||
|
|
||||||
def set_channel_enablement(self, keyfind, valfind, enablement):
|
def set_channel_enablement(self, keyfind, valfind, enablement):
|
||||||
@ -56,6 +54,10 @@ class Channels():
|
|||||||
channel_id = channel_obj.dict["id"]
|
channel_id = channel_obj.dict["id"]
|
||||||
self.list[channel_id] = channel_obj
|
self.list[channel_id] = channel_obj
|
||||||
|
|
||||||
|
def save_db_channels(self):
|
||||||
|
channel_ids = [x["id"] for x in self.get_channels()]
|
||||||
|
self.fhdhr.db.set_fhdhr_value("channels", "list", channel_ids)
|
||||||
|
|
||||||
def get_channels(self, forceupdate=False):
|
def get_channels(self, forceupdate=False):
|
||||||
"""Pull Channels from origin.
|
"""Pull Channels from origin.
|
||||||
|
|
||||||
@ -64,56 +66,50 @@ class Channels():
|
|||||||
Don't pull more often than 12 hours.
|
Don't pull more often than 12 hours.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
updatelist = False
|
if not len(list(self.list.keys())):
|
||||||
if not self.list_update_time:
|
self.get_db_channels()
|
||||||
updatelist = True
|
|
||||||
elif hours_between_datetime(self.list_update_time, datetime.datetime.now()) > 12:
|
|
||||||
updatelist = True
|
|
||||||
elif forceupdate:
|
|
||||||
updatelist = True
|
|
||||||
|
|
||||||
if updatelist:
|
if not forceupdate:
|
||||||
channel_origin_id_list = [str(self.list[x].dict["origin_id"]) for x in list(self.list.keys())]
|
return [self.list[x].dict for x in list(self.list.keys())]
|
||||||
|
|
||||||
self.fhdhr.logger.info("Performing Channel Scan.")
|
channel_origin_id_list = [str(self.list[x].dict["origin_id"]) for x in list(self.list.keys())]
|
||||||
|
|
||||||
channel_dict_list = self.origin.get_channels()
|
self.fhdhr.logger.info("Performing Channel Scan.")
|
||||||
self.fhdhr.logger.info("Found %s channels for %s." % (len(channel_dict_list), self.fhdhr.config.dict["main"]["servicename"]))
|
|
||||||
|
|
||||||
self.fhdhr.logger.info("Performing Channel Import, This can take some time, Please wait.")
|
channel_dict_list = self.origin.get_channels()
|
||||||
|
self.fhdhr.logger.info("Found %s channels for %s." % (len(channel_dict_list), self.fhdhr.config.dict["main"]["servicename"]))
|
||||||
|
|
||||||
newchan = 0
|
self.fhdhr.logger.info("Performing Channel Import, This can take some time, Please wait.")
|
||||||
chan_scan_start = time.time()
|
|
||||||
for channel_info in channel_dict_list:
|
|
||||||
|
|
||||||
chan_existing = False
|
newchan = 0
|
||||||
if str(channel_info["id"]) in channel_origin_id_list:
|
chan_scan_start = time.time()
|
||||||
chan_existing = True
|
for channel_info in channel_dict_list:
|
||||||
channel_obj = self.get_channel_obj("origin_id", channel_info["id"])
|
|
||||||
else:
|
|
||||||
channel_obj = Channel(self.fhdhr, self.id_system, origin_id=channel_info["id"])
|
|
||||||
|
|
||||||
channel_id = channel_obj.dict["id"]
|
chan_existing = str(channel_info["id"]) in channel_origin_id_list
|
||||||
channel_obj.basics(channel_info)
|
|
||||||
if not chan_existing:
|
|
||||||
self.list[channel_id] = channel_obj
|
|
||||||
newchan += 1
|
|
||||||
|
|
||||||
self.fhdhr.logger.info("Channel Import took %s" % humanized_time(time.time() - chan_scan_start))
|
if chan_existing:
|
||||||
|
channel_obj = self.get_channel_obj("origin_id", channel_info["id"])
|
||||||
|
else:
|
||||||
|
channel_obj = Channel(self.fhdhr, self.id_system, origin_id=channel_info["id"])
|
||||||
|
|
||||||
if not newchan:
|
channel_id = channel_obj.dict["id"]
|
||||||
newchan = "no"
|
channel_obj.basics(channel_info)
|
||||||
self.fhdhr.logger.info("Found %s NEW channels." % newchan)
|
if not chan_existing:
|
||||||
|
self.list[channel_id] = channel_obj
|
||||||
|
newchan += 1
|
||||||
|
|
||||||
self.fhdhr.logger.info("Total Channel Count: %s" % len(self.list.keys()))
|
self.fhdhr.logger.info("Channel Import took %s" % humanized_time(time.time() - chan_scan_start))
|
||||||
|
|
||||||
self.list_update_time = datetime.datetime.now()
|
if not newchan:
|
||||||
self.fhdhr.db.set_fhdhr_value("channels", "scanned_time", time.time())
|
newchan = "no"
|
||||||
|
self.fhdhr.logger.info("Found %s NEW channels." % newchan)
|
||||||
|
|
||||||
channel_list = []
|
self.fhdhr.logger.info("Total Channel Count: %s" % len(self.list.keys()))
|
||||||
for chan_obj in list(self.list.keys()):
|
self.save_db_channels()
|
||||||
channel_list.append(self.list[chan_obj].dict)
|
|
||||||
return channel_list
|
self.fhdhr.db.set_fhdhr_value("channels", "scanned_time", time.time())
|
||||||
|
|
||||||
|
return [self.list[x].dict for x in list(self.list.keys())]
|
||||||
|
|
||||||
def get_channel_stream(self, channel_number):
|
def get_channel_stream(self, channel_number):
|
||||||
return self.origin.get_channel_stream(self.get_channel_dict("number", channel_number))
|
return self.origin.get_channel_stream(self.get_channel_dict("number", channel_number))
|
||||||
|
|||||||
@ -271,7 +271,7 @@ class EPG():
|
|||||||
# if a stock method, generate Blocks EPG for missing channels
|
# if a stock method, generate Blocks EPG for missing channels
|
||||||
if method in ["blocks", "origin", self.fhdhr.config.dict["main"]["dictpopname"]]:
|
if method in ["blocks", "origin", self.fhdhr.config.dict["main"]["dictpopname"]]:
|
||||||
timestamps = self.blocks.timestamps
|
timestamps = self.blocks.timestamps
|
||||||
for fhdhr_id in list(self.channels.list.keys()):
|
for fhdhr_id in [x["id"] for x in self.fhdhr.device.channels.get_channels()]:
|
||||||
chan_obj = self.channels.list[fhdhr_id]
|
chan_obj = self.channels.list[fhdhr_id]
|
||||||
if str(chan_obj.number) not in list(programguide.keys()):
|
if str(chan_obj.number) not in list(programguide.keys()):
|
||||||
programguide[str(chan_obj.number)] = chan_obj.epgdict
|
programguide[str(chan_obj.number)] = chan_obj.epgdict
|
||||||
|
|||||||
@ -13,7 +13,7 @@ class blocksEPG():
|
|||||||
|
|
||||||
timestamps = self.timestamps
|
timestamps = self.timestamps
|
||||||
|
|
||||||
for fhdhr_id in list(self.channels.list.keys()):
|
for fhdhr_id in [x["id"] for x in self.fhdhr.device.channels.get_channels()]:
|
||||||
chan_obj = self.channels.list[fhdhr_id]
|
chan_obj = self.channels.list[fhdhr_id]
|
||||||
|
|
||||||
if str(chan_obj.number) not in list(programguide.keys()):
|
if str(chan_obj.number) not in list(programguide.keys()):
|
||||||
|
|||||||
@ -21,7 +21,7 @@ class Channels():
|
|||||||
|
|
||||||
if method == "get":
|
if method == "get":
|
||||||
channels_info = []
|
channels_info = []
|
||||||
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
|
for fhdhr_id in [x["id"] for x in self.fhdhr.device.channels.get_channels()]:
|
||||||
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["play_url"] = channel_obj.play_url
|
channel_dict["play_url"] = channel_obj.play_url
|
||||||
|
|||||||
@ -42,7 +42,7 @@ class M3U():
|
|||||||
|
|
||||||
if channel == "all":
|
if channel == "all":
|
||||||
fileName = "channels.m3u"
|
fileName = "channels.m3u"
|
||||||
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
|
for fhdhr_id in [x["id"] for x in self.fhdhr.device.channels.get_channels()]:
|
||||||
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
|
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
|
||||||
if channel_obj.enabled:
|
if channel_obj.enabled:
|
||||||
channel_items.append(channel_obj)
|
channel_items.append(channel_obj)
|
||||||
|
|||||||
@ -19,7 +19,7 @@ class Lineup_JSON():
|
|||||||
show = request.args.get('show', default="all", type=str)
|
show = request.args.get('show', default="all", type=str)
|
||||||
|
|
||||||
jsonlineup = []
|
jsonlineup = []
|
||||||
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
|
for fhdhr_id in [x["id"] for x in self.fhdhr.device.channels.get_channels()]:
|
||||||
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
|
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
|
||||||
if channel_obj.enabled or show == "found":
|
if channel_obj.enabled or show == "found":
|
||||||
lineup_dict = channel_obj.lineup_dict
|
lineup_dict = channel_obj.lineup_dict
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class Lineup_XML():
|
|||||||
show = request.args.get('show', default="all", type=str)
|
show = request.args.get('show', default="all", type=str)
|
||||||
|
|
||||||
out = xml.etree.ElementTree.Element('Lineup')
|
out = xml.etree.ElementTree.Element('Lineup')
|
||||||
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
|
for fhdhr_id in [x["id"] for x in self.fhdhr.device.channels.get_channels()]:
|
||||||
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
|
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
|
||||||
if channel_obj.enabled or show == "found":
|
if channel_obj.enabled or show == "found":
|
||||||
program_out = sub_el(out, 'Program')
|
program_out = sub_el(out, 'Program')
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class Channels_Editor_HTML():
|
|||||||
def get(self, *args):
|
def get(self, *args):
|
||||||
|
|
||||||
channelslist = []
|
channelslist = []
|
||||||
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
|
for fhdhr_id in [x["id"] for x in self.fhdhr.device.channels.get_channels()]:
|
||||||
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()
|
||||||
|
|
||||||
|
|||||||
@ -14,12 +14,12 @@ class Channels_HTML():
|
|||||||
def get(self, *args):
|
def get(self, *args):
|
||||||
|
|
||||||
channels_dict = {
|
channels_dict = {
|
||||||
"Total Channels": len(list(self.fhdhr.device.channels.list.keys())),
|
"Total Channels": len(self.fhdhr.device.channels.get_channels()),
|
||||||
"Enabled": 0,
|
"Enabled": 0
|
||||||
}
|
}
|
||||||
|
|
||||||
channelslist = []
|
channelslist = []
|
||||||
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
|
for fhdhr_id in [x["id"] for x in self.fhdhr.device.channels.get_channels()]:
|
||||||
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()
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class RMG_Devices_DeviceKey_Channels():
|
|||||||
out = xml.etree.ElementTree.Element('MediaContainer')
|
out = xml.etree.ElementTree.Element('MediaContainer')
|
||||||
if devicekey == self.fhdhr.config.dict["main"]["uuid"]:
|
if devicekey == self.fhdhr.config.dict["main"]["uuid"]:
|
||||||
out.set('size', str(len(self.fhdhr.device.channels.list)))
|
out.set('size', str(len(self.fhdhr.device.channels.list)))
|
||||||
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
|
for fhdhr_id in [x["id"] for x in self.fhdhr.device.channels.get_channels()]:
|
||||||
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
|
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
|
||||||
if channel_obj.enabled:
|
if channel_obj.enabled:
|
||||||
sub_el(out, 'Channel',
|
sub_el(out, 'Channel',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user