* Kodi: handle connection errors in fetch data

* feat: Update scraper URLs and fix streamed.su live sport event

* use only url for cache validation in live stream validation

* Handle debrid service downtime error & tracker fetch error

* handle review
This commit is contained in:
Mohamed Zumair
2024-08-29 10:05:39 +05:30
committed by GitHub
parent e502d0f10e
commit bd43ee4c3f
7 changed files with 40 additions and 22 deletions
+1 -1
View File
@@ -1 +1 @@
pydevd-pycharm~=241.18034.82
pydevd-pycharm
+15 -1
View File
@@ -64,6 +64,16 @@ def fetch_data(url, force_refresh=False):
if "no-store" in cache_control or "no-cache" in cache_control:
remove_cache(response.url)
return response.json()
except requests.ConnectionError as e:
xbmc.log(f"Connection failed: {e}", xbmc.LOGERROR)
xbmcgui.Dialog().notification(
"MediaFusion", "Connection failed", xbmcgui.NOTIFICATION_ERROR
)
except requests.Timeout as e:
xbmc.log(f"Request timed out: {e}", xbmc.LOGERROR)
xbmcgui.Dialog().notification(
"MediaFusion", "Request timed out", xbmcgui.NOTIFICATION_ERROR
)
except requests.RequestException as e:
if e.response is None:
xbmc.log(f"Request failed: {e}", xbmc.LOGERROR)
@@ -87,7 +97,11 @@ def fetch_data(url, force_refresh=False):
xbmcgui.Dialog().notification(
"MediaFusion", "Request failed", xbmcgui.NOTIFICATION_ERROR
)
return None
except Exception as e:
xbmc.log(f"Failed to fetch data: {e}", xbmc.LOGERROR)
xbmcgui.Dialog().notification(
"MediaFusion", "Failed to fetch data", xbmcgui.NOTIFICATION_ERROR
)
def build_url(action, **params):
+4 -2
View File
@@ -61,7 +61,7 @@ class DaddyLiveHDSpider(scrapy.Spider):
}
m3u8_base_url = "https://webhdrunns.mizhls.ru/lb/premium{}/index.m3u8"
referer = "https://qqwebplay.xyz/"
referer = "https://cookiewebplay.xyz/"
def __init__(self, *args, **kwargs):
super(DaddyLiveHDSpider, self).__init__(*args, **kwargs)
@@ -97,7 +97,9 @@ class DaddyLiveHDSpider(scrapy.Spider):
# Convert to UNIX timestamp
event_start_timestamp = int(aware_datetime.timestamp())
if event_start_timestamp != 0:
event_start_time = datetime.fromtimestamp(event_start_timestamp).strftime("%I:%M%p GMT")
event_start_time = datetime.fromtimestamp(
event_start_timestamp
).strftime("%I:%M%p GMT")
description = f'{event["event"]} - {event_start_time}'
else:
description = event["event"]
+12 -16
View File
@@ -28,9 +28,6 @@ class StreamedSpider(scrapy.Spider):
}
m3u8_base_url = "https://rr.vipstreams.in/alpha/js"
sub_domains = {
"rr.": "Main Server",
}
mediafusion_referer = "https://mediafusion.addon/"
custom_settings = {
@@ -112,16 +109,15 @@ class StreamedSpider(scrapy.Spider):
stream_quality = link.xpath(".//h2/text()").get().strip()
language = link.xpath(".//div[last()]/text()").get().strip()
for sub_domain, sub_domain_name in self.sub_domains.items():
m3u8_url = f"{self.m3u8_base_url}{stream_url.replace('/watch', '').replace('/alpha', '')}/playlist.m3u8"
item = response.meta["item"].copy()
item.update(
{
"stream_name": f"{stream_name} - 📡 {sub_domain_name}\n📺 {stream_quality} - 🌐 {language}",
"stream_url": m3u8_url,
"referer": self.mediafusion_referer,
"description": description,
"event_start_timestamp": event_start_timestamp,
}
)
yield item
m3u8_url = f"{self.m3u8_base_url}{stream_url.replace('/watch', '').replace('/alpha', '')}/playlist.m3u8"
item = response.meta["item"].copy()
item.update(
{
"stream_name": f"{stream_name}\n📺 {stream_quality} - 🌐 {language}",
"stream_url": m3u8_url,
"referer": self.mediafusion_referer,
"description": description,
"event_start_timestamp": event_start_timestamp,
}
)
yield item
+5
View File
@@ -55,6 +55,11 @@ class DebridClient:
try:
response.raise_for_status()
except RequestException as error:
if error.response.status_code in [502, 503, 504]:
raise ProviderException(
"Debrid service is down.", "debrid_service_down_error.mp4"
) from error
if is_expected_to_fail:
return
self._handle_service_specific_errors(error)
+1 -1
View File
@@ -175,7 +175,7 @@ async def init_best_trackers():
)
else:
logging.error(f"Failed to load trackers: {response.status_code}")
except httpx.ConnectTimeout as e:
except (httpx.ConnectTimeout, Exception) as e:
logging.error(f"Failed to load trackers: {e}")
+2 -1
View File
@@ -1,6 +1,7 @@
import asyncio
import json
import logging
from urllib import parse
from urllib.parse import urlparse
import aiohttp
@@ -58,7 +59,7 @@ async def validate_m3u8_url(
async def validate_m3u8_url_with_cache(redis: Redis, url: str, behaviour_hint: dict):
cache_key = f"m3u8_url:{url}"
cache_key = f"m3u8_url:{parse.urlparse(url).netloc}"
cache_data = await redis.get(cache_key)
if cache_data:
return json.loads(cache_data)