Skip to content

Commit

Permalink
1.33-20241028 - reverted some with statements on downloads that were …
Browse files Browse the repository at this point in the history
…causing issues on dreamboxes
  • Loading branch information
kiddac committed Oct 28, 2024
1 parent 9d681b7 commit 545bdbf
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.32-20241027
1.33-20241028
2 changes: 1 addition & 1 deletion CONTROL/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: enigma2-plugin-extensions-bouquetmakerxtream
Version: 1.32-20241027
Version: 1.33-20241028
Section: misc
Priority: optional
Architecture: all
Expand Down

0 comments on commit 545bdbf

Please sign in to comment.