From 545bdbf9434b67eef2c5ad0a8a8e1ef72904498e Mon Sep 17 00:00:00 2001
From: kiddac <kiddac2015@gmail.com>
Date: Mon, 28 Oct 2024 21:47:52 +0000
Subject: [PATCH] 1.33-20241028 - reverted some with statements on downloads
 that were causing issues on dreamboxes

---
 .../Extensions/BouquetMakerXtream/catchup.py  | 27 +++---
 .../BouquetMakerXtream/downloadpicons.py      | 72 +++++++-------
 .../BouquetMakerXtream/globalfunctions.py     | 96 +++++++++----------
 .../BouquetMakerXtream/playlists.py           | 32 +++----
 .../Extensions/BouquetMakerXtream/plugin.py   | 14 +--
 .../Extensions/BouquetMakerXtream/server.py   | 24 ++---
 .../Extensions/BouquetMakerXtream/version.txt |  2 +-
 CONTROL/control                               |  2 +-
 8 files changed, 136 insertions(+), 133 deletions(-)

diff --git a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/catchup.py b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/catchup.py
index 492a568..feb042f 100644
--- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/catchup.py
+++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/catchup.py
@@ -206,14 +206,14 @@ def downloadPlayerApi(self):
             http.mount("https://", adapter)
 
             try:
-                with http.get(self.player_api, headers=hdr, timeout=10, verify=False) as r:  # Use a context manager for the response
-                    r.raise_for_status()
+                r = http.get(self.player_api, headers=hdr, timeout=10, verify=False)
+                r.raise_for_status()
 
-                    if r.status_code == requests.codes.ok:
-                        try:
-                            response = r.json()
-                        except Exception as e:
-                            print(e)
+                if r.status_code == requests.codes.ok:
+                    try:
+                        response = r.json()
+                    except Exception as e:
+                        print(e)
 
             except Exception as e:
                 print(e)
@@ -252,11 +252,11 @@ def downloadSimpleData(self):
             http.mount("https://", adapter)
 
             try:
-                with http.get(self.simple_url, headers=hdr, timeout=(10, 20), verify=False) as response:
-                    response.raise_for_status()
+                response = http.get(self.simple_url, headers=hdr, timeout=(10, 20), verify=False)
+                response.raise_for_status()
 
-                    if response.status_code == requests.codes.ok:
-                        short_epg_json = response.json()
+                if response.status_code == requests.codes.ok:
+                    short_epg_json = response.json()
 
             except Exception as e:
                 print(e)
@@ -287,6 +287,7 @@ def downloadSimpleData(self):
                         start_datetime_original = self.parse_datetime(start)
                         if start_datetime_original:
                             start_datetime = start_datetime_original + timedelta(hours=shift)
+                            start_datetime_original_margin = start_datetime_original - timedelta(minutes=catchupstart)
                         else:
                             print("Error parsing start datetime")
                             continue
@@ -319,7 +320,9 @@ def downloadSimpleData(self):
 
                         epg_duration = int((end_datetime_margin - start_datetime_margin).total_seconds() / 60.0)
 
-                        url_datestring = start_datetime_margin.strftime("%Y-%m-%d:%H-%M")
+                        url_datestring = start_datetime_original_margin.strftime("%Y-%m-%d:%H-%M")
+
+                        # url_datestring = start_datetime_margin.strftime("%Y-%m-%d:%H-%M")
 
                         self.epg_short_list.append(buildCatchupEpgListEntry(str(epg_date_all), str(epg_time_all), str(title), str(description), str(url_datestring), str(epg_duration), index, self.ref_stream_num))
 
diff --git a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/downloadpicons.py b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/downloadpicons.py
index 42eb979..ac1e10d 100644
--- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/downloadpicons.py
+++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/downloadpicons.py
@@ -259,48 +259,48 @@ def fetch_url(self, url, i):
             http.mount("https://", adapter)
 
             try:
-                with http.get(url[i][1], headers=hdr, stream=True, timeout=5, verify=False, allow_redirects=False) as response:
-                    if response:
-                        if "content-length" in response.headers and int(cfg.picon_max_size.value) != 0:
-                            if int(response.headers["content-length"]) > int(cfg.picon_max_size.value):
-                                print("*** Picon source too large ***", url[i])
-                                self.sizecount += 1
-                                self.sizelist.append(url[i])
-                                if url[i][1] not in self.sizeblockinglist:
-                                    self.sizeblockinglist.append(url[i][1])
-                                return
-
-                        if "content-type" in response.headers and response.headers["content-type"] in image_formats:
-                            try:
-                                content = response.content
-                                image_file = io.BytesIO(content)
-                                self.makePicon(image_file, url[i][0], url[i][1])
-                                self.successcount += 1
-                                self.successlist.append(url[i])
-                                return
-
-                            except Exception as e:
-                                print("**** image builder failed***", e, url[i][1])
-                                self.typecount += 1
-                                self.typelist.append(url[i])
-                                if url[i][1] not in self.typeblockinglist:
-                                    self.typeblockinglist.append(url[i][1])
-                                return
-
-                        else:
-                            print("*** not png or jpeg ***", url[i][1])
+                response = http.get(url[i][1], headers=hdr, stream=True, timeout=5, verify=False, allow_redirects=False)
+                if response:
+                    if "content-length" in response.headers and int(cfg.picon_max_size.value) != 0:
+                        if int(response.headers["content-length"]) > int(cfg.picon_max_size.value):
+                            print("*** Picon source too large ***", url[i])
+                            self.sizecount += 1
+                            self.sizelist.append(url[i])
+                            if url[i][1] not in self.sizeblockinglist:
+                                self.sizeblockinglist.append(url[i][1])
+                            return
+
+                    if "content-type" in response.headers and response.headers["content-type"] in image_formats:
+                        try:
+                            content = response.content
+                            image_file = io.BytesIO(content)
+                            self.makePicon(image_file, url[i][0], url[i][1])
+                            self.successcount += 1
+                            self.successlist.append(url[i])
+                            return
+
+                        except Exception as e:
+                            print("**** image builder failed***", e, url[i][1])
                             self.typecount += 1
                             self.typelist.append(url[i])
                             if url[i][1] not in self.typeblockinglist:
                                 self.typeblockinglist.append(url[i][1])
                             return
+
                     else:
-                        print("**** bad response***", url[i][1])
-                        self.badurlcount += 1
-                        self.badurllist.append(url[i])
-                        if url[i][1] not in self.blockinglist:
-                            self.blockinglist.append(url[i][1])
-                            return
+                        print("*** not png or jpeg ***", url[i][1])
+                        self.typecount += 1
+                        self.typelist.append(url[i])
+                        if url[i][1] not in self.typeblockinglist:
+                            self.typeblockinglist.append(url[i][1])
+                        return
+                else:
+                    print("**** bad response***", url[i][1])
+                    self.badurlcount += 1
+                    self.badurllist.append(url[i])
+                    if url[i][1] not in self.blockinglist:
+                        self.blockinglist.append(url[i][1])
+                        return
 
             except Exception as e:
                 print("**** exception ***", url[i][1], e)
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 1308b2e..2e6838e 100644
--- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/globalfunctions.py
+++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/globalfunctions.py
@@ -43,19 +43,19 @@ def downloadUrl(url, ext):
         http.mount("https://", adapter)
 
         try:
-            with http.get(url, headers=hdr, timeout=(20, 60), verify=False) as r:
-                r.raise_for_status()
-
-                if r.status_code == requests.codes.ok:
-                    try:
-                        if ext == "json":
-                            response = r.json()
-                        else:
-                            response = r.content
-                        return response
-                    except Exception as e:
-                        print("Error processing response:", e)
-                        return ""
+            r = http.get(url, headers=hdr, timeout=(20, 60), verify=False)
+            r.raise_for_status()
+
+            if r.status_code == requests.codes.ok:
+                try:
+                    if ext == "json":
+                        response = r.json()
+                    else:
+                        response = r.content
+                    return response
+                except Exception as e:
+                    print("Error processing response:", e)
+                    return ""
         except Exception as e:
             print("Request failed:", e)
 
@@ -71,16 +71,16 @@ def downloadApi(url):
         http.mount("https://", adapter)
 
         try:
-            with http.get(url, headers=hdr, timeout=5, verify=False) as r:
-                r.raise_for_status()
+            r = http.get(url, headers=hdr, timeout=5, verify=False)
+            r.raise_for_status()
 
-                if r.status_code == requests.codes.ok:
-                    try:
-                        response = r.json()
-                        return response
-                    except Exception as e:
-                        print("Error processing JSON response:", e)
-                        return ""
+            if r.status_code == requests.codes.ok:
+                try:
+                    response = r.json()
+                    return response
+                except Exception as e:
+                    print("Error processing JSON response:", e)
+                    return ""
         except Exception as e:
             print("Request failed:", e)
 
@@ -98,15 +98,15 @@ def downloadUrlCategory(url):
         http.mount("https://", adapter)
 
         try:
-            with http.get(url[0], headers=hdr, timeout=20, verify=False) as r:
-                r.raise_for_status()
+            r = http.get(url[0], headers=hdr, timeout=20, verify=False)
+            r.raise_for_status()
 
-                if r.status_code == requests.codes.ok:
-                    if ext == "json":
-                        response = (category, r.json())
-                    else:
-                        response = (category, r.text)
-                    return response
+            if r.status_code == requests.codes.ok:
+                if ext == "json":
+                    response = (category, r.json())
+                else:
+                    response = (category, r.text)
+                return response
 
         except Exception as e:
             print("Request failed:", e)
@@ -126,24 +126,24 @@ def downloadUrlMulti(url, output_file=None):
         http.mount("https://", adapter)
 
         try:
-            with http.get(url[0], headers=hdr, timeout=(20, 300), verify=False, stream=True) as r:
-                r.raise_for_status()
-
-                if r.status_code == requests.codes.ok:
-                    if ext == "json":
-                        json_content = r.json()
-                        return category, json_content
-                    else:
-                        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)
-
-                        return category, output_file
+            r = http.get(url[0], headers=hdr, timeout=(20, 300), verify=False, stream=True)
+            r.raise_for_status()
+
+            if r.status_code == requests.codes.ok:
+                if ext == "json":
+                    json_content = r.json()
+                    return category, json_content
+                else:
+                    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)
+
+                    return category, output_file
 
         except requests.Timeout as e:
             print("Error message: {}".format(str(e)))
diff --git a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/playlists.py b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/playlists.py
index c7b72db..d4d7557 100644
--- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/playlists.py
+++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/playlists.py
@@ -167,22 +167,22 @@ def download_url(self, url):
 
             try:
                 # Perform the initial request
-                with http.get(url[0], headers=hdr, timeout=6, verify=False) as r:
-                    r.raise_for_status()
-
-                    if r.status_code == requests.codes.ok:
-                        if "player_api.php" in url[0]:
-                            try:
-                                response = r.json()
-                            except Exception as e:
-                                print("JSON parsing error:", e)
-                        else:
-                            try:
-                                response = r.text
-                                if "EXTM3U" not in response:
-                                    response = None
-                            except Exception as e:
-                                print("Text response error:", e)
+                r = http.get(url[0], headers=hdr, timeout=6, verify=False)
+                r.raise_for_status()
+
+                if r.status_code == requests.codes.ok:
+                    if "player_api.php" in url[0]:
+                        try:
+                            response = r.json()
+                        except Exception as e:
+                            print("JSON parsing error:", e)
+                    else:
+                        try:
+                            response = r.text
+                            if "EXTM3U" not in response:
+                                response = None
+                        except Exception as e:
+                            print("Text response error:", e)
 
             except Exception as e:
                 print("Request error:", e)
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 3f707db..c8314cc 100644
--- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/plugin.py
+++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/plugin.py
@@ -419,13 +419,13 @@ def showBmxCatchup(self):
 
         try:
             # Use context manager for the response
-            with http.get(get_live_streams, headers=hdr, timeout=10, verify=False) as r:
-                r.raise_for_status()
-                if r.status_code == requests.codes.ok:
-                    try:
-                        response = r.json()
-                    except Exception as ex:
-                        print("JSON parsing error:", ex)
+            r = http.get(get_live_streams, headers=hdr, timeout=10, verify=False)
+            r.raise_for_status()
+            if r.status_code == requests.codes.ok:
+                try:
+                    response = r.json()
+                except Exception as ex:
+                    print("JSON parsing error:", ex)
 
         except Exception as exc:
             print("Request error:", exc)
diff --git a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/server.py b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/server.py
index 5262365..4d7d7ec 100644
--- a/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/server.py
+++ b/BouquetMakerXtream/usr/lib/enigma2/python/Plugins/Extensions/BouquetMakerXtream/server.py
@@ -271,18 +271,18 @@ def checkline(self):
             http.mount("https://", adapter)
 
             try:
-                with http.get(self.apiline, headers=hdr, timeout=15, verify=False, stream=True) as response:
-                    response.raise_for_status()
-                    if response.status_code == requests.codes.ok:
-                        try:
-                            if self.playlist_type_cfg.value == "standard":
-                                json_response = response.json()
-                                if "user_info" in json_response and "auth" in json_response["user_info"]:
-                                    valid = json_response["user_info"]["auth"] == 1
-                            else:
-                                valid = True
-                        except Exception as e:
-                            print("JSON parsing error:", e)
+                response = http.get(self.apiline, headers=hdr, timeout=15, verify=False, stream=True)
+                response.raise_for_status()
+                if response.status_code == requests.codes.ok:
+                    try:
+                        if self.playlist_type_cfg.value == "standard":
+                            json_response = response.json()
+                            if "user_info" in json_response and "auth" in json_response["user_info"]:
+                                valid = json_response["user_info"]["auth"] == 1
+                        else:
+                            valid = True
+                    except Exception as e:
+                        print("JSON parsing error:", e)
 
             except Exception as e:
                 print("Error connecting:", e)
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 c63ae85..22f2714 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.32-20241027
\ No newline at end of file
+1.33-20241028
\ No newline at end of file
diff --git a/CONTROL/control b/CONTROL/control
index 33f7407..ffdb3ab 100644
--- a/CONTROL/control
+++ b/CONTROL/control
@@ -1,5 +1,5 @@
 Package: enigma2-plugin-extensions-bouquetmakerxtream
-Version: 1.32-20241027
+Version: 1.33-20241028
 Section: misc
 Priority: optional
 Architecture: all