From a564e039df3b7ebe7da9ae2098bd68319446ac22 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 28 Nov 2020 11:25:48 -0500 Subject: [PATCH 1/8] Use absolute_uri for m3u8 keys --- fHDHR/device/tuners/stream/direct_stream.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fHDHR/device/tuners/stream/direct_stream.py b/fHDHR/device/tuners/stream/direct_stream.py index 4a3f300..665a0aa 100644 --- a/fHDHR/device/tuners/stream/direct_stream.py +++ b/fHDHR/device/tuners/stream/direct_stream.py @@ -96,7 +96,7 @@ class Direct_Stream(): self.fhdhr.logger.info("Loaded %s segments." % str(len(segments))) if playlist.keys != [None]: - keys = [{"url": key.uri, "method": key.method, "iv": key.iv} for key in playlist.keys if key] + keys = [{"url": key.absolute_uri, "method": key.method, "iv": key.iv} for key in playlist.keys if key] else: keys = [None for i in range(0, len(segments))] From 32c40251c7bb8dd9c38d7368fb14c9d6196dfb62 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 28 Nov 2020 11:28:35 -0500 Subject: [PATCH 2/8] Skip Channel Scan on startup after initial run, unless configured --- data/internal_config/fhdhr.json | 7 ++++++- fHDHR/device/channels/__init__.py | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/data/internal_config/fhdhr.json b/data/internal_config/fhdhr.json index 1ead531..3e3bee9 100644 --- a/data/internal_config/fhdhr.json +++ b/data/internal_config/fhdhr.json @@ -61,7 +61,12 @@ "value": false, "config_file": true, "config_web": true - } + }, + "chanscan_on_start":{ + "value": false, + "config_file": true, + "config_web": true + } }, "epg":{ "images":{ diff --git a/fHDHR/device/channels/__init__.py b/fHDHR/device/channels/__init__.py index 7abc1c7..bcfd6ce 100644 --- a/fHDHR/device/channels/__init__.py +++ b/fHDHR/device/channels/__init__.py @@ -1,4 +1,5 @@ import datetime +import time from fHDHR.tools import hours_between_datetime @@ -19,7 +20,9 @@ class Channels(): self.list_update_time = None self.get_db_channels() - self.get_channels() + haseverscanned = self.fhdhr.db.get_fhdhr_value("channels", "scanned_time") + if (self.fhdhr.config.dict["fhdhr"]["chanscan_on_start"] or not haseverscanned): + self.get_channels() def get_channel_obj(self, keyfind, valfind): return next(self.list[fhdhr_id] for fhdhr_id in list(self.list.keys()) if self.list[fhdhr_id].dict[keyfind] == valfind) @@ -68,6 +71,7 @@ class Channels(): if not self.list_update_time: self.fhdhr.logger.info("Found " + str(len(self.list)) + " channels for " + str(self.fhdhr.config.dict["main"]["servicename"])) 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()): From 8a9f2b13616645e4d2a89896c54d36238035017c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 28 Nov 2020 12:08:08 -0500 Subject: [PATCH 3/8] Update Channel Page --- data/www/templates/channels.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/www/templates/channels.html b/data/www/templates/channels.html index 3c61d62..880cb12 100644 --- a/data/www/templates/channels.html +++ b/data/www/templates/channels.html @@ -2,7 +2,7 @@ {% block content %} -

What's On {{ fhdhr.config.dict["fhdhr"]["friendlyname"] }}

+

{{ fhdhr.config.dict["fhdhr"]["friendlyname"] }} Channels

From b5e425e6d198fff315fd6346526f69e29ab7afd7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 28 Nov 2020 12:46:36 -0500 Subject: [PATCH 4/8] Enhance Blocks EPG Method --- fHDHR/device/epgtypes/blocks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fHDHR/device/epgtypes/blocks.py b/fHDHR/device/epgtypes/blocks.py index b03b906..4beb923 100644 --- a/fHDHR/device/epgtypes/blocks.py +++ b/fHDHR/device/epgtypes/blocks.py @@ -29,7 +29,9 @@ class blocksEPG(): } timestamps.append(timestampdict) - for c in self.channels.get_channels(): + for fhdhr_id in list(self.channels.list.keys()): + c = self.channels.list[fhdhr_id].dict + if str(c["number"]) not in list(programguide.keys()): programguide[str(c["number"])] = { "callsign": c["callsign"], From 3b766f380ed8c5d0d1eb673562f7469c1efbb404 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 28 Nov 2020 12:50:32 -0500 Subject: [PATCH 5/8] Improve direct stream chunk key url methods --- fHDHR/device/tuners/stream/direct_stream.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fHDHR/device/tuners/stream/direct_stream.py b/fHDHR/device/tuners/stream/direct_stream.py index 665a0aa..706baef 100644 --- a/fHDHR/device/tuners/stream/direct_stream.py +++ b/fHDHR/device/tuners/stream/direct_stream.py @@ -103,7 +103,7 @@ class Direct_Stream(): for segment, key in zip(segments, keys): chunkurl = segment.absolute_uri - if chunkurl not in played_chunk_urls: + if chunkurl and chunkurl not in played_chunk_urls: played_chunk_urls.append(chunkurl) if (not self.stream_args["duration"] == 0 and @@ -116,9 +116,10 @@ class Direct_Stream(): break # raise TunerError("807 - No Video Data") if key: - keyfile = self.fhdhr.web.session.get(key["url"]).content - cryptor = AES.new(keyfile, AES.MODE_CBC, keyfile) - chunk = cryptor.decrypt(chunk) + if key["url"]: + keyfile = self.fhdhr.web.session.get(key["url"]).content + cryptor = AES.new(keyfile, AES.MODE_CBC, keyfile) + chunk = cryptor.decrypt(chunk) self.fhdhr.logger.info("Passing Through Chunk: %s" % chunkurl) yield chunk From 283aee262f00a0e253b78571e5a116b7eb8d17dc Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 28 Nov 2020 19:03:54 -0500 Subject: [PATCH 6/8] Add Channel Thumbnail Attribute --- fHDHR/device/channels/channel.py | 23 ++++++++++++++++++++--- fHDHR/origin/origin_channels.py | 10 ++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/fHDHR/device/channels/channel.py b/fHDHR/device/channels/channel.py index ad3d7a1..ee79e88 100644 --- a/fHDHR/device/channels/channel.py +++ b/fHDHR/device/channels/channel.py @@ -12,9 +12,19 @@ class Channel(): channel_id = id_system.get(origin_id) else: channel_id = id_system.assign() - self.dict = self.fhdhr.db.get_channel_value(str(channel_id), "dict") or self.create_empty_channel(channel_id) + self.dict = self.fhdhr.db.get_channel_value(str(channel_id), "dict") or self.default_dict(channel_id) + self.verify_dict() self.fhdhr.db.set_channel_value(self.dict["id"], "dict", self.dict) + def verify_dict(self): + """Development Purposes + Add new Channel dict keys + """ + default_dict = self.default_dict(self.dict["id"]) + for key in list(default_dict.keys()): + if key not in list(self.dict.keys()): + self.dict[key] = default_dict[key] + def basics(self, channel_info): """Some Channel Information is Critical""" @@ -46,16 +56,23 @@ class Channel(): if not self.dict["number"]: self.dict["number"] = self.dict["origin_number"] + if "thumbnail" not in list(channel_info.keys()): + channel_info["thumbnail"] = None + self.dict["origin_thumbnail"] = channel_info["thumbnail"] + if not self.dict["thumbnail"]: + self.dict["thumbnail"] = self.dict["origin_thumbnail"] + self.fhdhr.db.set_channel_value(self.dict["id"], "dict", self.dict) - def create_empty_channel(self, channel_id): + def default_dict(self, channel_id): return { "id": str(channel_id), "origin_id": None, "name": None, "origin_name": None, "callsign": None, "origin_callsign": None, "number": None, "origin_number": None, "tags": [], "origin_tags": [], - "enabled": True + "enabled": True, + "thumbnail": None, "origin_thumbnail": None } def destroy(self): diff --git a/fHDHR/origin/origin_channels.py b/fHDHR/origin/origin_channels.py index dbc1bbc..1d3a3ea 100644 --- a/fHDHR/origin/origin_channels.py +++ b/fHDHR/origin/origin_channels.py @@ -8,6 +8,15 @@ class OriginChannels(): self.fhdhr = fhdhr self.origin = origin + def get_channel_thumbnail(self, channel_id): + channel_thumb_url = ("%s%s:%s/service?method=channel.icon&channel_id=%s" % + ("https://" if self.fhdhr.config.dict["origin"]["ssl"] else "http://", + self.fhdhr.config.dict["origin"]["address"], + str(self.fhdhr.config.dict["origin"]["port"]), + str(channel_id) + )) + return channel_thumb_url + def get_channels(self): data_url = ('%s%s:%s/service?method=channel.list&sid=%s' % @@ -36,6 +45,7 @@ class OriginChannels(): "callsign": channel_dict["name"], "number": channel_dict["formatted-number"], "id": channel_dict["id"], + "thumbnail": self.get_channel_thumbnail(channel_dict["id"]) } channel_list.append(clean_station_item) return channel_list From 993873769be1c2b2991b7aeb02dd8d1253e1fc2b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sun, 29 Nov 2020 11:20:49 -0500 Subject: [PATCH 7/8] chanscan_on_start True --- data/internal_config/fhdhr.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/internal_config/fhdhr.json b/data/internal_config/fhdhr.json index 3e3bee9..27446e3 100644 --- a/data/internal_config/fhdhr.json +++ b/data/internal_config/fhdhr.json @@ -63,7 +63,7 @@ "config_web": true }, "chanscan_on_start":{ - "value": false, + "value": true, "config_file": true, "config_web": true } From 3d7f76234a2f9f2b9e8273465a7d6ad90e2eb2bf Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sun, 29 Nov 2020 11:41:01 -0500 Subject: [PATCH 8/8] Verify how Channel Numbers are stored from remapping --- fHDHR/device/channels/channel.py | 2 ++ fHDHR/http/api/m3u.py | 2 +- fHDHR/http/api/watch.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/fHDHR/device/channels/channel.py b/fHDHR/device/channels/channel.py index ee79e88..5cc8a46 100644 --- a/fHDHR/device/channels/channel.py +++ b/fHDHR/device/channels/channel.py @@ -84,6 +84,8 @@ class Channel(): def set_status(self, updatedict): for key in list(updatedict.keys()): + if key == "number": + updatedict[key] = str(float(updatedict[key])) self.dict[key] = updatedict[key] self.fhdhr.db.set_channel_value(self.dict["id"], "dict", self.dict) diff --git a/fHDHR/http/api/m3u.py b/fHDHR/http/api/m3u.py index 1bafffc..940e7c7 100644 --- a/fHDHR/http/api/m3u.py +++ b/fHDHR/http/api/m3u.py @@ -46,7 +46,7 @@ class M3U(): channel_obj = self.fhdhr.device.channels.list[fhdhr_id] if channel_obj.enabled: channel_items.append(channel_obj) - elif channel in self.fhdhr.device.channels.get_channel_list("number"): + elif str(channel) in [str(x) for x in self.fhdhr.device.channels.get_channel_list("number")]: channel_obj = self.fhdhr.device.channels.get_channel_obj("number", channel) fileName = str(channel_obj.number) + ".m3u" if channel_obj.enabled: diff --git a/fHDHR/http/api/watch.py b/fHDHR/http/api/watch.py index 7424cb9..56825c3 100644 --- a/fHDHR/http/api/watch.py +++ b/fHDHR/http/api/watch.py @@ -34,7 +34,7 @@ class Watch(): if not channel_number: return "Missing Channel" - if channel_number not in self.fhdhr.device.channels.get_channel_list("number"): + if str(channel_number) not in [str(x) for x in self.fhdhr.device.channels.get_channel_list("number")]: response = Response("Not Found", status=404) response.headers["X-fHDHR-Error"] = "801 - Unknown Channel" self.fhdhr.logger.error(response.headers["X-fHDHR-Error"])