mirror of
https://github.com/doms9/iptv.git
synced 2026-03-07 11:18:25 +01:00
e
This commit is contained in:
parent
398761d7ce
commit
00000d958f
2 changed files with 20 additions and 59 deletions
|
|
@ -11,9 +11,7 @@ urls: dict[str, dict[str, str | float]] = {}
|
||||||
|
|
||||||
TAG = "OVOGOAL"
|
TAG = "OVOGOAL"
|
||||||
|
|
||||||
CACHE_FILE = Cache(TAG, exp=10_800)
|
CACHE_FILE = Cache(TAG, exp=19_800)
|
||||||
|
|
||||||
HTML_CACHE = Cache(f"{TAG}-html", exp=19_800)
|
|
||||||
|
|
||||||
BASE_URL = "https://ovogoal.plus"
|
BASE_URL = "https://ovogoal.plus"
|
||||||
|
|
||||||
|
|
@ -48,27 +46,22 @@ async def process_event(url: str, url_num: int) -> tuple[str | None, str | None]
|
||||||
return match[3], iframe_src
|
return match[3], iframe_src
|
||||||
|
|
||||||
|
|
||||||
async def refresh_html_cache() -> dict[str, dict[str, str | float]]:
|
async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
|
||||||
log.info("Refreshing HTML cache")
|
events = []
|
||||||
|
|
||||||
now = Time.clean(Time.now())
|
|
||||||
|
|
||||||
events = {}
|
|
||||||
|
|
||||||
if not (html_data := await network.request(BASE_URL, log=log)):
|
if not (html_data := await network.request(BASE_URL, log=log)):
|
||||||
return events
|
return events
|
||||||
|
|
||||||
soup = HTMLParser(html_data.content)
|
soup = HTMLParser(html_data.content)
|
||||||
|
|
||||||
|
sport = "Live Event"
|
||||||
|
|
||||||
for card in soup.css(".stream-row"):
|
for card in soup.css(".stream-row"):
|
||||||
if (not (watch_btn_elem := card.css_first(".watch-btn"))) or (
|
if (not (watch_btn_elem := card.css_first(".watch-btn"))) or (
|
||||||
not (onclick := watch_btn_elem.attributes.get("onclick"))
|
not (onclick := watch_btn_elem.attributes.get("onclick"))
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not (event_time_elem := card.css_first(".stream-time")):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not (event_name_elem := card.css_first(".stream-info")):
|
if not (event_name_elem := card.css_first(".stream-info")):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -76,50 +69,20 @@ async def refresh_html_cache() -> dict[str, dict[str, str | float]]:
|
||||||
|
|
||||||
event_name = event_name_elem.text(strip=True)
|
event_name = event_name_elem.text(strip=True)
|
||||||
|
|
||||||
event_time = event_time_elem.text(strip=True)
|
if f"[{sport}] {event_name} ({TAG})" in cached_keys:
|
||||||
|
continue
|
||||||
|
|
||||||
event_dt = Time.from_str(f"{now.date()} {event_time}", timezone="CET")
|
events.append(
|
||||||
|
{
|
||||||
sport = "Live Event"
|
"sport": sport,
|
||||||
|
"event": event_name,
|
||||||
key = f"[{sport}] {event_name} ({TAG})"
|
"link": href,
|
||||||
|
}
|
||||||
events[key] = {
|
)
|
||||||
"sport": sport,
|
|
||||||
"event": event_name,
|
|
||||||
"link": href,
|
|
||||||
"event_ts": event_dt.timestamp(),
|
|
||||||
"timestamp": now.timestamp(),
|
|
||||||
}
|
|
||||||
|
|
||||||
return events
|
return events
|
||||||
|
|
||||||
|
|
||||||
async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
|
|
||||||
now = Time.clean(Time.now())
|
|
||||||
|
|
||||||
if not (events := HTML_CACHE.load()):
|
|
||||||
events = await refresh_html_cache()
|
|
||||||
|
|
||||||
HTML_CACHE.write(events)
|
|
||||||
|
|
||||||
live = []
|
|
||||||
|
|
||||||
start_ts = now.delta(minutes=-30).timestamp()
|
|
||||||
end_ts = now.delta(minutes=30).timestamp()
|
|
||||||
|
|
||||||
for k, v in events.items():
|
|
||||||
if k in cached_keys:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not start_ts <= v["event_ts"] <= end_ts:
|
|
||||||
continue
|
|
||||||
|
|
||||||
live.append(v)
|
|
||||||
|
|
||||||
return live
|
|
||||||
|
|
||||||
|
|
||||||
async def scrape() -> None:
|
async def scrape() -> None:
|
||||||
cached_urls = CACHE_FILE.load()
|
cached_urls = CACHE_FILE.load()
|
||||||
|
|
||||||
|
|
@ -138,6 +101,8 @@ async def scrape() -> None:
|
||||||
if events:
|
if events:
|
||||||
log.info(f"Processing {len(events)} new URL(s)")
|
log.info(f"Processing {len(events)} new URL(s)")
|
||||||
|
|
||||||
|
now = Time.clean(Time.now())
|
||||||
|
|
||||||
for i, ev in enumerate(events, start=1):
|
for i, ev in enumerate(events, start=1):
|
||||||
handler = partial(
|
handler = partial(
|
||||||
process_event,
|
process_event,
|
||||||
|
|
@ -152,11 +117,7 @@ async def scrape() -> None:
|
||||||
log=log,
|
log=log,
|
||||||
)
|
)
|
||||||
|
|
||||||
sport, event, ts = (
|
sport, event = ev["sport"], ev["event"]
|
||||||
ev["sport"],
|
|
||||||
ev["event"],
|
|
||||||
ev["event_ts"],
|
|
||||||
)
|
|
||||||
|
|
||||||
key = f"[{sport}] {event} ({TAG})"
|
key = f"[{sport}] {event} ({TAG})"
|
||||||
|
|
||||||
|
|
@ -166,7 +127,7 @@ async def scrape() -> None:
|
||||||
"url": url,
|
"url": url,
|
||||||
"logo": logo,
|
"logo": logo,
|
||||||
"base": iframe,
|
"base": iframe,
|
||||||
"timestamp": ts,
|
"timestamp": now.timestamp(),
|
||||||
"id": tvg_id or "Live.Event.us",
|
"id": tvg_id or "Live.Event.us",
|
||||||
"link": link,
|
"link": link,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,8 @@ async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
|
||||||
|
|
||||||
feed = feedparser.parse(html_data.content)
|
feed = feedparser.parse(html_data.content)
|
||||||
|
|
||||||
|
sport = "Live Event"
|
||||||
|
|
||||||
for entry in feed.entries:
|
for entry in feed.entries:
|
||||||
if not (link := entry.get("link")):
|
if not (link := entry.get("link")):
|
||||||
continue
|
continue
|
||||||
|
|
@ -68,8 +70,6 @@ async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
|
||||||
if not (title := entry.get("title")):
|
if not (title := entry.get("title")):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
sport = "Live Event"
|
|
||||||
|
|
||||||
title = title.replace(" v ", " vs ")
|
title = title.replace(" v ", " vs ")
|
||||||
|
|
||||||
if f"[{sport}] {title} ({TAG})" in cached_keys:
|
if f"[{sport}] {title} ({TAG})" in cached_keys:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue