From e28dbf4dccc85205d294e11c544eccbc7446f2fe Mon Sep 17 00:00:00 2001 From: kiddac Date: Sat, 25 Jan 2025 16:02:54 +0000 Subject: [PATCH] better memory management for series experiment --- .../BouquetMakerXtream/bouquetsettings.py | 12 +- .../BouquetMakerXtream/buildbouquets.py | 291 +++++++++--------- .../BouquetMakerXtream/checkinternet.py | 2 +- .../BouquetMakerXtream/globalfunctions.py | 29 +- .../Extensions/BouquetMakerXtream/plugin.py | 2 +- .../BouquetMakerXtream/processfiles.py | 1 + .../Extensions/BouquetMakerXtream/update.py | 287 ++++++++--------- .../Extensions/BouquetMakerXtream/version.txt | 2 +- CONTROL/control | 2 +- 9 files changed, 331 insertions(+), 297 deletions(-) diff --git a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/bouquetsettings.py b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/bouquetsettings.py index cec3773..6aa25cc 100644 --- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/bouquetsettings.py +++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/bouquetsettings.py @@ -330,7 +330,7 @@ def createSetup(self): self.list.append(getConfigListEntry(_("Short name or provider name:"), self.iptvname_cfg)) self.list.append(getConfigListEntry(_("Use name as bouquet prefix"), self.prefix_name_cfg)) - if self.hide_live is False: + if not self.hide_live: self.list.append(getConfigListEntry(_("Show LIVE category if available:"), self.show_live_cfg)) if self.show_live_cfg.value: self.list.append(getConfigListEntry(_("Stream Type LIVE:"), self.live_type_cfg)) @@ -339,17 +339,15 @@ def createSetup(self): self.list.append(getConfigListEntry(_("LIVE category bouquet order"), self.live_category_order_cfg)) self.list.append(getConfigListEntry(_("LIVE stream bouquet order"), self.live_stream_order_cfg)) - if self.hide_vod is False: + if not self.hide_vod: self.list.append(getConfigListEntry(_("Show VOD category if available:"), self.show_vod_cfg)) - if self.hide_series is False: + if not self.hide_series: self.list.append(getConfigListEntry(_("Show SERIES category if available:"), self.show_series_cfg)) - if self.hide_vod is False or self.hide_series is False: + if not self.hide_vod or not self.hide_series: if self.show_vod_cfg.value or self.show_series_cfg.value: self.list.append(getConfigListEntry(_("Stream Type VOD/SERIES:"), self.vod_type_cfg)) - - if self.show_vod_cfg.value: self.list.append(getConfigListEntry(_("VOD/SERIES category bouquet order"), self.vod_category_order_cfg)) self.list.append(getConfigListEntry(_("VOD/SERIES streams bouquet order"), self.vod_stream_order_cfg)) @@ -433,7 +431,7 @@ def save(self): self["config"].instance.moveSelectionTo(1) # hack to hide texthelper - if self.show_live_cfg.value is False and self.show_vod_cfg.value is False and self.show_series_cfg.value is False: + if not self.show_live_cfg.value and not self.show_vod_cfg.value and not self.show_series_cfg.value: self.session.open(MessageBox, _("No bouquets selected."), MessageBox.TYPE_ERROR, timeout=5) self.createSetup() return diff --git a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/buildbouquets.py b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/buildbouquets.py index 92cbc9e..02a53b6 100644 --- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/buildbouquets.py +++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/buildbouquets.py @@ -63,18 +63,21 @@ def __init__(self, session): self.progress_value = 0 self.progress_range = 0 - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + settings = glob.current_playlist["settings"] + playlist_info = glob.current_playlist["playlist_info"] + + if playlist_info == "xtream": self.progress_range += 2 * sum([ - glob.current_playlist["settings"]["show_live"], - glob.current_playlist["settings"]["show_vod"], - glob.current_playlist["settings"]["show_series"] + settings["show_live"], + settings["show_vod"], + settings["show_series"] ]) else: self.progress_range += 1 # Base range for non-xtream playlists self.progress_range += sum([ - glob.current_playlist["settings"]["show_live"], - glob.current_playlist["settings"]["show_vod"], - glob.current_playlist["settings"]["show_series"] + settings["show_live"], + settings["show_vod"], + settings["show_series"] ]) self.playlists_all = bmx.getPlaylistJson() @@ -105,9 +108,12 @@ def nextJob(self, actiontext, function): def start(self): if debugs: print("*** start ***") + + playlist_info = glob.current_playlist["playlist_info"] + self["progress"].setRange((0, self.progress_range)) self["progress"].setValue(self.progress_value) - self.safe_name = bmx.safeName(glob.current_playlist["playlist_info"]["name"]) + self.safe_name = bmx.safeName(playlist_info["name"]) self.old_name = bmx.safeName(glob.old_name) self.deleteExistingRefs() @@ -162,17 +168,17 @@ def makeUrlList(self): self.series_url_list = [] self.external_url_list = [] - full_url = glob.current_playlist["playlist_info"]["full_url"] + settings = glob.current_playlist["settings"] + playlist_info = glob.current_playlist["playlist_info"] - if glob.current_playlist["playlist_info"]["playlist_type"] != "local": - protocol = glob.current_playlist["playlist_info"]["protocol"] - domain = glob.current_playlist["playlist_info"]["domain"] - port = glob.current_playlist["playlist_info"]["port"] + full_url = playlist_info["full_url"] - if port: - self.host = protocol + domain + ":" + str(port) - else: - self.host = protocol + domain + if playlist_info["playlist_type"] != "local": + protocol = playlist_info["protocol"] + domain = playlist_info["domain"] + port = playlist_info["port"] + + self.host = protocol + domain + (":" + str(port) if port else "") self.host_encoded = quote(self.host) @@ -180,42 +186,42 @@ def makeUrlList(self): value = ord(j) self.unique_ref += value - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": - player_api = str(glob.current_playlist["playlist_info"]["player_api"]) - self.xmltv_api = str(glob.current_playlist["playlist_info"]["xmltv_api"]) + if playlist_info["playlist_type"] == "xtream": + player_api = str(playlist_info["player_api"]) + self.xmltv_api = str(playlist_info["xmltv_api"]) try: - if "next_days" in glob.current_playlist["settings"] and glob.current_playlist["settings"]["next_days"] != "0": - self.xmltv_api = str(glob.current_playlist["playlist_info"]["xmltv_api"]) + "&next_days=" + str(glob.current_playlist["settings"]["next_days"]) + if "next_days" in settings and settings["next_days"] != "0": + self.xmltv_api = str(playlist_info["xmltv_api"]) + "&next_days=" + str(settings["next_days"]) except: pass - self.username = glob.current_playlist["playlist_info"]["username"] - self.password = glob.current_playlist["playlist_info"]["password"] - self.output = glob.current_playlist["playlist_info"]["output"] + self.username = playlist_info["username"] + self.password = playlist_info["password"] + self.output = playlist_info["output"] - if glob.current_playlist["settings"]["show_live"]: + if settings["show_live"]: self.live_url_list.append([player_api + "&action=get_live_streams", 3, "json"]) - if glob.current_playlist["settings"]["show_vod"]: + if settings["show_vod"]: self.vod_url_list.append([player_api + "&action=get_vod_streams", 4, "json"]) - if glob.current_playlist["settings"]["show_series"]: + if settings["show_series"]: self.series_url_list.append([player_api + "&action=get_series", 5, "json"]) # self.simple = str(self.host) + "/get.php?username=" + str(self.username) + "&password=" + str(self.password) + "&type=simple&output=" + str(self.output) - if glob.current_playlist["settings"]["show_live"]: + if settings["show_live"]: self.nextJob(_("Downloading live data..."), self.downloadLive) - elif glob.current_playlist["settings"]["show_vod"]: + elif settings["show_vod"]: self.nextJob(_("Downloading VOD data..."), self.downloadVod) - elif glob.current_playlist["settings"]["show_series"]: + elif settings["show_series"]: self.nextJob(_("Downloading series data..."), self.downloadSeries) else: self.finished() - elif glob.current_playlist["playlist_info"]["playlist_type"] == "external": + elif playlist_info["playlist_type"] == "external": self.external_url_list.append([full_url, 6, "text"]) self.nextJob(_("Downloading external playlist..."), self.downloadExternal) else: @@ -259,7 +265,11 @@ def loadLocal(self): self.parseM3u8Playlist() def processDownloads(self, stream_type, outputtype=None): - print("*** processDownloads ***") + if debugs: + print("*** processDownloads ***") + + playlist_info = glob.current_playlist["playlist_info"] + if stream_type == "live": self.url_list = self.live_url_list @@ -294,7 +304,7 @@ def processDownloads(self, stream_type, outputtype=None): response = result[1] if response: - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + if playlist_info["playlist_type"] == "xtream": if category == 3: self.live_streams = response @@ -314,35 +324,39 @@ def loadLive(self): if debugs: print("*** loadLive ***") self.live_stream_data = [] - stream_type = glob.current_playlist["settings"]["live_type"] - live_categories = glob.current_playlist["data"]["live_categories"] + settings = glob.current_playlist["settings"] + playlist_info = glob.current_playlist["playlist_info"] + data = glob.current_playlist["data"] + + stream_type = settings["live_type"] + live_categories = data["live_categories"] if not live_categories: - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + if playlist_info["playlist_type"] == "xtream": - if glob.current_playlist["settings"]["show_vod"]: + if settings["show_vod"]: self.nextJob(_("Downloading VOD data..."), self.downloadVod) - elif glob.current_playlist["settings"]["show_series"]: + elif settings["show_series"]: self.nextJob(_("Downloading series data..."), self.downloadSeries) else: self.finished() return else: - if glob.current_playlist["settings"]["show_vod"]: + if settings["show_vod"]: self.nextJob(_("Process VOD data..."), self.loadVod) - elif glob.current_playlist["settings"]["show_series"]: + elif settings["show_series"]: self.nextJob(_("Processing series data..."), self.loadSeries) else: self.finished() return - if glob.current_playlist["playlist_info"]["playlist_type"] != "xtream": - self.live_streams = glob.current_playlist["data"]["live_streams"] + if playlist_info["playlist_type"] != "xtream": + self.live_streams = data["live_streams"] - if glob.current_playlist["settings"]["live_category_order"] == "alphabetical": + if settings["live_category_order"] == "alphabetical": live_categories.sort(key=lambda k: k["category_name"].lower()) if self.live_streams: @@ -353,8 +367,8 @@ def loadLive(self): if not stream_id or not category_id: continue - if str(category_id) in glob.current_playlist["data"]["live_categories_hidden"] or \ - str(stream_id) in glob.current_playlist["data"]["live_streams_hidden"]: + if str(category_id) in data["live_categories_hidden"] or \ + str(stream_id) in data["live_streams_hidden"]: continue if "name" not in channel or not channel["name"]: @@ -391,7 +405,7 @@ def loadLive(self): bouquet_string = "" - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + if playlist_info["playlist_type"] == "xtream": bouquet_string += "#SERVICE " + str(stream_type) + str(custom_sid) + str(self.host_encoded) + "/live/" + str(self.username) + "/" + str(self.password) + "/" + str(stream_id) + "." + str(self.output) + ":" + str(name) + "\n" else: source = quote(channel.get("source", "")) @@ -408,13 +422,20 @@ def loadLive(self): }) if self.live_stream_data: - if cfg.groups.value and self.bouquet_tv is False: + + # Sort streams once (cached results) + if settings["live_stream_order"] == "alphabetical": + self.live_stream_data.sort(key=lambda x: x["name"].lower()) + elif settings["live_stream_order"] == "added": + self.live_stream_data.sort(key=lambda x: x["added"], reverse=True) + + if cfg.groups.value and not self.bouquet_tv: self.buildBouquetTvGroupedFile() bouquet_tv_string = "" - if cfg.groups.value and self.userbouquet is False: - bouquet_tv_string += "#NAME " + str(glob.current_playlist["playlist_info"]["name"]) + "\n" + if cfg.groups.value and not self.userbouquet: + bouquet_tv_string += "#NAME " + str(playlist_info["name"]) + "\n" filename = "" @@ -425,7 +446,7 @@ def loadLive(self): exists = any(item for item in self.live_stream_data if item.get("category_id") == category_id) - if str(category_id) not in glob.current_playlist["data"]["live_categories_hidden"] and exists: + if str(category_id) not in data["live_categories_hidden"] and exists: if cfg.groups.value: filename = "/etc/enigma2/userbouquet.bouquetmakerxtream_" + str(self.safe_name) + ".tv" bouquet = "subbouquet" @@ -448,13 +469,13 @@ def loadLive(self): exists = any(item for item in self.live_stream_data if item.get("category_id") == category_id) - if str(category_id) not in glob.current_playlist["data"]["live_categories_hidden"] and exists: + if str(category_id) not in data["live_categories_hidden"] and exists: bouquet_title = self.safe_name + "_" + bmx.safeName(category["category_name"]) self.total_count += 1 output_string = "" string_list = [] - if glob.current_playlist["settings"]["prefix_name"] and cfg.groups.value is False: + if settings["prefix_name"] and not cfg.groups.value: output_string += "#NAME " + self.safe_name + " - " + category["category_name"] + "\n" else: output_string += "#NAME " + category["category_name"] + "\n" @@ -463,12 +484,6 @@ def loadLive(self): if str(category_id) == str(stream["category_id"]): string_list.append([str(stream["bouquet_string"]), str(stream["name"]), str(stream["added"])]) - if glob.current_playlist["settings"]["live_stream_order"] == "alphabetical": - string_list.sort(key=lambda x: x[1].lower()) - - if glob.current_playlist["settings"]["live_stream_order"] == "added": - string_list.sort(key=lambda x: x[2].lower(), reverse=True) - for string in string_list: output_string += string[0] @@ -483,24 +498,24 @@ def loadLive(self): self.progress_value += 1 self["progress"].setValue(self.progress_value) - glob.current_playlist["data"]["live_categories"] = [] - glob.current_playlist["data"]["live_streams"] = [] + data["live_categories"] = [] + data["live_streams"] = [] - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + if playlist_info["playlist_type"] == "xtream": if live_categories and epgimporter: self.buildXmltvSource() - if glob.current_playlist["settings"]["show_vod"]: + if settings["show_vod"]: self.nextJob(_("Downloading VOD data..."), self.downloadVod) - elif glob.current_playlist["settings"]["show_series"]: + elif settings["show_series"]: self.nextJob(_("Downloading series data..."), self.downloadSeries) else: self.finished() else: - if glob.current_playlist["settings"]["show_vod"]: + if settings["show_vod"]: self.nextJob(_("Process VOD data..."), self.loadVod) - elif glob.current_playlist["settings"]["show_series"]: + elif settings["show_series"]: self.nextJob(_("Processing series data..."), self.loadSeries) else: self.finished() @@ -509,29 +524,34 @@ def loadVod(self): if debugs: print("*** loadVod ***") self.vod_stream_data = [] - stream_type = glob.current_playlist["settings"]["vod_type"] - vod_categories = glob.current_playlist["data"]["vod_categories"] + + settings = glob.current_playlist["settings"] + playlist_info = glob.current_playlist["playlist_info"] + data = glob.current_playlist["data"] + + stream_type = settings["vod_type"] + vod_categories = data["vod_categories"] if not vod_categories: - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + if playlist_info["playlist_type"] == "xtream": - if glob.current_playlist["settings"]["show_series"]: + if settings["show_series"]: self.nextJob(_("Downloading series data..."), self.downloadSeries) else: self.finished() return else: - if glob.current_playlist["settings"]["show_series"]: + if settings["show_series"]: self.nextJob(_("Processing series data..."), self.loadSeries) else: self.finished() return - if glob.current_playlist["playlist_info"]["playlist_type"] != "xtream": - self.vod_streams = glob.current_playlist["data"]["vod_streams"] + if playlist_info["playlist_type"] != "xtream": + self.vod_streams = data["vod_streams"] - if glob.current_playlist["settings"]["vod_category_order"] == "alphabetical": + if settings["vod_category_order"] == "alphabetical": vod_categories.sort(key=lambda k: k["category_name"].lower()) if self.vod_streams: @@ -542,8 +562,8 @@ def loadVod(self): if not stream_id or not category_id: continue - if str(category_id) in glob.current_playlist["data"]["vod_categories_hidden"] or \ - str(stream_id) in glob.current_playlist["data"]["vod_streams_hidden"]: + if str(category_id) in data["vod_categories_hidden"] or \ + str(stream_id) in data["vod_streams_hidden"]: continue if "name" not in channel or not channel["name"]: @@ -560,7 +580,7 @@ def loadVod(self): custom_sid = ":0:1:" + str(format(bouquet_id1, "x")) + ":" + str(format(bouquet_id2, "x")) + ":" + str(format(self.unique_ref, "x")) + ":0:0:0:0:" bouquet_string = "" - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + if playlist_info["playlist_type"] == "xtream": extension = channel["container_extension"] bouquet_string += "#SERVICE " + str(stream_type) + str(custom_sid) + str(self.host_encoded) + "/movie/" + str(self.username) + "/" + str(self.password) + "/" + str(stream_id) + "." + str(extension) + ":" + str(name) + "\n" else: @@ -577,13 +597,19 @@ def loadVod(self): }) if self.vod_stream_data: - if cfg.groups.value and self.bouquet_tv is False: + + if settings["vod_stream_order"] == "alphabetical": + self.vod_stream_data.sort(key=lambda x: x["name"].lower()) + elif settings["vod_stream_order"] == "added": + self.vod_stream_data.sort(key=lambda x: x["added"], reverse=True) + + if cfg.groups.value and not self.bouquet_tv: self.buildBouquetTvGroupedFile() bouquet_tv_string = "" - if cfg.groups.value and self.userbouquet is False: - bouquet_tv_string += "#NAME " + str(glob.current_playlist["playlist_info"]["name"]) + "\n" + if cfg.groups.value and not self.userbouquet: + bouquet_tv_string += "#NAME " + str(playlist_info["name"]) + "\n" filename = "" @@ -594,7 +620,7 @@ def loadVod(self): exists = any(item for item in self.vod_stream_data if item.get("category_id") == category_id) - if str(category_id) not in glob.current_playlist["data"]["vod_categories_hidden"] and exists: + if str(category_id) not in data["vod_categories_hidden"] and exists: if cfg.groups.value: filename = "/etc/enigma2/userbouquet.bouquetmakerxtream_" + str(self.safe_name) + ".tv" bouquet = "subbouquet" @@ -617,13 +643,13 @@ def loadVod(self): exists = any(item for item in self.vod_stream_data if item.get("category_id") == category_id) - if str(category_id) not in glob.current_playlist["data"]["vod_categories_hidden"] and exists: + if str(category_id) not in data["vod_categories_hidden"] and exists: bouquet_title = self.safe_name + "_" + bmx.safeName(category["category_name"]) self.total_count += 1 output_string = "" string_list = [] - if glob.current_playlist["settings"]["prefix_name"] and cfg.groups.value is False: + if settings["prefix_name"] and not cfg.groups.value: output_string += "#NAME " + self.safe_name + " VOD - " + category["category_name"] + "\n" else: output_string += "#NAME " + "VOD - " + category["category_name"] + "\n" @@ -632,12 +658,6 @@ def loadVod(self): if str(category_id) == str(stream["category_id"]): string_list.append([str(stream["bouquet_string"]), str(stream["name"]), str(stream["added"])]) - if glob.current_playlist["settings"]["vod_stream_order"] == "alphabetical": - string_list.sort(key=lambda x: x[1].lower()) - - if glob.current_playlist["settings"]["vod_stream_order"] == "added": - string_list.sort(key=lambda x: x[2].lower(), reverse=True) - for string in string_list: output_string += string[0] @@ -652,16 +672,16 @@ def loadVod(self): self.progress_value += 1 self["progress"].setValue(self.progress_value) - glob.current_playlist["data"]["vod_categories"] = [] - glob.current_playlist["data"]["vod_streams"] = [] + data["vod_categories"] = [] + data["vod_streams"] = [] - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": - if glob.current_playlist["settings"]["show_series"]: + if playlist_info["playlist_type"] == "xtream": + if settings["show_series"]: self.nextJob(_("Downloading series data..."), self.downloadSeries) else: self.finished() else: - if glob.current_playlist["settings"]["show_series"]: + if settings["show_series"]: self.nextJob(_("Processing series data..."), self.loadSeries) else: self.finished() @@ -669,53 +689,42 @@ def loadVod(self): def loadSeries(self): if debugs: print("*** loadSeries ***") + self.series_stream_data = [] - stream_type = glob.current_playlist["settings"]["vod_type"] - series_categories = glob.current_playlist["data"]["series_categories"] + + settings = glob.current_playlist["settings"] + playlist_info = glob.current_playlist["playlist_info"] + data = glob.current_playlist["data"] + + stream_type = settings["vod_type"] + series_categories = data["series_categories"] if not series_categories: self.finished() return - if glob.current_playlist["settings"]["vod_category_order"] == "alphabetical": + if settings["vod_category_order"] == "alphabetical": series_categories.sort(key=lambda k: k["category_name"].lower()) - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": - protocol = glob.current_playlist["playlist_info"]["protocol"] - domain = glob.current_playlist["playlist_info"]["domain"] - port = glob.current_playlist["playlist_info"]["port"] + if playlist_info["playlist_type"] == "xtream": + protocol = playlist_info["protocol"] + domain = playlist_info["domain"] + port = playlist_info["port"] - if port: - self.host = protocol + domain + ":" + str(port) - else: - self.host = protocol + domain + self.host = protocol + domain + (":" + str(port) if port else "") - self.username = glob.current_playlist["playlist_info"]["username"] - self.password = glob.current_playlist["playlist_info"]["password"] - self.output = glob.current_playlist["playlist_info"]["output"] + self.username = playlist_info["username"] + self.password = playlist_info["password"] + self.output = playlist_info["output"] geturl = str(self.host) + "/get.php?username=" + str(self.username) + "&password=" + str(self.password) + "&type=m3u_plus&output=" + str(self.output) - # Directly use the URL in the download function - output_file = '/var/volatile/tmp/bouquetmakerxtream/temp' - - result = bmx.downloadUrlMulti([geturl, 7, "text"], output_file) - - category = result[0] - response = "" - - with open(output_file, 'r') as f: - response = f.read() + response = bmx.downloadUrlMulti([geturl, 7, "text"]) if response: - self.seriesParseM3u8Playlist(response) + self.seriesParseM3u8Playlist(response[1]) - # Delete the file after processing - - if os.path.exists(output_file): - os.remove(output_file) - - self.series_streams = glob.current_playlist["data"]["series_streams"] + self.series_streams = data["series_streams"] if self.series_streams: for channel in self.series_streams: @@ -725,7 +734,7 @@ def loadSeries(self): if not stream_id or not category_id: continue - if str(category_id) in glob.current_playlist["data"]["series_categories_hidden"]: + if str(category_id) in data["series_categories_hidden"]: continue if "name" not in channel or not channel["name"]: @@ -753,13 +762,19 @@ def loadSeries(self): }) if self.series_stream_data: - if cfg.groups.value and self.bouquet_tv is False: + + if settings["vod_stream_order"] == "alphabetical": + self.series_stream_data.sort(key=lambda x: x["name"].lower()) + elif settings["vod_stream_order"] == "added": + self.series_stream_data.sort(key=lambda x: x["added"], reverse=True) + + if cfg.groups.value and not self.bouquet_tv: self.buildBouquetTvGroupedFile() bouquet_tv_string = "" - if cfg.groups.value and self.userbouquet is False: - bouquet_tv_string += "#NAME " + str(glob.current_playlist["playlist_info"]["name"]) + "\n" + if cfg.groups.value and not self.userbouquet: + bouquet_tv_string += "#NAME " + str(playlist_info["name"]) + "\n" filename = "" @@ -771,7 +786,7 @@ def loadSeries(self): exists = any(item for item in self.series_stream_data if item.get("category_id") == category_id) - if str(category_id) not in glob.current_playlist["data"]["series_categories_hidden"] and exists: + if str(category_id) not in data["series_categories_hidden"] and exists: if cfg.groups.value: filename = "/etc/enigma2/userbouquet.bouquetmakerxtream_" + str(self.safe_name) + ".tv" bouquet = "subbouquet" @@ -794,13 +809,13 @@ def loadSeries(self): exists = any(item for item in self.series_stream_data if item.get("category_id") == category_id) - if str(category_id) not in glob.current_playlist["data"]["series_categories_hidden"] and exists: + if str(category_id) not in data["series_categories_hidden"] and exists: bouquet_title = self.safe_name + "_" + bmx.safeName(category["category_name"]) self.total_count += 1 output_string = "" string_list = [] - if glob.current_playlist["settings"]["prefix_name"] and cfg.groups.value is False: + if settings["prefix_name"] and not cfg.groups.value: output_string += "#NAME " + self.safe_name + " Series - " + category["category_name"] + "\n" else: output_string += "#NAME " + "Series - " + category["category_name"] + "\n" @@ -809,12 +824,6 @@ def loadSeries(self): if str(category_id) == str(stream["category_id"]): string_list.append([str(stream["bouquet_string"]), str(stream["name"]), str(stream["added"])]) - if glob.current_playlist["settings"]["vod_stream_order"] == "alphabetical": - string_list.sort(key=lambda x: x[1].lower()) - - if glob.current_playlist["settings"]["vod_stream_order"] == "added": - string_list.sort(key=lambda x: x[2].lower(), reverse=True) - for string in string_list: output_string += string[0] @@ -829,8 +838,8 @@ def loadSeries(self): self.progress_value += 1 self["progress"].setValue(self.progress_value) - glob.current_playlist["data"]["series_categories"] = [] - glob.current_playlist["data"]["series_streams"] = [] + data["series_categories"] = [] + data["series_streams"] = [] self.finished() @@ -869,7 +878,7 @@ def buildBouquetTvGroupedFile(self): exists = True break - if exists is False: + if not exists: with open("/etc/enigma2/bouquets.tv", "a+") as f: bouquet_tv_string = '#SERVICE 1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "' + str(groupname) + '" ORDER BY bouquet\n' f.write(str(bouquet_tv_string)) diff --git a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/checkinternet.py b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/checkinternet.py index b6d4be7..fa22101 100644 --- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/checkinternet.py +++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/checkinternet.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -debugs = True +debugs = False def check_internet(): diff --git a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/globalfunctions.py b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/globalfunctions.py index 9a951d8..7b1232b 100644 --- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/globalfunctions.py +++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/globalfunctions.py @@ -144,18 +144,41 @@ def downloadUrlMulti(url, output_file=None): if ext == "json": json_content = r.json() return category, json_content - else: + + chunk_size = 8192 * 8 # 128 KB + + if output_file: + # Save to the specified output file output_dir = os.path.dirname(output_file) if not os.path.exists(output_dir): os.makedirs(output_dir) - chunk_size = 8192 * 8 # 128 KB with open(output_file, 'wb') as f: for chunk in r.iter_content(chunk_size=chunk_size): - f.write(chunk) + if chunk: # Only write non-empty chunks + f.write(chunk) return category, output_file + else: + # Collect chunks into memory and return as content + if pythonVer == 2: + content = '' + else: + content = b"" + + for chunk in r.iter_content(chunk_size=chunk_size): + if chunk: # Only append non-empty chunks + if ext == "text": + if pythonVer == 2: + content += chunk.decode('utf-8', errors='ignore') + else: + content += chunk.decode('utf-8', errors='ignore').encode('utf-8') + else: + content += chunk + + return category, content + except requests.Timeout as e: print("Error message: {}".format(str(e))) return category, "" diff --git a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/plugin.py b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/plugin.py index 7384156..f378d93 100644 --- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/plugin.py +++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/plugin.py @@ -46,7 +46,7 @@ except ImportError: hasConcurrent = False -debugs = True +debugs = False pythonFull = float(str(sys.version_info.major) + "." + str(sys.version_info.minor)) pythonVer = sys.version_info.major diff --git a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/processfiles.py b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/processfiles.py index 7fda7e4..8c14b8c 100644 --- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/processfiles.py +++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/processfiles.py @@ -56,6 +56,7 @@ def processFiles(): with open(playlist_file, "w") as f: for line in lines: + line = line.strip() line = re.sub(" +", " ", line) line = line.strip(" ") if not line.startswith(("http://", "https://", "#")): diff --git a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/update.py b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/update.py index b304760..0a2effd 100644 --- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/update.py +++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/update.py @@ -117,26 +117,29 @@ def bouquetLoop(self): self.progress_value = 0 self.progress_range = 0 - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": - if glob.current_playlist["settings"]["show_live"] is True: + settings = glob.current_playlist["settings"] + playlist_info = glob.current_playlist["playlist_info"] + + if playlist_info["playlist_type"] == "xtream": + if settings["show_live"] is True: self.progress_range += 2 - if glob.current_playlist["settings"]["show_vod"] is True: + if settings["show_vod"] is True: self.progress_range += 2 - if glob.current_playlist["settings"]["show_series"] is True: + if settings["show_series"] is True: self.progress_range += 2 else: self.progress_range += 1 - if glob.current_playlist["settings"]["show_live"] is True: + if settings["show_live"] is True: self.progress_range += 1 - if glob.current_playlist["settings"]["show_vod"] is True: + if settings["show_vod"] is True: self.progress_range += 1 - if glob.current_playlist["settings"]["show_series"] is True: + if settings["show_series"] is True: self.progress_range += 1 self.start() @@ -194,17 +197,17 @@ def makeUrlList(self): self.series_url_list = [] self.external_url_list = [] - full_url = glob.current_playlist["playlist_info"]["full_url"] + settings = glob.current_playlist["settings"] + playlist_info = glob.current_playlist["playlist_info"] - if glob.current_playlist["playlist_info"]["playlist_type"] != "local": - protocol = glob.current_playlist["playlist_info"]["protocol"] - domain = glob.current_playlist["playlist_info"]["domain"] - port = glob.current_playlist["playlist_info"]["port"] + full_url = playlist_info["full_url"] - if port: - self.host = protocol + domain + ":" + str(port) - else: - self.host = protocol + domain + if playlist_info["playlist_type"] != "local": + protocol = playlist_info["protocol"] + domain = playlist_info["domain"] + port = playlist_info["port"] + + self.host = protocol + domain + (":" + str(port) if port else "") self.host_encoded = quote(self.host) @@ -212,45 +215,45 @@ def makeUrlList(self): value = ord(j) self.unique_ref += value - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": - player_api = str(glob.current_playlist["playlist_info"]["player_api"]) - self.xmltv_api = str(glob.current_playlist["playlist_info"]["xmltv_api"]) + if playlist_info["playlist_type"] == "xtream": + player_api = str(playlist_info["player_api"]) + self.xmltv_api = str(playlist_info["xmltv_api"]) try: - if "next_days" in glob.current_playlist["settings"] and glob.current_playlist["settings"]["next_days"] != "0": - self.xmltv_api = str(glob.current_playlist["playlist_info"]["xmltv_api"]) + "&next_days=" + str(glob.current_playlist["settings"]["next_days"]) + if "next_days" in settings and settings["next_days"] != "0": + self.xmltv_api = str(playlist_info["xmltv_api"]) + "&next_days=" + str(settings["next_days"]) except: pass - self.username = glob.current_playlist["playlist_info"]["username"] - self.password = glob.current_playlist["playlist_info"]["password"] - self.output = glob.current_playlist["playlist_info"]["output"] + self.username = playlist_info["username"] + self.password = playlist_info["password"] + self.output = playlist_info["output"] - if glob.current_playlist["settings"]["show_live"]: + if settings["show_live"]: self.live_url_list.append([player_api + "&action=get_live_categories", 0, "json"]) self.live_url_list.append([player_api + "&action=get_live_streams", 3, "json"]) - if glob.current_playlist["settings"]["show_vod"]: + if settings["show_vod"]: self.vod_url_list.append([player_api + "&action=get_vod_categories", 1, "json"]) self.vod_url_list.append([player_api + "&action=get_vod_streams", 4, "json"]) - if glob.current_playlist["settings"]["show_series"]: + if settings["show_series"]: self.series_url_list.append([player_api + "&action=get_series_categories", 2, "json"]) self.series_url_list.append([player_api + "&action=get_series", 5, "json"]) # self.simple = str(self.host) + "/get.php?username=" + str(self.username) + "&password=" + str(self.password) + "&type=simple&output=" + str(self.output) - if glob.current_playlist["settings"]["show_live"]: + if settings["show_live"]: self.nextJob(_("Downloading live data..."), self.downloadLive) - elif glob.current_playlist["settings"]["show_vod"]: + elif settings["show_vod"]: self.nextJob(_("Downloading VOD data..."), self.downloadVod) - elif glob.current_playlist["settings"]["show_series"]: + elif settings["show_series"]: self.nextJob(_("Downloading series data..."), self.downloadSeries) else: self.finished() - elif glob.current_playlist["playlist_info"]["playlist_type"] == "external": + elif playlist_info["playlist_type"] == "external": self.external_url_list.append([full_url, 6, "text"]) self.nextJob(_("Downloading external playlist..."), self.downloadExternal) else: @@ -288,6 +291,9 @@ def loadLocal(self): self.parseM3u8Playlist() def processDownloads(self, stream_type, outputtype=None): + + playlist_info = glob.current_playlist["playlist_info"] + if stream_type == "live": self.url_list = self.live_url_list @@ -329,7 +335,7 @@ def processDownloads(self, stream_type, outputtype=None): response = result[1] if response: - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + if playlist_info["playlist_type"] == "xtream": if category == 0: self.live_categories = response @@ -356,39 +362,44 @@ def processDownloads(self, stream_type, outputtype=None): def loadLive(self): self.live_stream_data = [] - stream_type = glob.current_playlist["settings"]["live_type"] + + settings = glob.current_playlist["settings"] + playlist_info = glob.current_playlist["playlist_info"] + data = glob.current_playlist["data"] + + stream_type = settings["live_type"] if self.live_categories: - glob.current_playlist["data"]["live_categories"] = self.live_categories + data["live_categories"] = self.live_categories - live_categories = glob.current_playlist["data"]["live_categories"] + live_categories = data["live_categories"] if not live_categories: - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + if playlist_info["playlist_type"] == "xtream": - if glob.current_playlist["settings"]["show_vod"]: + if settings["show_vod"]: self.nextJob(_("Downloading VOD data..."), self.downloadVod) - elif glob.current_playlist["settings"]["show_series"]: + elif settings["show_series"]: self.nextJob(_("Downloading series data..."), self.downloadSeries) else: self.finished() return else: - if glob.current_playlist["settings"]["show_vod"]: + if settings["show_vod"]: self.nextJob(_("Process VOD data..."), self.loadVod) - elif glob.current_playlist["settings"]["show_series"]: + elif settings["show_series"]: self.nextJob(_("Processing series data..."), self.loadSeries) else: self.finished() return - if glob.current_playlist["playlist_info"]["playlist_type"] != "xtream": - self.live_streams = glob.current_playlist["data"]["live_streams"] + if playlist_info["playlist_type"] != "xtream": + self.live_streams = data["live_streams"] - if glob.current_playlist["settings"]["live_category_order"] == "alphabetical": + if settings["live_category_order"] == "alphabetical": live_categories.sort(key=lambda k: k["category_name"].lower()) if self.live_streams: @@ -399,8 +410,8 @@ def loadLive(self): if not stream_id or not category_id: continue - if str(category_id) in glob.current_playlist["data"]["live_categories_hidden"] or \ - str(stream_id) in glob.current_playlist["data"]["live_streams_hidden"]: + if str(category_id) in data["live_categories_hidden"] or \ + str(stream_id) in data["live_streams_hidden"]: continue if "name" not in channel or not channel["name"]: @@ -437,7 +448,7 @@ def loadLive(self): bouquet_string = "" - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + if playlist_info["playlist_type"] == "xtream": bouquet_string += "#SERVICE " + str(stream_type) + str(custom_sid) + str(self.host_encoded) + "/live/" + str(self.username) + "/" + str(self.password) + "/" + str(stream_id) + "." + str(self.output) + ":" + str(name) + "\n" else: source = quote(channel.get("source", "")) @@ -454,13 +465,19 @@ def loadLive(self): }) if self.live_stream_data: - if cfg.groups.value and self.bouquet_tv is False: + + if settings["live_stream_order"] == "alphabetical": + self.live_stream_data.sort(key=lambda x: x["name"].lower()) + elif settings["live_stream_order"] == "added": + self.live_stream_data.sort(key=lambda x: x["added"], reverse=True) + + if cfg.groups.value and not self.bouquet_tv: self.buildBouquetTvGroupedFile() bouquet_tv_string = "" - if cfg.groups.value and self.userbouquet is False: - bouquet_tv_string += "#NAME " + str(glob.current_playlist["playlist_info"]["name"]) + "\n" + if cfg.groups.value and not self.userbouquet: + bouquet_tv_string += "#NAME " + str(playlist_info["name"]) + "\n" filename = "" @@ -471,7 +488,7 @@ def loadLive(self): exists = any(item for item in self.live_stream_data if item.get("category_id") == category_id) - if str(category_id) not in glob.current_playlist["data"]["live_categories_hidden"] and exists: + if str(category_id) not in data["live_categories_hidden"] and exists: if cfg.groups.value: filename = "/etc/enigma2/userbouquet.bouquetmakerxtream_" + str(self.safe_name) + ".tv" bouquet = "subbouquet" @@ -494,13 +511,13 @@ def loadLive(self): exists = any(item for item in self.live_stream_data if item.get("category_id") == category_id) - if str(category_id) not in glob.current_playlist["data"]["live_categories_hidden"] and exists: + if str(category_id) not in data["live_categories_hidden"] and exists: bouquet_title = self.safe_name + "_" + bmx.safeName(category["category_name"]) self.total_count += 1 output_string = "" string_list = [] - if glob.current_playlist["settings"]["prefix_name"] and cfg.groups.value is False: + if settings["prefix_name"] and not cfg.groups.value: output_string += "#NAME " + self.safe_name + " - " + category["category_name"] + "\n" else: output_string += "#NAME " + category["category_name"] + "\n" @@ -509,12 +526,6 @@ def loadLive(self): if str(category_id) == str(stream["category_id"]): string_list.append([str(stream["bouquet_string"]), str(stream["name"]), str(stream["added"])]) - if glob.current_playlist["settings"]["live_stream_order"] == "alphabetical": - string_list.sort(key=lambda x: x[1].lower()) - - if glob.current_playlist["settings"]["live_stream_order"] == "added": - string_list.sort(key=lambda x: x[2].lower(), reverse=True) - for string in string_list: output_string += string[0] @@ -530,55 +541,60 @@ def loadLive(self): self.progress_value += 1 self["progress"].setValue(self.progress_value) - glob.current_playlist["data"]["live_categories"] = [] - glob.current_playlist["data"]["live_streams"] = [] + data["live_categories"] = [] + data["live_streams"] = [] - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + if playlist_info["playlist_type"] == "xtream": if live_categories and epgimporter: self.buildXmltvSource() - if glob.current_playlist["settings"]["show_vod"]: + if settings["show_vod"]: self.nextJob(_("Downloading VOD data..."), self.downloadVod) - elif glob.current_playlist["settings"]["show_series"]: + elif settings["show_series"]: self.nextJob(_("Downloading series data..."), self.downloadSeries) else: self.finished() else: - if glob.current_playlist["settings"]["show_vod"]: + if settings["show_vod"]: self.nextJob(_("Process VOD data..."), self.loadVod) - elif glob.current_playlist["settings"]["show_series"]: + elif settings["show_series"]: self.nextJob(_("Processing series data..."), self.loadSeries) else: self.finished() def loadVod(self): self.vod_stream_data = [] - stream_type = glob.current_playlist["settings"]["vod_type"] + + settings = glob.current_playlist["settings"] + playlist_info = glob.current_playlist["playlist_info"] + data = glob.current_playlist["data"] + + stream_type = settings["vod_type"] if self.vod_categories: - glob.current_playlist["data"]["vod_categories"] = self.vod_categories + data["vod_categories"] = self.vod_categories - vod_categories = glob.current_playlist["data"]["vod_categories"] + vod_categories = data["vod_categories"] if not vod_categories: - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": - if glob.current_playlist["settings"]["show_series"]: + if playlist_info["playlist_type"] == "xtream": + if settings["show_series"]: self.nextJob(_("Downloading series data..."), self.downloadSeries) else: self.finished() return else: - if glob.current_playlist["settings"]["show_series"]: + if settings["show_series"]: self.nextJob(_("Processing series data..."), self.loadSeries) else: self.finished() return - if glob.current_playlist["playlist_info"]["playlist_type"] != "xtream": - self.vod_streams = glob.current_playlist["data"]["vod_streams"] + if playlist_info["playlist_type"] != "xtream": + self.vod_streams = data["vod_streams"] - if glob.current_playlist["settings"]["vod_category_order"] == "alphabetical": + if settings["vod_category_order"] == "alphabetical": vod_categories.sort(key=lambda k: k["category_name"].lower()) if self.vod_streams: @@ -589,8 +605,8 @@ def loadVod(self): if not stream_id or not category_id: continue - if str(category_id) in glob.current_playlist["data"]["vod_categories_hidden"] or \ - str(stream_id) in glob.current_playlist["data"]["vod_streams_hidden"]: + if str(category_id) in data["vod_categories_hidden"] or \ + str(stream_id) in data["vod_streams_hidden"]: continue if "name" not in channel or not channel["name"]: @@ -607,7 +623,7 @@ def loadVod(self): custom_sid = ":0:1:" + str(format(bouquet_id1, "x")) + ":" + str(format(bouquet_id2, "x")) + ":" + str(format(self.unique_ref, "x")) + ":0:0:0:0:" bouquet_string = "" - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + if playlist_info["playlist_type"] == "xtream": extension = channel["container_extension"] bouquet_string += "#SERVICE " + str(stream_type) + str(custom_sid) + str(self.host_encoded) + "/movie/" + str(self.username) + "/" + str(self.password) + "/" + str(stream_id) + "." + str(extension) + ":" + str(name) + "\n" else: @@ -624,13 +640,19 @@ def loadVod(self): }) if self.vod_stream_data: - if cfg.groups.value and self.bouquet_tv is False: + + if settings["vod_stream_order"] == "alphabetical": + self.vod_stream_data.sort(key=lambda x: x["name"].lower()) + elif settings["vod_stream_order"] == "added": + self.vod_stream_data.sort(key=lambda x: x["added"], reverse=True) + + if cfg.groups.value and not self.bouquet_tv: self.buildBouquetTvGroupedFile() bouquet_tv_string = "" - if cfg.groups.value and self.userbouquet is False: - bouquet_tv_string += "#NAME " + str(glob.current_playlist["playlist_info"]["name"]) + "\n" + if cfg.groups.value and not self.userbouquet: + bouquet_tv_string += "#NAME " + str(playlist_info["name"]) + "\n" filename = "" @@ -641,7 +663,7 @@ def loadVod(self): exists = any(item for item in self.vod_stream_data if item.get("category_id") == category_id) - if str(category_id) not in glob.current_playlist["data"]["vod_categories_hidden"] and exists: + if str(category_id) not in data["vod_categories_hidden"] and exists: if cfg.groups.value: filename = "/etc/enigma2/userbouquet.bouquetmakerxtream_" + str(self.safe_name) + ".tv" bouquet = "subbouquet" @@ -664,13 +686,13 @@ def loadVod(self): exists = any(item for item in self.vod_stream_data if item.get("category_id") == category_id) - if str(category_id) not in glob.current_playlist["data"]["vod_categories_hidden"] and exists: + if str(category_id) not in data["vod_categories_hidden"] and exists: bouquet_title = self.safe_name + "_" + bmx.safeName(category["category_name"]) self.total_count += 1 output_string = "" string_list = [] - if glob.current_playlist["settings"]["prefix_name"] and cfg.groups.value is False: + if settings["prefix_name"] and not cfg.groups.value: output_string += "#NAME " + self.safe_name + " VOD - " + category["category_name"] + "\n" else: output_string += "#NAME " + "VOD - " + category["category_name"] + "\n" @@ -679,12 +701,6 @@ def loadVod(self): if str(category_id) == str(stream["category_id"]): string_list.append([str(stream["bouquet_string"]), str(stream["name"]), str(stream["added"])]) - if glob.current_playlist["settings"]["vod_stream_order"] == "alphabetical": - string_list.sort(key=lambda x: x[1].lower()) - - if glob.current_playlist["settings"]["vod_stream_order"] == "added": - string_list.sort(key=lambda x: x[2].lower(), reverse=True) - for string in string_list: output_string += string[0] @@ -700,73 +716,61 @@ def loadVod(self): self.progress_value += 1 self["progress"].setValue(self.progress_value) - glob.current_playlist["data"]["vod_categories"] = [] - glob.current_playlist["data"]["vod_streams"] = [] + data["vod_categories"] = [] + data["vod_streams"] = [] - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": - if glob.current_playlist["settings"]["show_series"]: + if playlist_info["playlist_type"] == "xtream": + if settings["show_series"]: self.nextJob(_("Downloading series data..."), self.downloadSeries) else: self.finished() else: - if glob.current_playlist["settings"]["show_series"]: + if settings["show_series"]: self.nextJob(_("Processing series data..."), self.loadSeries) else: self.finished() def loadSeries(self): self.series_stream_data = [] - stream_type = glob.current_playlist["settings"]["vod_type"] + + settings = glob.current_playlist["settings"] + playlist_info = glob.current_playlist["playlist_info"] + data = glob.current_playlist["data"] + + stream_type = settings["vod_type"] if self.series_categories: - glob.current_playlist["data"]["series_categories"] = self.series_categories + data["series_categories"] = self.series_categories - series_categories = glob.current_playlist["data"]["series_categories"] + series_categories = data["series_categories"] if not series_categories: self.finished() return - if glob.current_playlist["settings"]["vod_category_order"] == "alphabetical": + if settings["vod_category_order"] == "alphabetical": series_categories.sort(key=lambda k: k["category_name"].lower()) - if glob.current_playlist["playlist_info"]["playlist_type"] == "xtream": + if playlist_info["playlist_type"] == "xtream": - protocol = glob.current_playlist["playlist_info"]["protocol"] - domain = glob.current_playlist["playlist_info"]["domain"] - port = glob.current_playlist["playlist_info"]["port"] + protocol = playlist_info["protocol"] + domain = playlist_info["domain"] + port = playlist_info["port"] - if port: - self.host = protocol + domain + ":" + str(port) - else: - self.host = protocol + domain + self.host = protocol + domain + (":" + str(port) if port else "") - self.username = glob.current_playlist["playlist_info"]["username"] - self.password = glob.current_playlist["playlist_info"]["password"] - self.output = glob.current_playlist["playlist_info"]["output"] + self.username = playlist_info["username"] + self.password = playlist_info["password"] + self.output = playlist_info["output"] geturl = str(self.host) + "/get.php?username=" + str(self.username) + "&password=" + str(self.password) + "&type=m3u_plus&output=" + str(self.output) - # Directly use the URL in the download function - output_file = '/var/volatile/tmp/bouquetmakerxtream/temp' - - result = bmx.downloadUrlMulti([geturl, 7, "text"], output_file) - - category = result[0] - response = "" - - with open(output_file, 'r') as f: - response = f.read() + response = bmx.downloadUrlMulti([geturl, 7, "text"]) if response: - self.seriesParseM3u8Playlist(response) + self.seriesParseM3u8Playlist(response[1]) - # Delete the file after processing - - if os.path.exists(output_file): - os.remove(output_file) - - self.series_streams = glob.current_playlist["data"]["series_streams"] + self.series_streams = data["series_streams"] if self.series_streams: for channel in self.series_streams: @@ -776,7 +780,7 @@ def loadSeries(self): if not stream_id or not category_id: continue - if str(category_id) in glob.current_playlist["data"]["series_categories_hidden"]: + if str(category_id) in data["series_categories_hidden"]: continue if "name" not in channel or not channel["name"]: @@ -804,13 +808,18 @@ def loadSeries(self): }) if self.series_stream_data: - if cfg.groups.value and self.bouquet_tv is False: + if settings["vod_stream_order"] == "alphabetical": + self.series_stream_data.sort(key=lambda x: x["name"].lower()) + elif settings["vod_stream_order"] == "added": + self.series_stream_data.sort(key=lambda x: x["added"], reverse=True) + + if cfg.groups.value and not self.bouquet_tv: self.buildBouquetTvGroupedFile() bouquet_tv_string = "" - if cfg.groups.value and self.userbouquet is False: - bouquet_tv_string += "#NAME " + str(glob.current_playlist["playlist_info"]["name"]) + "\n" + if cfg.groups.value and not self.userbouquet: + bouquet_tv_string += "#NAME " + str(playlist_info["name"]) + "\n" filename = "" @@ -822,7 +831,7 @@ def loadSeries(self): exists = any(item for item in self.series_stream_data if item.get("category_id") == category_id) - if str(category_id) not in glob.current_playlist["data"]["series_categories_hidden"] and exists: + if str(category_id) not in data["series_categories_hidden"] and exists: if cfg.groups.value: filename = "/etc/enigma2/userbouquet.bouquetmakerxtream_" + str(self.safe_name) + ".tv" bouquet = "subbouquet" @@ -845,13 +854,13 @@ def loadSeries(self): exists = any(item for item in self.series_stream_data if item.get("category_id") == category_id) - if str(category_id) not in glob.current_playlist["data"]["series_categories_hidden"] and exists: + if str(category_id) not in data["series_categories_hidden"] and exists: bouquet_title = self.safe_name + "_" + bmx.safeName(category["category_name"]) self.total_count += 1 output_string = "" string_list = [] - if glob.current_playlist["settings"]["prefix_name"] and cfg.groups.value is False: + if settings["prefix_name"] and not cfg.groups.value: output_string += "#NAME " + self.safe_name + " Series - " + category["category_name"] + "\n" else: output_string += "#NAME " + "Series - " + category["category_name"] + "\n" @@ -860,12 +869,6 @@ def loadSeries(self): if str(category_id) == str(stream["category_id"]): string_list.append([str(stream["bouquet_string"]), str(stream["name"]), str(stream["added"])]) - if glob.current_playlist["settings"]["vod_stream_order"] == "alphabetical": - string_list.sort(key=lambda x: x[1].lower()) - - if glob.current_playlist["settings"]["vod_stream_order"] == "added": - string_list.sort(key=lambda x: x[2].lower(), reverse=True) - for string in string_list: output_string += string[0] @@ -881,8 +884,8 @@ def loadSeries(self): self.progress_value += 1 self["progress"].setValue(self.progress_value) - glob.current_playlist["data"]["series_categories"] = [] - glob.current_playlist["data"]["series_streams"] = [] + data["series_categories"] = [] + data["series_streams"] = [] self.finished() @@ -911,7 +914,7 @@ def buildBouquetTvGroupedFile(self): exists = True break - if exists is False: + if not exists: with open("/etc/enigma2/bouquets.tv", "a+") as f: bouquet_tv_string = '#SERVICE 1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "' + str(groupname) + '" ORDER BY bouquet\n' f.write(str(bouquet_tv_string)) diff --git a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/version.txt b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/version.txt index 92a52b1..1aee084 100644 --- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/version.txt +++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/version.txt @@ -1 +1 @@ -1.42-20250110 \ No newline at end of file +1.44-20250125 \ No newline at end of file diff --git a/CONTROL/control b/CONTROL/control index d9f498f..4136c61 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,5 +1,5 @@ Package: enigma2-plugin-extensions-bouquetmakerxtream -Version: 1.42-20250110 +Version: 1.44-20250125 Section: misc Priority: optional Architecture: all