e
This commit is contained in:
parent
00000d9d54
commit
00000d932b
6 changed files with 34 additions and 3639 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -35,11 +35,21 @@ CACHE_FILE = Path(__file__).parent / "livetvsx.json"
|
|||
|
||||
|
||||
async def safe_process_event(fn, url_num: int, timeout=20) -> Any | None:
|
||||
task = asyncio.create_task(fn())
|
||||
|
||||
try:
|
||||
return await asyncio.wait_for(fn(), timeout=timeout)
|
||||
return await asyncio.wait_for(task, timeout=timeout)
|
||||
except asyncio.TimeoutError:
|
||||
log.warning(f"URL {url_num}) Timed out after {timeout}s, skipping event")
|
||||
return
|
||||
|
||||
task.cancel()
|
||||
|
||||
try:
|
||||
await task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
except Exception as e:
|
||||
log.debug(f"URL {url_num}) Ignore exception after timeout: {e}")
|
||||
|
||||
|
||||
async def write_to_cert(client: httpx.AsyncClient, url: str, cert: Path) -> None:
|
||||
|
|
@ -79,7 +89,7 @@ def load_cache() -> dict[str, dict[str, str | str]]:
|
|||
try:
|
||||
data = json.loads(CACHE_FILE.read_text(encoding="utf-8"))
|
||||
|
||||
now = datetime.now().timestamp()
|
||||
now = datetime.now(TZ).timestamp()
|
||||
|
||||
return {
|
||||
k: v
|
||||
|
|
@ -169,7 +179,7 @@ async def parse_feed(
|
|||
return events
|
||||
|
||||
|
||||
async def process_event(url: str, url_num: int, max_wait_ms=15_000) -> str | None:
|
||||
async def process_event(url: str, url_num: int) -> str | None:
|
||||
async with async_playwright() as p:
|
||||
browser = await p.firefox.launch(headless=True)
|
||||
|
||||
|
|
@ -199,7 +209,7 @@ async def process_event(url: str, url_num: int, max_wait_ms=15_000) -> str | Non
|
|||
await ev_page.goto(
|
||||
url,
|
||||
wait_until="domcontentloaded",
|
||||
timeout=30_000,
|
||||
timeout=10_000,
|
||||
)
|
||||
|
||||
btn = await ev_page.query_selector(".lnkhdr > tbody > tr > td:nth-child(2)")
|
||||
|
|
@ -248,7 +258,7 @@ async def process_event(url: str, url_num: int, max_wait_ms=15_000) -> str | Non
|
|||
wait_task = asyncio.create_task(got_one.wait())
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(wait_task, timeout=max_wait_ms / 1000)
|
||||
await asyncio.wait_for(wait_task, timeout=1.5e1)
|
||||
|
||||
except asyncio.TimeoutError:
|
||||
log.warning(f"URL {url_num}) Timed out waiting for m3u8.")
|
||||
|
|
@ -308,7 +318,7 @@ async def main(client: httpx.AsyncClient) -> None:
|
|||
|
||||
log.info(f"Processing {len(events)} URLs")
|
||||
|
||||
now_ts = datetime.now().timestamp()
|
||||
now_ts = datetime.now(TZ).timestamp()
|
||||
|
||||
for num, ev in enumerate(events, start=1):
|
||||
sport = ev["sport"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue