mirror of
https://github.com/doms9/iptv.git
synced 2026-03-07 11:18:25 +01:00
Compare commits
34 commits
2f4f1b907c
...
90ec2f586d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90ec2f586d | ||
|
|
00000d927f | ||
|
|
00000d9d52 | ||
|
|
3a14fc06d8 | ||
|
|
fc0ce0e8d3 | ||
|
|
144f99bad1 | ||
|
|
1b7ac1a21e | ||
|
|
4348139220 | ||
|
|
9c94daa802 | ||
|
|
a4213bc1a2 | ||
|
|
042bd6ece9 | ||
|
|
00000d91fc | ||
|
|
53e4b14fb7 | ||
|
|
2d361f0e74 | ||
|
|
20e5676248 | ||
|
|
b4b3043671 | ||
|
|
eaf1511881 | ||
|
|
061e8cafa8 | ||
|
|
6d3b361f52 | ||
|
|
84f9050241 | ||
|
|
a7576d37b7 | ||
|
|
97d3ffbaef | ||
|
|
38333fd518 | ||
|
|
074e0c327a | ||
|
|
bcf4febb5a | ||
|
|
f65097c64a | ||
|
|
399e513e27 | ||
|
|
b6d750735a | ||
|
|
3b5e043110 | ||
|
|
00000d9290 | ||
|
|
0a22e41289 | ||
|
|
f0cd074431 | ||
|
|
d76071700d | ||
|
|
0268e87fad |
12 changed files with 93754 additions and 86395 deletions
8
.github/workflows/epg.yml
vendored
8
.github/workflows/epg.yml
vendored
|
|
@ -14,6 +14,14 @@ jobs:
|
|||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Cache venv
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: .venv
|
||||
key: venv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
|
||||
restore-keys: |
|
||||
venv-${{ runner.os }}-
|
||||
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v6
|
||||
with:
|
||||
|
|
|
|||
8
.github/workflows/m3u8.yml
vendored
8
.github/workflows/m3u8.yml
vendored
|
|
@ -22,6 +22,14 @@ jobs:
|
|||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Cache venv
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: .venv
|
||||
key: venv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
|
||||
restore-keys: |
|
||||
venv-${{ runner.os }}-
|
||||
|
||||
- name: Install uv
|
||||
if: steps.check_time.outputs.run == 'true'
|
||||
uses: astral-sh/setup-uv@v6
|
||||
|
|
|
|||
1386
M3U8/TV.m3u8
1386
M3U8/TV.m3u8
File diff suppressed because it is too large
Load diff
176444
M3U8/TV.xml
176444
M3U8/TV.xml
File diff suppressed because it is too large
Load diff
1386
M3U8/events.m3u8
1386
M3U8/events.m3u8
File diff suppressed because it is too large
Load diff
|
|
@ -9,6 +9,7 @@ from scrapers import (
|
|||
embedhd,
|
||||
fawa,
|
||||
istreameast,
|
||||
livetvsx,
|
||||
pawa,
|
||||
pixel,
|
||||
ppv,
|
||||
|
|
@ -20,11 +21,10 @@ from scrapers import (
|
|||
streamfree,
|
||||
streamhub,
|
||||
streamsgate,
|
||||
tflix,
|
||||
totalsportek,
|
||||
tvpass,
|
||||
watchfooty,
|
||||
webcast,
|
||||
xstreameast,
|
||||
)
|
||||
from scrapers.utils import get_logger, network
|
||||
|
||||
|
|
@ -63,13 +63,13 @@ async def main() -> None:
|
|||
pw_tasks = [
|
||||
asyncio.create_task(cdnlivetv.scrape(hdl_brwsr)),
|
||||
asyncio.create_task(embedhd.scrape(hdl_brwsr)),
|
||||
asyncio.create_task(livetvsx.scrape(hdl_brwsr)),
|
||||
asyncio.create_task(pixel.scrape(hdl_brwsr)),
|
||||
asyncio.create_task(ppv.scrape(xtrnl_brwsr)),
|
||||
asyncio.create_task(sport9.scrape(xtrnl_brwsr)),
|
||||
asyncio.create_task(streamcenter.scrape(xtrnl_brwsr)),
|
||||
# asyncio.create_task(streamhub.scrape(xtrnl_brwsr)),
|
||||
asyncio.create_task(streamsgate.scrape(xtrnl_brwsr)),
|
||||
# asyncio.create_task(tflix.scrape(xtrnl_brwsr)),
|
||||
asyncio.create_task(webcast.scrape(hdl_brwsr)),
|
||||
asyncio.create_task(watchfooty.scrape(xtrnl_brwsr)),
|
||||
]
|
||||
|
|
@ -82,8 +82,8 @@ async def main() -> None:
|
|||
asyncio.create_task(shark.scrape()),
|
||||
asyncio.create_task(streambtw.scrape()),
|
||||
asyncio.create_task(streamfree.scrape()),
|
||||
asyncio.create_task(totalsportek.scrape()),
|
||||
asyncio.create_task(tvpass.scrape()),
|
||||
asyncio.create_task(xstreameast.scrape()),
|
||||
]
|
||||
|
||||
await asyncio.gather(*(pw_tasks + httpx_tasks))
|
||||
|
|
@ -100,6 +100,7 @@ async def main() -> None:
|
|||
| embedhd.urls
|
||||
| fawa.urls
|
||||
| istreameast.urls
|
||||
| livetvsx.urls
|
||||
| pawa.urls
|
||||
| pixel.urls
|
||||
| ppv.urls
|
||||
|
|
@ -111,11 +112,10 @@ async def main() -> None:
|
|||
| streamfree.urls
|
||||
| streamhub.urls
|
||||
| streamsgate.urls
|
||||
| tflix.urls
|
||||
| totalsportek.urls
|
||||
| tvpass.urls
|
||||
| watchfooty.urls
|
||||
| webcast.urls
|
||||
| xstreameast.urls
|
||||
)
|
||||
|
||||
live_events: list[str] = []
|
||||
|
|
|
|||
244
M3U8/scrapers/livetvsx.py
Normal file
244
M3U8/scrapers/livetvsx.py
Normal file
|
|
@ -0,0 +1,244 @@
|
|||
import asyncio
|
||||
from functools import partial
|
||||
|
||||
import feedparser
|
||||
from playwright.async_api import Browser, Page
|
||||
|
||||
from .utils import Cache, Time, get_logger, leagues, network
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
urls: dict[str, dict[str, str | float]] = {}
|
||||
|
||||
TAG = "LTVSX"
|
||||
|
||||
XML_CACHE = Cache(f"{TAG}-xml", exp=28_000)
|
||||
|
||||
CACHE_FILE = Cache(TAG, exp=10_800)
|
||||
|
||||
BASE_URL = "https://cdn.livetv861.me/rss/upcoming_en.xml"
|
||||
|
||||
VALID_SPORTS = {"NBA", "NHL", "NFL", "NCAA", "MLB"}
|
||||
|
||||
|
||||
async def process_event(
|
||||
url: str,
|
||||
url_num: int,
|
||||
page: Page,
|
||||
) -> str | None:
|
||||
|
||||
captured: list[str] = []
|
||||
|
||||
got_one = asyncio.Event()
|
||||
|
||||
handler = partial(
|
||||
network.capture_req,
|
||||
captured=captured,
|
||||
got_one=got_one,
|
||||
)
|
||||
|
||||
page.on("request", handler)
|
||||
|
||||
try:
|
||||
await page.goto(
|
||||
url,
|
||||
wait_until="domcontentloaded",
|
||||
timeout=15_000,
|
||||
)
|
||||
|
||||
await page.wait_for_timeout(1_500)
|
||||
|
||||
buttons = await page.query_selector_all(".lnktbj a[href*='webplayer']")
|
||||
|
||||
href = None
|
||||
|
||||
for btn in buttons:
|
||||
img = await btn.query_selector("img")
|
||||
|
||||
label = (await img.get_attribute("alt") or "").lower()
|
||||
|
||||
if label == "web":
|
||||
continue
|
||||
|
||||
href = await btn.get_attribute("href")
|
||||
break
|
||||
|
||||
else:
|
||||
log.warning(f"URL {url_num}) No available stream links.")
|
||||
|
||||
return
|
||||
|
||||
href = href if href.startswith("http") else f"https:{href}"
|
||||
|
||||
await page.goto(
|
||||
href,
|
||||
wait_until="domcontentloaded",
|
||||
timeout=5_000,
|
||||
)
|
||||
|
||||
wait_task = asyncio.create_task(got_one.wait())
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(wait_task, timeout=6)
|
||||
except asyncio.TimeoutError:
|
||||
log.warning(f"URL {url_num}) Timed out waiting for M3U8.")
|
||||
return
|
||||
|
||||
finally:
|
||||
if not wait_task.done():
|
||||
wait_task.cancel()
|
||||
|
||||
try:
|
||||
await wait_task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
|
||||
if captured:
|
||||
log.info(f"URL {url_num}) Captured M3U8")
|
||||
return captured[0]
|
||||
|
||||
log.warning(f"URL {url_num}) No M3U8 captured after waiting.")
|
||||
return
|
||||
|
||||
except Exception as e:
|
||||
log.warning(f"URL {url_num}) Exception while processing: {e}")
|
||||
return
|
||||
|
||||
finally:
|
||||
page.remove_listener("request", handler)
|
||||
|
||||
|
||||
async def refresh_xml_cache(now_ts: float) -> dict[str, dict[str, str | float]]:
|
||||
log.info("Refreshing XML cache")
|
||||
|
||||
events = {}
|
||||
|
||||
if not (xml_data := await network.request(BASE_URL, log=log)):
|
||||
return events
|
||||
|
||||
feed = feedparser.parse(xml_data.content)
|
||||
|
||||
for entry in feed.entries:
|
||||
title = entry.get("title")
|
||||
|
||||
link = entry.get("link")
|
||||
|
||||
sport_sum = entry.get("summary")
|
||||
|
||||
date = entry.get("published")
|
||||
|
||||
if not all([title, link, sport_sum, date]):
|
||||
continue
|
||||
|
||||
sport = sport_sum.split()[-1]
|
||||
|
||||
if sport not in VALID_SPORTS:
|
||||
continue
|
||||
|
||||
event_dt = Time.from_str(date)
|
||||
|
||||
key = f"[{sport}] {title} ({TAG})"
|
||||
|
||||
events[key] = {
|
||||
"sport": sport,
|
||||
"event": title,
|
||||
"link": link,
|
||||
"event_ts": event_dt.timestamp(),
|
||||
"timestamp": now_ts,
|
||||
}
|
||||
|
||||
return events
|
||||
|
||||
|
||||
async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
|
||||
now = Time.clean(Time.now())
|
||||
|
||||
if not (events := XML_CACHE.load()):
|
||||
events = await refresh_xml_cache(now.timestamp())
|
||||
|
||||
XML_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(browser: Browser) -> 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://livetv.sx/enx/"')
|
||||
|
||||
events = await get_events(cached_urls.keys())
|
||||
|
||||
log.info(f"Processing {len(events)} new URL(s)")
|
||||
|
||||
if events:
|
||||
async with network.event_context(browser) as context:
|
||||
for i, ev in enumerate(events, start=1):
|
||||
async with network.event_page(context) as page:
|
||||
handler = partial(
|
||||
process_event,
|
||||
url=ev["link"],
|
||||
url_num=i,
|
||||
page=page,
|
||||
)
|
||||
|
||||
url = await network.safe_process(
|
||||
handler,
|
||||
url_num=i,
|
||||
semaphore=network.PW_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": "https://livetv.sx/enx/",
|
||||
"timestamp": ts,
|
||||
"id": tvg_id or "Live.Event.us",
|
||||
}
|
||||
|
||||
cached_urls[key] = entry
|
||||
|
||||
if url:
|
||||
valid_count += 1
|
||||
|
||||
urls[key] = entry
|
||||
|
||||
if new_count := valid_count - cached_count:
|
||||
log.info(f"Collected and cached {new_count} new event(s)")
|
||||
|
||||
else:
|
||||
log.info("No new events found")
|
||||
|
||||
CACHE_FILE.write(cached_urls)
|
||||
|
|
@ -1,234 +0,0 @@
|
|||
import asyncio
|
||||
from functools import partial
|
||||
from urllib.parse import urljoin
|
||||
|
||||
import feedparser
|
||||
from playwright.async_api import Browser, Error, Page, TimeoutError
|
||||
|
||||
from .utils import Cache, Time, get_logger, leagues, network
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
urls: dict[str, dict[str, str | float]] = {}
|
||||
|
||||
TAG = "TFLIX"
|
||||
|
||||
CACHE_FILE = Cache(TAG, exp=28_800)
|
||||
|
||||
BASE_URL = "https://tv.tflix.app/"
|
||||
|
||||
SPORT_ENDPOINTS = ["football", "nba", "nfl", "nhl"]
|
||||
|
||||
|
||||
async def process_event(
|
||||
url: str,
|
||||
url_num: int,
|
||||
page: Page,
|
||||
) -> tuple[str | None, str | None]:
|
||||
try:
|
||||
await page.goto(
|
||||
url,
|
||||
wait_until="domcontentloaded",
|
||||
timeout=15_000,
|
||||
)
|
||||
|
||||
try:
|
||||
iframe = await page.wait_for_selector(
|
||||
"iframe.metaframe.rptss",
|
||||
timeout=3_500,
|
||||
)
|
||||
except TimeoutError:
|
||||
log.warning(f"URL {url_num}) No iframe element.")
|
||||
|
||||
return None, None
|
||||
|
||||
if (old_src := await iframe.get_attribute("src")) and old_src.startswith(
|
||||
"https://kloxmkhs.site/stream"
|
||||
):
|
||||
new_src = old_src
|
||||
|
||||
else:
|
||||
try:
|
||||
option = await page.wait_for_selector(
|
||||
'li.dooplay_player_option >> span.title:has-text("TFLIX HD - iOS")',
|
||||
timeout=3_000,
|
||||
)
|
||||
|
||||
await option.scroll_into_view_if_needed()
|
||||
|
||||
await option.evaluate("el => el.click()")
|
||||
|
||||
await page.wait_for_function(
|
||||
"""
|
||||
(oldSrc) => {
|
||||
const iframe = document.querySelector('iframe.metaframe.rptss');
|
||||
return iframe && iframe.src && iframe.src !== oldSrc;
|
||||
};
|
||||
""",
|
||||
arg=old_src,
|
||||
timeout=5_000,
|
||||
)
|
||||
|
||||
iframe_2 = await page.wait_for_selector("iframe.metaframe.rptss")
|
||||
|
||||
if not iframe_2 or not (new_src := await iframe_2.get_attribute("src")):
|
||||
log.warning(f"URL {url_num}) No iframe source.")
|
||||
|
||||
return None, None
|
||||
except TimeoutError:
|
||||
log.warning(f"URL {url_num}) No valid TFLIX source.")
|
||||
|
||||
return None, None
|
||||
|
||||
try:
|
||||
await page.goto(
|
||||
new_src,
|
||||
wait_until="domcontentloaded",
|
||||
timeout=10_000,
|
||||
referer=url,
|
||||
)
|
||||
except Error:
|
||||
log.warning(
|
||||
f"URL {url_num}) HTTP 403/404 error while redirecting to iframe source."
|
||||
)
|
||||
|
||||
return None, None
|
||||
|
||||
try:
|
||||
play_btn = await page.wait_for_selector(
|
||||
'button[data-url][onclick*="startPlcb"]',
|
||||
timeout=5_000,
|
||||
)
|
||||
except TimeoutError:
|
||||
log.warning(f"URL {url_num}) No play button found.")
|
||||
|
||||
return None, None
|
||||
|
||||
if not (data_url := await play_btn.get_attribute("data-url")):
|
||||
log.warning(f"URL {url_num}) No PBID found.")
|
||||
|
||||
return None, None
|
||||
|
||||
log.info(f"URL {url_num}) Captured M3U8")
|
||||
|
||||
return (
|
||||
f"https://kloxmkhs.site/stream/stream.m3u8?id={data_url}&format=.m3u8",
|
||||
new_src,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
log.warning(f"URL {url_num}) Exception while processing: {e}")
|
||||
|
||||
return None, None
|
||||
|
||||
|
||||
async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
|
||||
tasks = [
|
||||
network.request(urljoin(BASE_URL, f"genre/{sport}/feed"), log=log)
|
||||
for sport in SPORT_ENDPOINTS
|
||||
]
|
||||
|
||||
results = await asyncio.gather(*tasks)
|
||||
|
||||
events = []
|
||||
|
||||
if not (feeds := [feedparser.parse(html.content) for html in results if html]):
|
||||
return events
|
||||
|
||||
for feed in feeds:
|
||||
title: str = feed["feed"]["title"]
|
||||
|
||||
sport = title.split("Archives")[0].strip()
|
||||
|
||||
for entry in feed.entries:
|
||||
if not (link := entry.get("link")):
|
||||
continue
|
||||
|
||||
if not (title := entry.get("title")):
|
||||
continue
|
||||
|
||||
if f"[{sport}] {title} ({TAG})" in cached_keys:
|
||||
continue
|
||||
|
||||
events.append(
|
||||
{
|
||||
"sport": sport,
|
||||
"event": title,
|
||||
"link": link,
|
||||
}
|
||||
)
|
||||
|
||||
return events
|
||||
|
||||
|
||||
async def scrape(browser: Browser) -> 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(cached_urls)
|
||||
|
||||
urls.update(valid_urls)
|
||||
|
||||
log.info(f"Loaded {cached_count} event(s) from cache")
|
||||
|
||||
log.info(f'Scraping from "{BASE_URL}"')
|
||||
|
||||
events = await get_events(cached_urls.keys())
|
||||
|
||||
log.info(f"Processing {len(events)} new URL(s)")
|
||||
|
||||
if events:
|
||||
now = Time.clean(Time.now()).timestamp()
|
||||
|
||||
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:
|
||||
handler = partial(
|
||||
process_event,
|
||||
url=ev["link"],
|
||||
url_num=i,
|
||||
page=page,
|
||||
)
|
||||
|
||||
url, iframe = await network.safe_process(
|
||||
handler,
|
||||
url_num=i,
|
||||
semaphore=network.PW_S,
|
||||
log=log,
|
||||
timeout=20,
|
||||
)
|
||||
|
||||
sport, event, link = (
|
||||
ev["sport"],
|
||||
ev["event"],
|
||||
ev["link"],
|
||||
)
|
||||
|
||||
key = f"[{sport}] {event} ({TAG})"
|
||||
|
||||
tvg_id, logo = leagues.get_tvg_info(sport, event)
|
||||
|
||||
entry = {
|
||||
"url": url,
|
||||
"logo": logo,
|
||||
"base": iframe,
|
||||
"timestamp": now,
|
||||
"id": tvg_id or "Live.Event.us",
|
||||
"link": link,
|
||||
}
|
||||
|
||||
cached_urls[key] = entry
|
||||
|
||||
if url:
|
||||
valid_count += 1
|
||||
|
||||
urls[key] = entry
|
||||
|
||||
if new_count := valid_count - cached_count:
|
||||
log.info(f"Collected and cached {new_count} new event(s)")
|
||||
|
||||
else:
|
||||
log.info("No new events found")
|
||||
|
||||
CACHE_FILE.write(cached_urls)
|
||||
|
|
@ -1,205 +0,0 @@
|
|||
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 = "TOTALSPRTK"
|
||||
|
||||
CACHE_FILE = Cache(TAG, exp=28_800)
|
||||
|
||||
MIRRORS = [
|
||||
{
|
||||
"base": "https://live.totalsportek777.com/",
|
||||
"hex_decode": True,
|
||||
},
|
||||
{
|
||||
"base": "https://live2.totalsportek777.com/",
|
||||
"hex_decode": False,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def fix_txt(s: str) -> str:
|
||||
s = " ".join(s.split())
|
||||
|
||||
return s.upper() if s.islower() else s
|
||||
|
||||
|
||||
async def process_event(href: str, url_num: int) -> tuple[str | None, str | None]:
|
||||
valid_m3u8 = re.compile(r'var\s+(\w+)\s*=\s*"([^"]*)"', re.IGNORECASE)
|
||||
|
||||
for x, mirror in enumerate(MIRRORS, start=1):
|
||||
base: str = mirror["base"]
|
||||
|
||||
hex_decode: bool = mirror["hex_decode"]
|
||||
|
||||
url = urljoin(base, href)
|
||||
|
||||
if not (html_data := await network.request(url, log=log)):
|
||||
log.info(f"M{x} | URL {url_num}) Failed to load url.")
|
||||
|
||||
return None, None
|
||||
|
||||
soup = HTMLParser(html_data.content)
|
||||
|
||||
iframe = soup.css_first("iframe")
|
||||
|
||||
if not iframe or not (iframe_src := iframe.attributes.get("src")):
|
||||
log.warning(f"M{x} | URL {url_num}) No iframe element found.")
|
||||
continue
|
||||
|
||||
if not (iframe_src_data := await network.request(iframe_src, log=log)):
|
||||
log.warning(f"M{x} | URL {url_num}) Failed to load iframe source.")
|
||||
continue
|
||||
|
||||
if not (match := valid_m3u8.search(iframe_src_data.text)):
|
||||
log.warning(f"M{x} | URL {url_num}) No Clappr source found.")
|
||||
continue
|
||||
|
||||
raw: str = match[2]
|
||||
|
||||
try:
|
||||
m3u8_url = bytes.fromhex(raw).decode("utf-8") if hex_decode else raw
|
||||
except Exception as e:
|
||||
log.warning(f"M{x} | URL {url_num}) Decoding failed: {e}")
|
||||
continue
|
||||
|
||||
if m3u8_url and iframe_src:
|
||||
log.info(f"M{x} | URL {url_num}) Captured M3U8")
|
||||
|
||||
return m3u8_url, iframe_src
|
||||
|
||||
log.warning(f"M{x} | URL {url_num}) No M3U8 found")
|
||||
|
||||
return None, None
|
||||
|
||||
|
||||
async def get_events(url: str, cached_keys: list[str]) -> list[dict[str, str]]:
|
||||
events = []
|
||||
|
||||
if not (html_data := await network.request(url, log=log)):
|
||||
return events
|
||||
|
||||
soup = HTMLParser(html_data.content)
|
||||
|
||||
sport = "Live Event"
|
||||
|
||||
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) != "MatchStarted":
|
||||
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,
|
||||
"href": 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")
|
||||
|
||||
if not (base_url := await network.get_base([mirr["base"] for mirr in MIRRORS])):
|
||||
log.warning("No working TotalSportek mirrors")
|
||||
|
||||
CACHE_FILE.write(cached_urls)
|
||||
|
||||
return
|
||||
|
||||
events = await get_events(base_url, cached_urls.keys())
|
||||
|
||||
log.info(f"Processing {len(events)} new URL(s)")
|
||||
|
||||
if events:
|
||||
now = Time.clean(Time.now())
|
||||
|
||||
for i, ev in enumerate(events, start=1):
|
||||
handler = partial(
|
||||
process_event,
|
||||
href=ev["href"],
|
||||
url_num=i,
|
||||
)
|
||||
|
||||
url, iframe = await network.safe_process(
|
||||
handler,
|
||||
url_num=i,
|
||||
semaphore=network.HTTP_S,
|
||||
log=log,
|
||||
)
|
||||
|
||||
sport, event, href = (
|
||||
ev["sport"],
|
||||
ev["event"],
|
||||
ev["href"],
|
||||
)
|
||||
|
||||
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",
|
||||
"href": href,
|
||||
}
|
||||
|
||||
cached_urls[key] = entry
|
||||
|
||||
if url:
|
||||
valid_count += 1
|
||||
|
||||
urls[key] = entry
|
||||
|
||||
if new_count := valid_count - cached_count:
|
||||
log.info(f"Collected and cached {new_count} new event(s)")
|
||||
|
||||
else:
|
||||
log.info("No new events found")
|
||||
|
||||
CACHE_FILE.write(cached_urls)
|
||||
|
|
@ -76,6 +76,8 @@ async def process_event(
|
|||
page: Page,
|
||||
) -> tuple[str | None, str | None]:
|
||||
|
||||
nones = [None for _ in range(2)]
|
||||
|
||||
pattern = re.compile(r"\((\d+)\)")
|
||||
|
||||
captured: list[str] = []
|
||||
|
|
@ -106,12 +108,12 @@ async def process_event(
|
|||
except TimeoutError:
|
||||
log.warning(f"URL {url_num}) Can't find stream links header.")
|
||||
|
||||
return None, None
|
||||
return nones
|
||||
|
||||
if not (match := pattern.search(text)) or int(match[1]) == 0:
|
||||
log.warning(f"URL {url_num}) No available stream links.")
|
||||
|
||||
return None, None
|
||||
return nones
|
||||
|
||||
try:
|
||||
first_available = await page.wait_for_selector(
|
||||
|
|
@ -121,12 +123,12 @@ async def process_event(
|
|||
except TimeoutError:
|
||||
log.warning(f"URL {url_num}) No available stream links.")
|
||||
|
||||
return None, None
|
||||
return nones
|
||||
|
||||
if not (href := await first_available.get_attribute("href")):
|
||||
log.warning(f"URL {url_num}) No available stream links.")
|
||||
|
||||
return None, None
|
||||
return nones
|
||||
|
||||
embed = re.sub(
|
||||
pattern=r"^.*\/stream",
|
||||
|
|
@ -147,7 +149,7 @@ async def process_event(
|
|||
except asyncio.TimeoutError:
|
||||
log.warning(f"URL {url_num}) Timed out waiting for M3U8.")
|
||||
|
||||
return None, None
|
||||
return nones
|
||||
|
||||
finally:
|
||||
if not wait_task.done():
|
||||
|
|
@ -165,12 +167,12 @@ async def process_event(
|
|||
|
||||
log.warning(f"URL {url_num}) No M3U8 captured after waiting.")
|
||||
|
||||
return None, None
|
||||
return nones
|
||||
|
||||
except Exception as e:
|
||||
log.warning(f"URL {url_num}) Exception while processing: {e}")
|
||||
|
||||
return None, None
|
||||
return nones
|
||||
|
||||
finally:
|
||||
page.remove_listener("request", handler)
|
||||
|
|
|
|||
188
M3U8/scrapers/xstreameast.py
Normal file
188
M3U8/scrapers/xstreameast.py
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
import asyncio
|
||||
import re
|
||||
from functools import partial
|
||||
from urllib.parse import urljoin
|
||||
|
||||
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 = "XSTRMEST"
|
||||
|
||||
CACHE_FILE = Cache(TAG, exp=10_800)
|
||||
|
||||
BASE_URL = "https://xstreameast.com"
|
||||
|
||||
SPORT_ENDPOINTS = [
|
||||
# "f1",
|
||||
# "mlb",
|
||||
"mma",
|
||||
"nba",
|
||||
"nfl",
|
||||
"nhl",
|
||||
"soccer",
|
||||
"wwe",
|
||||
]
|
||||
|
||||
|
||||
async def process_event(url: str, url_num: int) -> tuple[str | None, str | None]:
|
||||
valid_m3u8 = re.compile(r'var\s+(\w+)\s*=\s*"([^"]*)"', re.IGNORECASE)
|
||||
|
||||
nones = [None for _ in range(2)]
|
||||
|
||||
if not (html_data := await network.request(url, log=log)):
|
||||
log.info(f"URL {url_num}) Failed to load url.")
|
||||
return nones
|
||||
|
||||
soup = HTMLParser(html_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 iframe element found.")
|
||||
return nones
|
||||
|
||||
elif iframe_src == "about:blank":
|
||||
log.warning(f"URL {url_num}) No iframe element found.")
|
||||
return nones
|
||||
|
||||
if not (iframe_src_data := await network.request(iframe_src, log=log)):
|
||||
log.warning(f"URL {url_num}) Failed to load iframe source.")
|
||||
return nones
|
||||
|
||||
if not (match := valid_m3u8.search(iframe_src_data.text)):
|
||||
log.warning(f"URL {url_num}) No Clappr source found.")
|
||||
return nones
|
||||
|
||||
log.info(f"URL {url_num}) Captured M3U8")
|
||||
|
||||
return bytes.fromhex(match[2]).decode("utf-8"), iframe_src
|
||||
|
||||
|
||||
async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
|
||||
tasks = [
|
||||
network.request(
|
||||
urljoin(BASE_URL, f"categories/{sport}/"),
|
||||
log=log,
|
||||
)
|
||||
for sport in SPORT_ENDPOINTS
|
||||
]
|
||||
|
||||
results = await asyncio.gather(*tasks)
|
||||
|
||||
events = []
|
||||
|
||||
if not (soups := [HTMLParser(html.content) for html in results if html]):
|
||||
return events
|
||||
|
||||
for soup in soups:
|
||||
|
||||
sport = "Live Event"
|
||||
|
||||
if sport_header := soup.css_first("h1.text-3xl"):
|
||||
header = sport_header.text(strip=True)
|
||||
|
||||
sport = header.split("Streams")[0].strip()
|
||||
|
||||
for card in soup.css("article.game-card"):
|
||||
if not (team_elem := card.css_first("h2.text-xl.font-semibold")):
|
||||
continue
|
||||
|
||||
if not (link_elem := card.css_first("a.stream-button")) or not (
|
||||
href := link_elem.attributes.get("href")
|
||||
):
|
||||
continue
|
||||
|
||||
if (
|
||||
not (live_badge := card.css_first("span.bg-green-600"))
|
||||
or live_badge.text(strip=True) != "LIVE"
|
||||
):
|
||||
continue
|
||||
|
||||
event_name = team_elem.text(strip=True)
|
||||
|
||||
if f"[{sport}] {event_name} ({TAG})" in cached_keys:
|
||||
continue
|
||||
|
||||
events.append(
|
||||
{
|
||||
"sport": sport,
|
||||
"event": event_name,
|
||||
"link": 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(f'Scraping from "{BASE_URL}"')
|
||||
|
||||
events = await get_events(cached_urls.keys())
|
||||
|
||||
log.info(f"Processing {len(events)} new URL(s)")
|
||||
|
||||
if events:
|
||||
now = Time.clean(Time.now())
|
||||
|
||||
for i, ev in enumerate(events, start=1):
|
||||
handler = partial(
|
||||
process_event,
|
||||
url=ev["link"],
|
||||
url_num=i,
|
||||
)
|
||||
|
||||
url, iframe = await network.safe_process(
|
||||
handler,
|
||||
url_num=i,
|
||||
semaphore=network.HTTP_S,
|
||||
log=log,
|
||||
)
|
||||
|
||||
sport, event, link = (
|
||||
ev["sport"],
|
||||
ev["event"],
|
||||
ev["link"],
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
if new_count := valid_count - cached_count:
|
||||
log.info(f"Collected and cached {new_count} new event(s)")
|
||||
|
||||
else:
|
||||
log.info("No new events found")
|
||||
|
||||
CACHE_FILE.write(cached_urls)
|
||||
18
readme.md
18
readme.md
|
|
@ -1,18 +1,18 @@
|
|||
## Base Log @ 2026-01-25 20:43 UTC
|
||||
## Base Log @ 2026-01-27 03:57 UTC
|
||||
|
||||
### ✅ Working Streams: 136<br>❌ Dead Streams: 9
|
||||
|
||||
| Channel | Error (Code) | Link |
|
||||
| ------- | ------------ | ---- |
|
||||
| BBC World News | HTTP Error (404) | `http://fl1.moveonjoy.com/BBC_WORLD_NEWS/index.m3u8` |
|
||||
| Boomerang | HTTP Error (404) | `http://fl1.moveonjoy.com/BOOMERANG/index.m3u8` |
|
||||
| Disney XD | HTTP Error (404) | `http://fl1.moveonjoy.com/DISNEY_XD/index.m3u8` |
|
||||
| FDSN Florida | HTTP Error (502) | `http://mytvstream.net:8080/live/A1Jay5/362586/46794.m3u8` |
|
||||
| FDSN Southeast | HTTP Error (502) | `http://mytvstream.net:8080/live/A1Jay5/362586/2213.m3u8` |
|
||||
| NBC Sports Bay Area | HTTP Error (502) | `http://hardcoremedia.xyz:80/NW3Vk7xXwW/8375773282/257216` |
|
||||
| NFL RedZone | HTTP Error (502) | `http://hardcoremedia.xyz:80/NW3Vk7xXwW/8375773282/249239` |
|
||||
| Premier Sports 1 | HTTP Error (502) | `http://hardcoremedia.xyz:80/NW3Vk7xXwW/8375773282/117037` |
|
||||
| Premier Sports 2 | HTTP Error (502) | `http://hardcoremedia.xyz:80/NW3Vk7xXwW/8375773282/117038` |
|
||||
| FDSN Southeast | HTTP Error (403) | `http://mytvstream.net:8080/live/A1Jay5/362586/2213.m3u8` |
|
||||
| FDSN Southwest | HTTP Error (403) | `http://mytvstream.net:8080/live/A1Jay5/362586/21843.m3u8` |
|
||||
| FXX | HTTP Error (404) | `https://fl1.moveonjoy.com/FXX/index.m3u8` |
|
||||
| Lifetime Movie Network | HTTP Error (404) | `https://fl1.moveonjoy.com/LIFETIME_MOVIE_NETWORK/index.m3u8` |
|
||||
| NBC Sports Bay Area | Unknown status (302) | `http://hardcoremedia.xyz:80/NW3Vk7xXwW/8375773282/257216` |
|
||||
| Paramount Network | HTTP Error (404) | `https://fl1.moveonjoy.com/PARAMOUNT_NETWORK/index.m3u8` |
|
||||
| Premier Sports 2 | Unknown status (302) | `http://hardcoremedia.xyz:80/NW3Vk7xXwW/8375773282/117038` |
|
||||
| Sportsnet One | HTTP Error (403) | `http://mytvstream.net:8080/live/k4Svp2/645504/57297.m3u8` |
|
||||
---
|
||||
#### Base Channels URL
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue