From 0aea878ebee7885c0cabd6144828e3dd3d0029ef Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 18 Dec 2020 08:54:07 -0500 Subject: [PATCH] More EPG Enhancements --- data/internal_config/epg.json | 6 ++++++ fHDHR/config/__init__.py | 6 +++++- fHDHR/device/epg/__init__.py | 10 +++++++--- fHDHR_web/api/startup_tasks.py | 3 ++- fHDHR_web/api/xmltv.py | 23 +++++++++++++---------- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/data/internal_config/epg.json b/data/internal_config/epg.json index a77400c..93cd7a7 100644 --- a/data/internal_config/epg.json +++ b/data/internal_config/epg.json @@ -35,5 +35,11 @@ "config_file": false, "config_web": false } + , + "xmltv_offset": { + "value": "+0000", + "config_file": false, + "config_web": false + } } } diff --git a/fHDHR/config/__init__.py b/fHDHR/config/__init__.py index 62b3c3a..d2e8215 100644 --- a/fHDHR/config/__init__.py +++ b/fHDHR/config/__init__.py @@ -155,7 +155,9 @@ class Config(): self.conf_default[section][key] = {} confvalue = confimport[section][key]["value"] - if isint(confvalue): + if key == "xmltv_offset": + confvalue = str(confvalue) + elif isint(confvalue): confvalue = int(confvalue) elif isfloat(confvalue): confvalue = float(confvalue) @@ -196,6 +198,8 @@ class Config(): for (each_key, each_val) in config_handler.items(each_section): if not each_val: each_val = None + elif each_key == "xmltv_offset": + each_val = str(each_val) elif each_val.lower() in ["none"]: each_val = None elif each_val.lower() in ["false"]: diff --git a/fHDHR/device/epg/__init__.py b/fHDHR/device/epg/__init__.py index 0ad4575..d0c623f 100644 --- a/fHDHR/device/epg/__init__.py +++ b/fHDHR/device/epg/__init__.py @@ -28,8 +28,12 @@ class EPG(): self.def_method = self.fhdhr.config.dict["epg"]["def_method"] self.sleeptime = {} - for epg_method in list(self.epg_handling.keys()): - self.sleeptime[epg_method] = self.fhdhr.config.dict["epg"]["update_frequency"] + for epg_method in self.epg_methods: + if epg_method in list(self.fhdhr.config.dict.keys()): + if "update_frequency" in list(self.fhdhr.config.dict[epg_method].keys()): + self.sleeptime[epg_method] = self.fhdhr.config.dict[epg_method]["update_frequency"] + if epg_method not in list(self.sleeptime.keys()): + self.sleeptime[epg_method] = self.fhdhr.config.dict["epg"]["update_frequency"] self.epg_update_url = "%s/api/epg?method=update" % (self.fhdhr.api.base) @@ -303,7 +307,7 @@ class EPG(): updatetheepg = True if updatetheepg: try: - self.fhdhr.web.session.get(self.epg_update_url, timeout=0.0000000001) + self.fhdhr.web.session.get("%s?sorurce=%s" % (self.epg_update_url, epg_method), timeout=0.0000000001) except self.fhdhr.web.exceptions.ReadTimeout: pass except self.fhdhr.web.exceptions.ConnectionError as e: diff --git a/fHDHR_web/api/startup_tasks.py b/fHDHR_web/api/startup_tasks.py index 63c2c2f..cb802e9 100644 --- a/fHDHR_web/api/startup_tasks.py +++ b/fHDHR_web/api/startup_tasks.py @@ -28,6 +28,7 @@ class Startup_Tasks(): self.fhdhr.api.client.get(self.channel_update_url) # Hit EPG Update API - self.fhdhr.api.client.get(self.epg_update_url) + for epg_method in self.fhdhr.device.epg.epg_methods: + self.fhdhr.api.client.get("%s?sorurce=%s" % (self.epg_update_url, epg_method)) return "Success" diff --git a/fHDHR_web/api/xmltv.py b/fHDHR_web/api/xmltv.py index e38705f..f13b6b0 100644 --- a/fHDHR_web/api/xmltv.py +++ b/fHDHR_web/api/xmltv.py @@ -16,6 +16,14 @@ class xmlTV(): def __init__(self, fhdhr): self.fhdhr = fhdhr + self.xmltv_offset = {} + for epg_method in list(self.fhdhr.device.epg.epg_handling.keys()): + if epg_method in list(self.fhdhr.config.dict.keys()): + if "xmltv_offset" in list(self.fhdhr.config.dict[epg_method].keys()): + self.xmltv_offset[epg_method] = self.fhdhr.config.dict[epg_method]["xmltv_offset"] + if epg_method not in list(self.xmltv_offset.keys()): + self.xmltv_offset[epg_method] = self.fhdhr.config.dict["epg"]["xmltv_offset"] + def __call__(self, *args): return self.get(*args) @@ -91,17 +99,12 @@ class xmlTV(): """This method is called when creation of a full xmltv is not possible""" return self.xmltv_file(self.xmltv_headers()) - def timestamp_to_datetime(self, time_start, time_end): + def timestamp_to_datetime(self, time_start, time_end, source): xmltvtimetamps = {} - + source_offset = self.xmltv_offset[source] for time_item, time_value in zip(["time_start", "time_end"], [time_start, time_end]): - - if str(time_value).endswith(tuple(["+0000", "+00:00"])): - xmltvtimetamps[time_item] = str(time_value) - else: - timestampval = datetime.datetime.fromtimestamp(time_value) - xmltvtimetamps[time_item] = str(timestampval.strftime('%Y%m%d%H%M%S')) + " +0000" - + timestampval = datetime.datetime.fromtimestamp(time_value).strftime('%Y%m%d%H%M%S') + xmltvtimetamps[time_item] = "%s %s" % (timestampval, source_offset) return xmltvtimetamps def create_xmltv(self, base_url, epgdict, source): @@ -143,7 +146,7 @@ class xmlTV(): for program in channel_listing: - xmltvtimetamps = self.timestamp_to_datetime(program['time_start'], program['time_end']) + xmltvtimetamps = self.timestamp_to_datetime(program['time_start'], program['time_end'], source) prog_out = sub_el(out, 'programme', start=xmltvtimetamps['time_start'],