From 00000d91c7b68e71fae184c87753d7578911f25c Mon Sep 17 00:00:00 2001 From: doms9 <96013514+doms9@users.noreply.github.com> Date: Fri, 19 Dec 2025 13:25:40 -0500 Subject: [PATCH] e fix watchfooty scraping --- M3U8/scrapers/istreameast.py | 16 ++++++++-------- M3U8/scrapers/watchfooty.py | 25 ++++++++++++++++++++----- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/M3U8/scrapers/istreameast.py b/M3U8/scrapers/istreameast.py index be8410d..b6da253 100644 --- a/M3U8/scrapers/istreameast.py +++ b/M3U8/scrapers/istreameast.py @@ -67,6 +67,14 @@ async def get_events(cached_keys: list[str]) -> list[dict[str, str]]: if not (rank_elem := li_item.css_first(".f1-podium--rank")): continue + if not (time_elem := li_item.css_first(".SaatZamanBilgisi")): + continue + + time_text = time_elem.text(strip=True) + + if not pattern.search(time_text): + continue + sport = rank_elem.text(strip=True) if not (driver_elem := li_item.css_first(".f1-podium--driver")): @@ -83,14 +91,6 @@ async def get_events(cached_keys: list[str]) -> list[dict[str, str]]: if not (href := link.attributes.get("href")): continue - if not (time_elem := li_item.css_first(".SaatZamanBilgisi")): - continue - - time_text = time_elem.text(strip=True) - - if not pattern.search(time_text): - continue - events.append( { "sport": sport, diff --git a/M3U8/scrapers/watchfooty.py b/M3U8/scrapers/watchfooty.py index 430fcd1..0df5942 100644 --- a/M3U8/scrapers/watchfooty.py +++ b/M3U8/scrapers/watchfooty.py @@ -17,7 +17,7 @@ TAG = "WATCHFTY" CACHE_FILE = Cache(f"{TAG.lower()}.json", exp=10_800) -API_FILE = Cache(f"{TAG.lower()}-api.json", exp=28_800) +API_FILE = Cache(f"{TAG.lower()}-api.json", exp=19_800) API_URL = "https://api.watchfooty.st" @@ -118,11 +118,26 @@ async def process_event( return - first_available = await page.wait_for_selector( - 'a[href*="/stream/"]', timeout=3_000 - ) + try: + first_available = await page.wait_for_selector( + 'a[href*="/stream/"]', + timeout=3_000, + ) + except TimeoutError: + log.warning(f"URL {url_num}) No available stream links.") - await first_available.click() + return + + if not (href := await first_available.get_attribute("href")): + log.warning(f"URL {url_num}) No available stream links.") + + return + + await page.goto( + href, + wait_until="domcontentloaded", + timeout=5_000, + ) wait_task = asyncio.create_task(got_one.wait())