e
This commit is contained in:
parent
cb9d5637fc
commit
00000d905f
7 changed files with 224 additions and 93 deletions
|
|
@ -1,11 +1,14 @@
|
|||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
import pytz
|
||||
from playwright.async_api import Request
|
||||
|
||||
TZ = pytz.timezone("America/New_York")
|
||||
|
||||
|
|
@ -65,6 +68,24 @@ def get_logger(name: str | None = None) -> logging.Logger:
|
|||
return logger
|
||||
|
||||
|
||||
def load_ts_cache(
|
||||
file: Path,
|
||||
cache_exp: int | float,
|
||||
) -> dict[str, dict[str, str | float]]:
|
||||
try:
|
||||
data: dict[str, dict[str, str | float]] = json.loads(
|
||||
file.read_text(encoding="utf-8")
|
||||
)
|
||||
|
||||
return {
|
||||
k: v
|
||||
for k, v in data.items()
|
||||
if now.timestamp() - v.get("timestamp", 0) < cache_exp
|
||||
}
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
return {}
|
||||
|
||||
|
||||
async def safe_process_event(
|
||||
fn,
|
||||
url_num: int,
|
||||
|
|
@ -107,3 +128,15 @@ async def get_base(client: httpx.AsyncClient, mirrors: list[str]) -> str:
|
|||
results = await asyncio.gather(*tasks)
|
||||
|
||||
return [url for url, ok in zip(mirrors, results) if ok][0]
|
||||
|
||||
|
||||
def capture_req(
|
||||
req: Request,
|
||||
captured: list[str],
|
||||
got_one: asyncio.Event,
|
||||
) -> None:
|
||||
valid_m3u8 = re.compile(r"^(?!.*(amazonaws|knitcdn)).*\.m3u8")
|
||||
|
||||
if valid_m3u8.search(req.url):
|
||||
captured.append(req.url)
|
||||
got_one.set()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue