diff --git a/fHDHR/device/channels/__init__.py b/fHDHR/device/channels/__init__.py index 36d85af..99631a7 100644 --- a/fHDHR/device/channels/__init__.py +++ b/fHDHR/device/channels/__init__.py @@ -70,13 +70,20 @@ class Channels(): updatelist = True 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.") channel_dict_list = self.origin.get_channels() for channel_info in channel_dict_list: - channel_obj = Channel(self.fhdhr, self.id_system, origin_id=channel_info["id"]) + chan_existing = False + if str(channel_info["id"]) in channel_origin_id_list: + chan_existing = True + 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"] channel_obj.basics(channel_info) - self.list[channel_id] = channel_obj + if not chan_existing: + self.list[channel_id] = channel_obj if not self.list_update_time: self.fhdhr.logger.info("Found " + str(len(self.list)) + " channels for " + str(self.fhdhr.config.dict["main"]["servicename"])) diff --git a/fHDHR/device/epg/__init__.py b/fHDHR/device/epg/__init__.py index b79dca5..4d7e817 100644 --- a/fHDHR/device/epg/__init__.py +++ b/fHDHR/device/epg/__init__.py @@ -36,6 +36,13 @@ class EPG(): if epg_method not in list(self.sleeptime.keys()): self.sleeptime[epg_method] = self.fhdhr.config.dict["epg"]["update_frequency"] + if self.fhdhr.config.dict["fhdhr"]["address"] == "0.0.0.0": + self.location = ('http://127.0.0.1:%s' % str(self.fhdhr.config.dict["fhdhr"]["port"])) + else: + self.location = ('http://%s:%s' % (self.fhdhr.config.dict["fhdhr"]["address"], str(self.fhdhr.config.dict["fhdhr"]["port"]))) + + self.epg_update_url = "%s/api/epg?method=update" % (self.location) + def clear_epg_cache(self, method=None): if not method: @@ -178,12 +185,12 @@ class EPG(): def run(self): for epg_method in self.epg_methods: - self.update(epg_method) + self.fhdhr.web.session.get(self.epg_update_url) try: while True: for epg_method in self.epg_methods: if time.time() >= (self.fhdhr.db.get_fhdhr_value("update_time", epg_method) + self.sleeptime[epg_method]): - self.update(epg_method) - time.sleep(3600) + self.fhdhr.web.session.get(self.epg_update_url) + time.sleep(360) except KeyboardInterrupt: pass diff --git a/fHDHR/http/api/epg.py b/fHDHR/http/api/epg.py index 26a8040..78d619f 100644 --- a/fHDHR/http/api/epg.py +++ b/fHDHR/http/api/epg.py @@ -28,6 +28,16 @@ class EPG(): if method == "get": epgdict = self.fhdhr.device.epg.get_epg(source) + epgdict = epgdict.copy() + for c in list(epgdict.keys()): + 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.dict["number"]]["name"] = chan_obj.dict["name"] + epgdict[chan_obj.dict["number"]]["callsign"] = chan_obj.dict["callsign"] + epgdict[chan_obj.dict["number"]]["number"] = chan_obj.dict["number"] + epgdict[chan_obj.dict["number"]]["id"] = chan_obj.dict["origin_id"] + epgdict[chan_obj.dict["number"]]["thumbnail"] = chan_obj.thumbnail + epg_json = json.dumps(epgdict, indent=4) return Response(status=200, diff --git a/fHDHR/http/api/xmltv.py b/fHDHR/http/api/xmltv.py index 5457a91..3ff34ba 100644 --- a/fHDHR/http/api/xmltv.py +++ b/fHDHR/http/api/xmltv.py @@ -81,13 +81,13 @@ class xmlTV(): def create_xmltv(self, base_url, epgdict, source): if not epgdict: return self.xmltv_empty() - epgdict.copy() + epgdict = epgdict.copy() out = self.xmltv_headers() if source in ["origin", "blocks", self.fhdhr.config.dict["main"]["dictpopname"]]: for c in list(epgdict.keys()): - chan_obj = self.fhdhr.channels.get_channel_obj("origin_id", 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.dict["number"]]["name"] = chan_obj.dict["name"] epgdict[chan_obj.dict["number"]]["callsign"] = chan_obj.dict["callsign"]