diff --git a/M3U8/fetch.py b/M3U8/fetch.py index 8594fa1..b0e4085 100644 --- a/M3U8/fetch.py +++ b/M3U8/fetch.py @@ -60,7 +60,7 @@ async def main() -> None: asyncio.create_task(streamsgate.scrape(network.client)), asyncio.create_task(strmd.scrape(network.client)), asyncio.create_task(tvpass.scrape(network.client)), - #asyncio.create_task(watchfooty.scrape(network.client)), + # asyncio.create_task(watchfooty.scrape(network.client)), asyncio.create_task(webcast.scrape(network.client)), ] diff --git a/M3U8/scrapers/lotus.py b/M3U8/scrapers/lotus.py index 4908501..84e9087 100644 --- a/M3U8/scrapers/lotus.py +++ b/M3U8/scrapers/lotus.py @@ -25,7 +25,7 @@ def fix_league(s: str) -> str: async def refresh_api_cache( client: httpx.AsyncClient, url: str, - ts: float, + now_ts: float, ) -> dict[str, dict[str, str]]: log.info("Refreshing API cache") @@ -37,9 +37,10 @@ async def refresh_api_cache( return {} - data = r.json() + if not (data := r.json()): + return {} - data["timestamp"] = ts + data["timestamp"] = now_ts return data diff --git a/M3U8/scrapers/ppv.py b/M3U8/scrapers/ppv.py index 477d13f..243947d 100644 --- a/M3U8/scrapers/ppv.py +++ b/M3U8/scrapers/ppv.py @@ -115,6 +115,8 @@ async def scrape(client: httpx.AsyncClient) -> None: CACHE_FILE.write(cached_urls) return + log.info(f'Scraping from "{base_url}"') + events = await get_events( client, api_url, diff --git a/M3U8/scrapers/streamcenter.py b/M3U8/scrapers/streamcenter.py index 3d6b995..cd83b05 100644 --- a/M3U8/scrapers/streamcenter.py +++ b/M3U8/scrapers/streamcenter.py @@ -45,9 +45,10 @@ async def refresh_api_cache( except Exception as e: log.error(f'Failed to fetch "{url}": {e}') - return {} + return [] - data = r.json() + if not (data := r.json()): + return [] data[-1]["timestamp"] = now_ts diff --git a/M3U8/scrapers/streamsgate.py b/M3U8/scrapers/streamsgate.py index 6abd74c..92a14dc 100644 --- a/M3U8/scrapers/streamsgate.py +++ b/M3U8/scrapers/streamsgate.py @@ -59,7 +59,8 @@ async def get_api_data(client: httpx.AsyncClient, url: str) -> list[dict[str, An async def refresh_api_cache( - client: httpx.AsyncClient, ts: float + client: httpx.AsyncClient, + now_ts: float, ) -> list[dict[str, Any]]: log.info("Refreshing API cache") @@ -70,12 +71,13 @@ async def refresh_api_cache( results = await asyncio.gather(*tasks) - data = list(chain(*results)) + if not (data := list(chain(*results))): + return [] for ev in data: ev["ts"] = ev.pop("timestamp") - data[-1]["timestamp"] = ts + data[-1]["timestamp"] = now_ts return data diff --git a/M3U8/scrapers/strmd.py b/M3U8/scrapers/strmd.py index 7712479..282bb3b 100644 --- a/M3U8/scrapers/strmd.py +++ b/M3U8/scrapers/strmd.py @@ -38,7 +38,7 @@ def fix_sport(s: str) -> str: async def refresh_api_cache( client: httpx.AsyncClient, url: str, - ts: float, + now_ts: float, ) -> list[dict[str, Any]]: log.info("Refreshing API cache") @@ -49,11 +49,12 @@ async def refresh_api_cache( except Exception as e: log.error(f'Failed to fetch "{url}": {e}') - return {} + return [] - data = r.json() + if not (data := r.json()): + return [] - data[-1]["timestamp"] = ts + data[-1]["timestamp"] = now_ts return data diff --git a/M3U8/scrapers/utils/webwork.py b/M3U8/scrapers/utils/webwork.py index 063faa9..1a801c0 100644 --- a/M3U8/scrapers/utils/webwork.py +++ b/M3U8/scrapers/utils/webwork.py @@ -53,7 +53,7 @@ class Network: async def check_status(self, url: str) -> bool: try: - r = await self.client.get(url) + r = await self.client.get(url, timeout=5) r.raise_for_status() return r.status_code == 200 except (httpx.HTTPError, httpx.TimeoutException) as e: diff --git a/M3U8/scrapers/watchfooty.py b/M3U8/scrapers/watchfooty.py index 563f7c0..ebb024d 100644 --- a/M3U8/scrapers/watchfooty.py +++ b/M3U8/scrapers/watchfooty.py @@ -67,12 +67,13 @@ async def refresh_api_cache( results = await asyncio.gather(*tasks) - data = list(chain(*results)) + if not (data := list(chain(*results))): + return [] for ev in data: ev["ts"] = ev.pop("timestamp") - data[-1]["timestamp"] = Time.now().timestamp() + data[-1]["timestamp"] = Time.now().timestamp() return data