This commit is contained in:
doms9 2025-11-19 18:58:52 -05:00
parent 7b761c7189
commit 00000d9fe2
6 changed files with 222 additions and 56 deletions

View file

@ -13,7 +13,7 @@ CACHE_FILE = Cache("tvpass.json", exp=86_400)
BASE_URL = "https://tvpass.org/playlist/m3u"
async def fetch_m3u8(client: httpx.AsyncClient) -> list[str]:
async def get_data(client: httpx.AsyncClient) -> list[str]:
try:
r = await client.get(BASE_URL)
r.raise_for_status()
@ -25,19 +25,12 @@ async def fetch_m3u8(client: httpx.AsyncClient) -> list[str]:
return r.text.splitlines()
async def scrape(client: httpx.AsyncClient) -> None:
if cached := CACHE_FILE.load():
urls.update(cached)
log.info(f"Loaded {len(urls)} event(s) from cache")
return
log.info(f'Scraping from "{BASE_URL}"')
async def get_events(client: httpx.AsyncClient) -> dict[str, dict[str, str | float]]:
now = Time.now().timestamp()
if not (data := await fetch_m3u8(client)):
log.warning("No M3U8 data received")
return
events = {}
data = await get_data(client)
for i, line in enumerate(data):
if line.startswith("#EXTINF"):
@ -59,7 +52,7 @@ async def scrape(client: httpx.AsyncClient) -> None:
tvg_id, logo = leagues.info(sport)
entry = {
events[key] = {
"url": f"http://origin.thetvapp.to/hls/{channel}/mono.m3u8",
"logo": logo,
"id": tvg_id or "Live.Event.us",
@ -67,8 +60,21 @@ async def scrape(client: httpx.AsyncClient) -> None:
"timestamp": now,
}
urls[key] = entry
return events
async def scrape(client: httpx.AsyncClient) -> None:
if cached := CACHE_FILE.load():
urls.update(cached)
log.info(f"Loaded {len(urls)} event(s) from cache")
return
log.info(f'Scraping from "{BASE_URL}"')
events = await get_events(client)
urls.update(events)
CACHE_FILE.write(urls)
log.info(f"Cached {len(urls)} event(s)")
log.info(f"Collected and cached {len(urls)} new event(s)")