mirror of
https://github.com/doms9/iptv.git
synced 2026-04-22 19:57:00 +02:00
e
- edit scraping method for webcast.py - edit domain for totalsportek.py
This commit is contained in:
parent
3deb6a3f17
commit
00000d922b
3 changed files with 35 additions and 72 deletions
|
|
@ -67,6 +67,7 @@ async def main() -> None:
|
||||||
# asyncio.create_task(fsports.scrape(xtrnl_brwsr)),
|
# asyncio.create_task(fsports.scrape(xtrnl_brwsr)),
|
||||||
asyncio.create_task(ppv.scrape(xtrnl_brwsr)),
|
asyncio.create_task(ppv.scrape(xtrnl_brwsr)),
|
||||||
asyncio.create_task(roxie.scrape(hdl_brwsr)),
|
asyncio.create_task(roxie.scrape(hdl_brwsr)),
|
||||||
|
asyncio.create_task(webcast.scrape(hdl_brwsr)),
|
||||||
]
|
]
|
||||||
|
|
||||||
httpx_tasks = [
|
httpx_tasks = [
|
||||||
|
|
@ -83,7 +84,6 @@ async def main() -> None:
|
||||||
asyncio.create_task(streamtpnew.scrape()),
|
asyncio.create_task(streamtpnew.scrape()),
|
||||||
# asyncio.create_task(totalsportek.scrape()),
|
# asyncio.create_task(totalsportek.scrape()),
|
||||||
asyncio.create_task(tvapp.scrape()),
|
asyncio.create_task(tvapp.scrape()),
|
||||||
asyncio.create_task(webcast.scrape()),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
await asyncio.gather(*(pw_tasks + httpx_tasks))
|
await asyncio.gather(*(pw_tasks + httpx_tasks))
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ TAG = "TOTALSPRTK"
|
||||||
|
|
||||||
CACHE_FILE = Cache(TAG, exp=28_800)
|
CACHE_FILE = Cache(TAG, exp=28_800)
|
||||||
|
|
||||||
BASE_URL = "https://live3.totalsportek.foo"
|
BASE_URL = "https://live3.totalsportek.fyi"
|
||||||
|
|
||||||
|
|
||||||
def fix_txt(s: str) -> str:
|
def fix_txt(s: str) -> str:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import re
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
from playwright.async_api import Browser
|
||||||
from selectolax.parser import HTMLParser
|
from selectolax.parser import HTMLParser
|
||||||
|
|
||||||
from .utils import Cache, Time, get_logger, leagues, network
|
from .utils import Cache, Time, get_logger, leagues, network
|
||||||
|
|
@ -25,47 +25,6 @@ def fix_event(s: str) -> str:
|
||||||
return " vs ".join(s.split("@"))
|
return " vs ".join(s.split("@"))
|
||||||
|
|
||||||
|
|
||||||
async def process_event(url: str, url_num: int) -> str | None:
|
|
||||||
if not (event_data := await network.request(url, log=log)):
|
|
||||||
log.warning(f"URL {url_num}) Failed to load url.")
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
soup = HTMLParser(event_data.content)
|
|
||||||
|
|
||||||
if not (iframe := soup.css_first('iframe[name="srcFrame"]')):
|
|
||||||
log.warning(f"URL {url_num}) No iframe element found.")
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
if not (iframe_src := iframe.attributes.get("src")):
|
|
||||||
log.warning(f"URL {url_num}) No iframe source found.")
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
if not (
|
|
||||||
iframe_src_data := await network.request(
|
|
||||||
iframe_src,
|
|
||||||
headers={"Referer": url},
|
|
||||||
log=log,
|
|
||||||
)
|
|
||||||
):
|
|
||||||
log.warning(f"URL {url_num}) Failed to load iframe source.")
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
pattern = re.compile(r"(source:|streamUrl\s+=)\s+(\'|\")(.*)(\'|\")", re.I)
|
|
||||||
|
|
||||||
if not (match := pattern.search(iframe_src_data.text)):
|
|
||||||
log.warning(f"URL {url_num}) No Clappr source found.")
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
log.info(f"URL {url_num}) Captured M3U8")
|
|
||||||
|
|
||||||
return match[3]
|
|
||||||
|
|
||||||
|
|
||||||
async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
|
async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
|
||||||
tasks = [network.request(url, log=log) for url in BASE_URLS.values()]
|
tasks = [network.request(url, log=log) for url in BASE_URLS.values()]
|
||||||
|
|
||||||
|
|
@ -111,7 +70,7 @@ async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
|
||||||
return events
|
return events
|
||||||
|
|
||||||
|
|
||||||
async def scrape() -> None:
|
async def scrape(browser: Browser) -> None:
|
||||||
cached_urls = CACHE_FILE.load()
|
cached_urls = CACHE_FILE.load()
|
||||||
|
|
||||||
valid_urls = {k: v for k, v in cached_urls.items() if v["url"]}
|
valid_urls = {k: v for k, v in cached_urls.items() if v["url"]}
|
||||||
|
|
@ -129,11 +88,15 @@ async def scrape() -> None:
|
||||||
|
|
||||||
now = Time.clean(Time.now())
|
now = Time.clean(Time.now())
|
||||||
|
|
||||||
|
async with network.event_context(browser) as context:
|
||||||
for i, ev in enumerate(events, start=1):
|
for i, ev in enumerate(events, start=1):
|
||||||
|
async with network.event_page(context) as page:
|
||||||
handler = partial(
|
handler = partial(
|
||||||
process_event,
|
network.process_event,
|
||||||
url=(link := ev["link"]),
|
url=(link := ev["link"]),
|
||||||
url_num=i,
|
url_num=i,
|
||||||
|
page=page,
|
||||||
|
log=log,
|
||||||
)
|
)
|
||||||
|
|
||||||
url = await network.safe_process(
|
url = await network.safe_process(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue