diff --git a/fHDHR/device/epg/__init__.py b/fHDHR/device/epg/__init__.py index a7b1ea0..a9a87e7 100644 --- a/fHDHR/device/epg/__init__.py +++ b/fHDHR/device/epg/__init__.py @@ -296,10 +296,18 @@ class EPG(): while True: for epg_method in self.epg_methods: last_update_time = self.fhdhr.db.get_fhdhr_value("update_time", epg_method) + updatetheepg = False if not last_update_time: - self.fhdhr.web.session.get(self.epg_update_url) + updatetheepg = True elif time.time() >= (last_update_time + self.sleeptime[epg_method]): - self.fhdhr.web.session.get(self.epg_update_url) + updatetheepg = True + if updatetheepg: + try: + self.fhdhr.web.session.get(self.epg_update_url, timeout=0.0000000001) + except self.fhdhr.web.exceptions.ReadTimeout: + pass + except self.fhdhr.web.exceptions.ConnectionError as e: + self.fhdhr.logger.error("Error updating %s EPG cache: %s" % (epg_method, e)) time.sleep(360) except KeyboardInterrupt: pass diff --git a/origin/origin_channels.py b/origin/origin_channels.py index 5973c77..12a83f2 100644 --- a/origin/origin_channels.py +++ b/origin/origin_channels.py @@ -15,8 +15,6 @@ class OriginChannels(): "https://ott-gateway-stirr.sinclairstoryline.com/api/rest/v3/status/40b80f75-2efc-49af-813b-2a674e69ea59" - "https://ott-gateway-stirr.sinclairstoryline.com/api/rest/v3/program/stirr/ott/" - def get_channels(self): channel_list = [] diff --git a/origin/origin_epg.py b/origin/origin_epg.py index bac6ded..18f4068 100644 --- a/origin/origin_epg.py +++ b/origin/origin_epg.py @@ -5,13 +5,40 @@ class OriginEPG(): def __init__(self, fhdhr): self.fhdhr = fhdhr + self.base_epg_url = "https://ott-gateway-stirr.sinclairstoryline.com/api/rest/v3/program/stirr/ott/" + def update_epg(self, fhdhr_channels): programguide = {} for fhdhr_id in list(fhdhr_channels.list.keys()): chan_obj = fhdhr_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 + + epg_opn = self.fhdhr.web.session.get(self.base_epg_url + str(chan_obj.dict["origin_id"])) + epg_json = epg_opn.json() + + for listing in epg_json["channel"][0]["programme"]: + clean_prog_dict = { + "time_start": None, + "time_end": None, + "duration_minutes": None, + "title": "Unavailable", + "sub-title": "Unavailable", + "description": "Unavailable", + "rating": "N/A", + "episodetitle": None, + "releaseyear": None, + "genres": [], + "seasonnumber": None, + "episodenumber": None, + "isnew": False, + "id": None, + "thumbnail": None + } + + if not any((d['time_start'] == clean_prog_dict['time_start'] and d['id'] == clean_prog_dict['id']) for d in programguide[chan_obj.number]["listing"]): + programguide[str(chan_obj.number)]["listing"].append(clean_prog_dict) return programguide