mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 10:26:57 -05:00
commit
a981d8d845
@ -1,7 +1,6 @@
|
||||
import datetime
|
||||
import time
|
||||
|
||||
from fHDHR.tools import hours_between_datetime, humanized_time
|
||||
from fHDHR.tools import humanized_time
|
||||
|
||||
from .channel import Channel
|
||||
from .chan_ident import Channel_IDs
|
||||
@ -17,27 +16,26 @@ class Channels():
|
||||
self.id_system = Channel_IDs(fhdhr)
|
||||
|
||||
self.list = {}
|
||||
self.list_update_time = None
|
||||
|
||||
self.get_db_channels()
|
||||
|
||||
def get_channel_obj(self, 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
|
||||
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:
|
||||
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):
|
||||
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:
|
||||
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):
|
||||
self.get_channel_obj(keyfind, valfind).set_status(updatedict)
|
||||
|
||||
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)
|
||||
|
||||
def set_channel_enablement(self, keyfind, valfind, enablement):
|
||||
@ -56,6 +54,10 @@ class Channels():
|
||||
channel_id = channel_obj.dict["id"]
|
||||
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):
|
||||
"""Pull Channels from origin.
|
||||
|
||||
@ -64,15 +66,12 @@ class Channels():
|
||||
Don't pull more often than 12 hours.
|
||||
"""
|
||||
|
||||
updatelist = False
|
||||
if not self.list_update_time:
|
||||
updatelist = True
|
||||
elif hours_between_datetime(self.list_update_time, datetime.datetime.now()) > 12:
|
||||
updatelist = True
|
||||
elif forceupdate:
|
||||
updatelist = True
|
||||
if not len(list(self.list.keys())):
|
||||
self.get_db_channels()
|
||||
|
||||
if not forceupdate:
|
||||
return [self.list[x].dict for x in list(self.list.keys())]
|
||||
|
||||
if updatelist:
|
||||
channel_origin_id_list = [str(self.list[x].dict["origin_id"]) for x in list(self.list.keys())]
|
||||
|
||||
self.fhdhr.logger.info("Performing Channel Scan.")
|
||||
@ -86,9 +85,9 @@ class Channels():
|
||||
chan_scan_start = time.time()
|
||||
for channel_info in channel_dict_list:
|
||||
|
||||
chan_existing = False
|
||||
if str(channel_info["id"]) in channel_origin_id_list:
|
||||
chan_existing = True
|
||||
chan_existing = str(channel_info["id"]) in channel_origin_id_list
|
||||
|
||||
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"])
|
||||
@ -106,14 +105,11 @@ class Channels():
|
||||
self.fhdhr.logger.info("Found %s NEW channels." % newchan)
|
||||
|
||||
self.fhdhr.logger.info("Total Channel Count: %s" % len(self.list.keys()))
|
||||
self.save_db_channels()
|
||||
|
||||
self.list_update_time = datetime.datetime.now()
|
||||
self.fhdhr.db.set_fhdhr_value("channels", "scanned_time", time.time())
|
||||
|
||||
channel_list = []
|
||||
for chan_obj in list(self.list.keys()):
|
||||
channel_list.append(self.list[chan_obj].dict)
|
||||
return channel_list
|
||||
return [self.list[x].dict for x in list(self.list.keys())]
|
||||
|
||||
def get_channel_stream(self, 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 method in ["blocks", "origin", self.fhdhr.config.dict["main"]["dictpopname"]]:
|
||||
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]
|
||||
if str(chan_obj.number) not in list(programguide.keys()):
|
||||
programguide[str(chan_obj.number)] = chan_obj.epgdict
|
||||
|
||||
@ -13,7 +13,7 @@ class blocksEPG():
|
||||
|
||||
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]
|
||||
|
||||
if str(chan_obj.number) not in list(programguide.keys()):
|
||||
|
||||
@ -21,7 +21,7 @@ class Channels():
|
||||
|
||||
if method == "get":
|
||||
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_dict = channel_obj.dict.copy()
|
||||
channel_dict["play_url"] = channel_obj.play_url
|
||||
|
||||
@ -42,7 +42,7 @@ class M3U():
|
||||
|
||||
if channel == "all":
|
||||
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]
|
||||
if channel_obj.enabled:
|
||||
channel_items.append(channel_obj)
|
||||
|
||||
@ -19,7 +19,7 @@ class Lineup_JSON():
|
||||
show = request.args.get('show', default="all", type=str)
|
||||
|
||||
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]
|
||||
if channel_obj.enabled or show == "found":
|
||||
lineup_dict = channel_obj.lineup_dict
|
||||
|
||||
@ -22,7 +22,7 @@ class Lineup_XML():
|
||||
show = request.args.get('show', default="all", type=str)
|
||||
|
||||
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]
|
||||
if channel_obj.enabled or show == "found":
|
||||
program_out = sub_el(out, 'Program')
|
||||
|
||||
@ -14,7 +14,7 @@ class Channels_Editor_HTML():
|
||||
def get(self, *args):
|
||||
|
||||
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_dict = channel_obj.dict.copy()
|
||||
|
||||
|
||||
@ -14,12 +14,12 @@ class Channels_HTML():
|
||||
def get(self, *args):
|
||||
|
||||
channels_dict = {
|
||||
"Total Channels": len(list(self.fhdhr.device.channels.list.keys())),
|
||||
"Enabled": 0,
|
||||
"Total Channels": len(self.fhdhr.device.channels.get_channels()),
|
||||
"Enabled": 0
|
||||
}
|
||||
|
||||
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_dict = channel_obj.dict.copy()
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ class RMG_Devices_DeviceKey_Channels():
|
||||
out = xml.etree.ElementTree.Element('MediaContainer')
|
||||
if devicekey == self.fhdhr.config.dict["main"]["uuid"]:
|
||||
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]
|
||||
if channel_obj.enabled:
|
||||
sub_el(out, 'Channel',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user