From 00000d9759494c06b33a3aa5f61591e105ab7446 Mon Sep 17 00:00:00 2001 From: doms9 <96013514+doms9@users.noreply.github.com> Date: Wed, 10 Jun 2026 02:12:50 -0400 Subject: [PATCH] e - add resportz.py - add vivatops.py - remove totalsportek.py - misc. edits --- M3U8/fetch.py | 9 +- M3U8/scrapers/fawa.py | 2 +- M3U8/scrapers/pelotalibre.py | 4 +- M3U8/scrapers/resportz.py | 168 +++++++++++++++++++++++++ M3U8/scrapers/shark.py | 2 - M3U8/scrapers/totalsportek.py | 227 ---------------------------------- M3U8/scrapers/vivatops.py | 159 ++++++++++++++++++++++++ 7 files changed, 335 insertions(+), 236 deletions(-) create mode 100644 M3U8/scrapers/resportz.py delete mode 100644 M3U8/scrapers/totalsportek.py create mode 100644 M3U8/scrapers/vivatops.py diff --git a/M3U8/fetch.py b/M3U8/fetch.py index 25d7691d..e7f982a4 100644 --- a/M3U8/fetch.py +++ b/M3U8/fetch.py @@ -12,13 +12,14 @@ from scrapers import ( istreameast, mainportal, pelotalibre, + resportz, roxie, shark, streambiz, streamcenter, streamsgate, streamtp, - totalsportek, + vivatops, watchfooty, webcast, xyzstream, @@ -69,11 +70,12 @@ async def main() -> None: asyncio.create_task(istreameast.scrape()), # asyncio.create_task(mainportal.scrape()), asyncio.create_task(pelotalibre.scrape()), + asyncio.create_task(resportz.scrape()), asyncio.create_task(shark.scrape()), asyncio.create_task(streamcenter.scrape()), asyncio.create_task(streamsgate.scrape()), asyncio.create_task(streamtp.scrape()), - asyncio.create_task(totalsportek.scrape()), + asyncio.create_task(vivatops.scrape()), asyncio.create_task(webcast.scrape()), asyncio.create_task(xyzstream.scrape()), ] @@ -99,13 +101,14 @@ async def main() -> None: | istreameast.urls | mainportal.urls | pelotalibre.urls + | resportz.urls | roxie.urls | shark.urls | streambiz.urls | streamcenter.urls | streamsgate.urls | streamtp.urls - | totalsportek.urls + | vivatops.urls | watchfooty.urls | webcast.urls | xyzstream.urls diff --git a/M3U8/scrapers/fawa.py b/M3U8/scrapers/fawa.py index 05cf6e19..900f9c5d 100644 --- a/M3U8/scrapers/fawa.py +++ b/M3U8/scrapers/fawa.py @@ -29,7 +29,7 @@ async def process_event(url: str, url_num: int) -> str | None: ) if not (match := valid_m3u8.search(html_data.text)): - log.info(f"URL {url_num}) No M3U8 found") + log.warning(f"URL {url_num}) No M3U8 found") return diff --git a/M3U8/scrapers/pelotalibre.py b/M3U8/scrapers/pelotalibre.py index 58a03955..a2cec1b7 100644 --- a/M3U8/scrapers/pelotalibre.py +++ b/M3U8/scrapers/pelotalibre.py @@ -17,14 +17,12 @@ API_URL = "https://la18hd.com/eventos/json/agenda123.json" async def process_event(url: str, url_num: int) -> str | None: if not (html_data := await network.request(url, log=log)): log.warning(f"URL {url_num}) Failed to load url.") - return valid_m3u8 = re.compile(r'var\s+playbackURL\s+=\s+"([^"]*)"', re.I) if not (match := valid_m3u8.search(html_data.text)): - log.info(f"URL {url_num}) No M3U8 found") - + log.warning(f"URL {url_num}) No M3U8 found") return log.info(f"URL {url_num}) Captured M3U8") diff --git a/M3U8/scrapers/resportz.py b/M3U8/scrapers/resportz.py new file mode 100644 index 00000000..21149223 --- /dev/null +++ b/M3U8/scrapers/resportz.py @@ -0,0 +1,168 @@ +import base64 +import re +from functools import partial + +from .utils import Cache, Time, get_logger, leagues, network + +log = get_logger(__name__) + +urls: dict[str, dict[str, str | float]] = {} + +TAG = "RESPRTZ" + +CACHE_FILE = Cache(TAG, exp=3_600) + +API_FILE = Cache(f"{TAG}-api", exp=28_800) + +API_URL = "https://streameast.mov/api/events" + + +async def process_event(channel_id: str, url_num: int) -> tuple[str | None, str | None]: + nones = None, None + + ifr_url, ref_url = ( + f"https://donis.jimpenopisonline.online/premiumtv/resportz.php?id={channel_id}", + f"https://resportz.cfd/live/stream-{channel_id}.php", + ) + + if not ( + html_data := await network.request( + ifr_url, + headers={"Referer": ref_url}, + log=log, + ) + ): + log.warning(f"URL {url_num}) Failed to load url.") + return nones + + pattern = re.compile(r'source:\s+window.atob\((\'|\")([^"]*)(\'|\")\)', re.I) + + if not (match := pattern.search(html_data.text)): + log.warning(f"URL {url_num}) No M3U8 found") + return nones + + log.info(f"URL {url_num}) Captured M3U8") + + return base64.b64decode(match[2]).decode("utf-8"), ref_url + + +async def get_events() -> list[dict[str, str]]: + now = Time.clean(Time.now()) + + events = [] + + if not (api_data := API_FILE.load(per_entry=False, index=-1)): + log.info("Refreshing API cache") + + api_data = [{"timestamp": now.timestamp()}] + + if r := await network.request(API_URL, log=log): + api_data: list[dict] = r.json() + + api_data[-1]["timestamp"] = now.timestamp() + + API_FILE.write(api_data) + + if not (date := api_data[0].get("day")): + return events + + api_date = re.sub( + r"(?<=\d)(st|nd|rd|th)", + "", + date.split("-")[0].strip(), + flags=re.I, + ) + + if api_date != f"{now:%A} {now.day} {now:%B} {now:%Y}": + return events + + for category in api_data[0].get("categories", {}): + if category.lower() in ["popular live events", "tv shows"]: + continue + + category_info = api_data[0]["categories"][category] + + for event_info in category_info: + if event_info.get("source") != "tv": + continue + + if not (channels := event_info.get("channels")): + continue + + name: str = event_info["event"] + + channel_id: str = channels[0]["channel_id"] + + events.append( + { + "sport": ( + "Soccer" + if category.lower() == "all soccer events" + else category + ), + "event": name, + "channel-id": channel_id, + "timestamp": now.timestamp(), + } + ) + + return events + + +async def scrape() -> None: + if cached_urls := CACHE_FILE.load(): + urls.update({k: v for k, v in cached_urls.items() if v["url"]}) + + log.info(f"Loaded {len(urls)} event(s) from cache") + + return + + log.info('Scraping from "https://streameast.mov"') + + if events := await get_events(): + log.info(f"Processing {len(events)} URL(s)") + + for i, ev in enumerate(events, start=1): + handler = partial( + process_event, + channel_id=ev["channel-id"], + url_num=i, + ) + + url, iframe = await network.safe_process( + handler, + url_num=i, + semaphore=network.HTTP_S, + log=log, + ) + + sport, event, ts = ( + ev["sport"], + ev["event"], + ev["timestamp"], + ) + + key = f"[{sport}] {event} ({TAG})" + + tvg_id, logo = leagues.get_tvg_info(sport, event) + + entry = { + "url": url, + "logo": logo, + "base": iframe, + "timestamp": ts, + "id": tvg_id or "Live.Event.us", + "link": iframe, + } + + cached_urls[key] = entry + + if url: + urls[key] = entry + + log.info(f"Collected and cached {len(urls)} event(s)") + + else: + log.info("No events found") + + CACHE_FILE.write(cached_urls) diff --git a/M3U8/scrapers/shark.py b/M3U8/scrapers/shark.py index 35f1eb94..b6e418ad 100644 --- a/M3U8/scrapers/shark.py +++ b/M3U8/scrapers/shark.py @@ -19,14 +19,12 @@ BASE_URL = "https://sharkstreams.net" async def process_event(url: str, url_num: int) -> str | None: if not (r := await network.request(url, log=log)): log.warning(f"URL {url_num}) Failed to load url.") - return data: dict[str, list[str]] = r.json() if not (urls := data.get("urls")): log.warning(f"URL {url_num}) No M3U8 found") - return log.info(f"URL {url_num}) Captured M3U8") diff --git a/M3U8/scrapers/totalsportek.py b/M3U8/scrapers/totalsportek.py deleted file mode 100644 index adc2fa42..00000000 --- a/M3U8/scrapers/totalsportek.py +++ /dev/null @@ -1,227 +0,0 @@ -import json -import re -from functools import partial -from urllib.parse import urljoin, urlparse - -from selectolax.parser import HTMLParser - -from .utils import Cache, Time, get_logger, leagues, network - -log = get_logger(__name__) - -urls: dict[str, dict[str, str | float]] = {} - -TAG = "TSPRTK" - -CACHE_FILE = Cache(TAG, exp=19_800) - -BASES = { - "TSPRTK1": "https://live.totalsportek.rodeo", - "TSPRTK3": "https://live3.totalsportek.rodeo", -} - - -def fix_txt(s: str) -> str: - s = " ".join(s.split()) - - return s.upper() if s.islower() else s - - -async def process_ts1(ifr_src: str, url_num: int) -> str | None: - if not (ifr_src_data := await network.request(ifr_src, log=log)): - log.info(f"URL {url_num}) Failed to load iframe source.") - return - - valid_m3u8 = re.compile(r'(var|const)\s+(\w+)\s+=\s+"([^"]*)"', re.I) - - if not (match := valid_m3u8.search(ifr_src_data.text)): - log.warning(f"URL {url_num}) No Clappr source found.") - return - - if len(encoded := match[2]) < 20: - encoded = match[3] - - log.info(f"URL {url_num}) Captured M3U8") - - return bytes.fromhex(encoded).decode("utf-8") - - -async def process_ts3(ifr_src: str, url_num: int) -> str | None: - if not (ifr_1_src_data := await network.request(ifr_src, log=log)): - log.warning(f"URL {url_num}) Failed to load iframe source. (IFR1)") - return - - soup = HTMLParser(ifr_1_src_data.content) - - ifr_2 = soup.css_first("iframe") - - if not ifr_2 or not (ifr_2_src := ifr_2.attributes.get("src")): - log.warning(f"URL {url_num}) No iframe element found. (IFR2)") - return - - if not ( - ifr_2_src_data := await network.request( - ifr_2_src, - headers={"Referer": ifr_src}, - log=log, - ) - ): - log.warning(f"URL {url_num}) Failed to load iframe source. (IFR2)") - return - - valid_m3u8 = re.compile(r'StreamUrl\s+=\s+"([^"]*)"', re.I) - - if not (match := valid_m3u8.search(ifr_2_src_data.text)): - log.warning(f"URL {url_num}) No Clappr source found.") - return - - log.info(f"URL {url_num}) Captured M3U8") - - return json.loads(f'"{match[1]}"') - - -async def process_event( - url: str, - url_num: int, - tag: str, -) -> tuple[str | None, str | None]: - - nones = None, None - - if not (event_data := await network.request(url, log=log)): - log.warning(f"URL {url_num}) Failed to load url.") - return nones - - soup = HTMLParser(event_data.content) - - iframe = soup.css_first("iframe") - - if not iframe or not (iframe_src := iframe.attributes.get("src")): - log.warning(f"URL {url_num}) No valid iframe source found.") - return nones - - m3u8 = ( - await process_ts1(iframe_src, url_num) - if tag == "TSPRTK1" - else await process_ts3(iframe_src, url_num) - ) - - return (m3u8, iframe_src) if m3u8 else nones - - -async def get_events(cached_keys: list[str]) -> list[dict[str, str]]: - events = [] - - if not (html_data := await network.request(BASES["TSPRTK1"], log=log)): - return events - - soup = HTMLParser(html_data.content) - - sport = "Live Event" - - for tag, url in BASES.items(): - for node in soup.css("a"): - if not node.attributes.get("class"): - continue - - if (parent := node.parent) and "my-1" in parent.attributes.get("class", ""): - if span := node.css_first("span"): - sport = span.text(strip=True) - - sport = fix_txt(sport) - - if not (teams := [t.text(strip=True) for t in node.css(".col-7 .col-12")]): - continue - - if not (href := node.attributes.get("href")): - continue - - href = urlparse(href).path if href.startswith("http") else href - - # if not (time_node := node.css_first(".col-3 span")): - # continue - - # if time_node.text(strip=True).lower() not in [ - # "matchstarted", - # "1minfrom now", - # ]: - # continue - - event_name = fix_txt(" vs ".join(teams)) - - if f"[{sport}] {event_name} ({tag})" in cached_keys: - continue - - events.append( - { - "sport": sport, - "event": event_name, - "tag": tag, - "link": urljoin(url, href), - } - ) - - return events - - -async def scrape() -> None: - cached_urls = CACHE_FILE.load() - - valid_urls = {k: v for k, v in cached_urls.items() if v["url"]} - - valid_count = cached_count = len(valid_urls) - - urls.update(valid_urls) - - log.info(f"Loaded {cached_count} event(s) from cache") - - log.info('Scraping from "https://live.totalsportek.fyi"') - - if events := await get_events(cached_urls.keys()): - log.info(f"Processing {len(events)} new URL(s)") - - now = Time.clean(Time.now()) - - for i, ev in enumerate(events, start=1): - handler = partial( - process_event, - url=(link := ev["link"]), - url_num=i, - tag=(tag := ev["tag"]), - ) - - url, iframe = await network.safe_process( - handler, - url_num=i, - semaphore=network.HTTP_S, - log=log, - ) - - sport, event = ev["sport"], ev["event"] - - key = f"[{sport}] {event} ({tag})" - - tvg_id, logo = leagues.get_tvg_info(sport, event) - - entry = { - "url": url, - "logo": logo, - "base": iframe, - "timestamp": now.timestamp(), - "id": tvg_id or "Live.Event.us", - "link": link, - } - - cached_urls[key] = entry - - if url: - valid_count += 1 - - urls[key] = entry - - log.info(f"Collected and cached {valid_count - cached_count} new event(s)") - - else: - log.info("No new events found") - - CACHE_FILE.write(cached_urls) diff --git a/M3U8/scrapers/vivatops.py b/M3U8/scrapers/vivatops.py new file mode 100644 index 00000000..ab8cef25 --- /dev/null +++ b/M3U8/scrapers/vivatops.py @@ -0,0 +1,159 @@ +import json +import re +from functools import partial +from urllib.parse import parse_qsl, urlsplit + +from selectolax.parser import HTMLParser + +from .utils import Cache, Time, get_logger, leagues, network + +log = get_logger(__name__) + +urls: dict[str, dict[str, str | float]] = {} + +TAG = "VIVATOPS" + +CACHE_FILE = Cache(TAG, exp=19_800) + +BASE_URL = "https://vivatops.cyou" + + +async def process_event(channel_id: str, url_num: int) -> str | None: + nones = None, None + + ifr_url, ref_url = ( + f"https://edher.lockedherhe.site/player_stateless/channel{channel_id}", + f"{BASE_URL}/vivo/?ch={channel_id}", + ) + + if not ( + html_data := await network.request( + ifr_url, + headers={"Referer": ref_url}, + log=log, + ) + ): + log.warning(f"URL {url_num}) Failed to load url.") + return nones + + valid_m3u8 = re.compile(r'streamUrl\s+=\s+"([^"]*)"', re.I) + + if not (match := valid_m3u8.search(html_data.text)): + log.warning(f"URL {url_num}) No M3U8 found") + return nones + + log.info(f"URL {url_num}) Captured M3U8") + + return json.loads(f'"{match[1]}"'), ref_url + + +async def get_events() -> list[dict[str, str]]: + now = Time.clean(Time.now()) + + events = [] + + if not (html_data := await network.request(BASE_URL, log=log)): + return events + + soup = HTMLParser(html_data.content) + + if not (last_update := soup.css_first("h2.update")): + return events + + elif ( + now.strftime("%d-%m-%y") + != last_update.text(strip=True).split(":")[-1].split()[0] + ): + return events + + sport = "Live Event" + + for matches in soup.css(".match"): + if not (a_elem := matches.css_first("a")) or not ( + href := a_elem.attributes.get("href") + ): + continue + + params = dict(parse_qsl(urlsplit(href).query, keep_blank_values=True)) + + if not (channel_id := params.get("ch")): + continue + + for event in matches.css("strong"): + splits = event.text(strip=True).split() + + event_name = ( + " ".join(splits[: splits.index("-")]) + if "-" in splits + else " ".join(splits) + ) + + events.append( + { + "sport": sport, + "event": event_name, + "channel-id": channel_id, + "timestamp": now.timestamp(), + } + ) + + return events + + +async def scrape() -> None: + if cached_urls := CACHE_FILE.load(): + urls.update({k: v for k, v in cached_urls.items() if v["url"]}) + + log.info(f"Loaded {len(urls)} event(s) from cache") + + return + + log.info(f'Scraping from "{BASE_URL}"') + + if events := await get_events(): + log.info(f"Processing {len(events)} new URL(s)") + + for i, ev in enumerate(events, start=1): + handler = partial( + process_event, + channel_id=ev["channel-id"], + url_num=i, + ) + + url, iframe = await network.safe_process( + handler, + url_num=i, + semaphore=network.HTTP_S, + log=log, + ) + + sport, event, ts = ( + ev["sport"], + ev["event"], + ev["timestamp"], + ) + + key = f"[{sport}] {event} ({TAG})" + + tvg_id, logo = leagues.get_tvg_info(sport, event) + + entry = { + "url": url, + "logo": logo, + "base": iframe, + "timestamp": ts, + "id": tvg_id or "Live.Event.us", + "link": iframe, + } + + cached_urls[key] = entry + + if url: + urls[key] = entry + + log.info(f"Collected and cached {len(urls)} new event(s)") + + else: + log.info("No events found") + + CACHE_FILE.write(cached_urls)