iptv/M3U8/scrapers/xyzstream.py

83 lines
1.9 KiB
Python
Raw Normal View History

2026-05-25 22:25:24 -04:00
from .utils import Cache, Time, get_logger, leagues, network
log = get_logger(__name__)
urls: dict[str, dict[str, str | float]] = {}
TAG = "XYZSTRM"
CACHE_FILE = Cache(TAG, exp=28_800)
2026-05-30 16:30:54 -04:00
BASE_URL = "https://xyzstreams.shop"
2026-05-25 22:25:24 -04:00
API_URL = "https://blog.xyzstreams.shop:2053/api/scoreboard"
async def get_events() -> dict[str, dict[str, str | float]]:
events = {}
2026-05-30 16:30:54 -04:00
if not (
r := await network.request(
API_URL,
headers={"Referer": BASE_URL},
log=log,
)
):
2026-05-25 22:25:24 -04:00
return events
now = Time.clean(Time.now())
api_data: list[dict[str, str | dict]] = r.json()
sport = "Live Event"
for event_info in api_data:
away_team: str = event_info.get("away", {}).get("name")
home_team: str = event_info.get("home", {}).get("name")
event_date: str = event_info.get("gameDate")
if not (event_date and away_team and home_team):
continue
event_dt = Time.fromisoformat(event_date)
if event_dt.date() != now.date():
continue
if not (feeds := event_info.get("feeds")):
continue
event_name = f"{away_team} vs {home_team}"
for i, feed in enumerate(feeds.values(), start=1):
key = f"[{sport}] {event_name} {i} ({TAG})"
tvg_id, logo = leagues.get_tvg_info(sport, event_name)
events[key] = {
"url": feed,
"logo": logo,
2026-05-30 16:30:54 -04:00
"base": BASE_URL,
2026-05-25 22:25:24 -04:00
"timestamp": now.timestamp(),
"id": tvg_id or "Live.Event.us",
}
return events
async def scrape() -> None:
if cached := CACHE_FILE.load():
urls.update(cached)
log.info(f"Loaded {len(urls)} event(s) from cache")
return
2026-05-30 16:30:54 -04:00
log.info(f'Scraping from "{BASE_URL}"')
2026-05-25 22:25:24 -04:00
urls.update(await get_events() or {})
log.info(f"Collected and cached {len(urls)} new event(s)")
CACHE_FILE.write(urls)