mirror of
https://github.com/doms9/iptv.git
synced 2026-06-13 12:26:26 +02:00
e
- edit scraping for streambiz.py
This commit is contained in:
parent
feac0cb9e1
commit
00000d9c3d
1 changed files with 22 additions and 4 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import asyncio
|
||||
import re
|
||||
from functools import partial
|
||||
from urllib.parse import urljoin
|
||||
|
||||
|
|
@ -117,6 +118,8 @@ async def process_event(
|
|||
|
||||
|
||||
async def get_events(cached_links: set[str]) -> list[dict[str, str]]:
|
||||
now = Time.clean(Time.now())
|
||||
|
||||
tasks = [network.request(url, log=log) for url in SPORT_URLS.values()]
|
||||
|
||||
results = await asyncio.gather(*tasks)
|
||||
|
|
@ -128,6 +131,11 @@ async def get_events(cached_links: set[str]) -> list[dict[str, str]]:
|
|||
):
|
||||
return events
|
||||
|
||||
start_dt = now.delta(minutes=-30)
|
||||
end_dt = now.delta(minutes=30)
|
||||
|
||||
date_ptrn = re.compile(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}Z", re.I)
|
||||
|
||||
for soup, url in soups:
|
||||
sport = next((k for k, v in SPORT_URLS.items() if v == url), "Live Event")
|
||||
|
||||
|
|
@ -138,13 +146,25 @@ async def get_events(cached_links: set[str]) -> list[dict[str, str]]:
|
|||
elif cached_links & {link := urljoin(BASE_URL, href)}:
|
||||
continue
|
||||
|
||||
if not event.css_first("span.status-badge.badge.bg-success"):
|
||||
if (scr_elem := event.css_first("script")) and (
|
||||
match := date_ptrn.search(scr_elem.text(strip=True))
|
||||
):
|
||||
event_dt = Time.fromisoformat(match[0]).to_tz("EST")
|
||||
|
||||
elif event.css_first("span.status-badge.badge.bg-success"):
|
||||
event_dt = now
|
||||
|
||||
else:
|
||||
continue
|
||||
|
||||
if not start_dt <= event_dt <= end_dt:
|
||||
continue
|
||||
|
||||
events.append(
|
||||
{
|
||||
"sport": sport,
|
||||
"link": link,
|
||||
"timestamp": event_dt.timestamp(),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -169,8 +189,6 @@ async def scrape(browser: Browser) -> None:
|
|||
if events := await get_events(cached_links):
|
||||
log.info(f"Processing {len(events)} URL(s)")
|
||||
|
||||
now = Time.clean(Time.now())
|
||||
|
||||
async with network.event_context(browser, stealth=False) as context:
|
||||
for i, ev in enumerate(events, start=1):
|
||||
async with network.event_page(context) as page:
|
||||
|
|
@ -196,7 +214,7 @@ async def scrape(browser: Browser) -> None:
|
|||
"url": url,
|
||||
"logo": logo,
|
||||
"base": ifr_src,
|
||||
"timestamp": now.timestamp(),
|
||||
"timestamp": ev["timestamp"],
|
||||
"id": tvg_id or "Live.Event.us",
|
||||
"link": link,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue