mirror of
https://github.com/doms9/iptv.git
synced 2026-04-21 19:46:59 +02:00
update M3U8
This commit is contained in:
parent
b9ffecf2d1
commit
55c8b7cfd3
4 changed files with 1326 additions and 1386 deletions
1190
M3U8/TV.m3u8
1190
M3U8/TV.m3u8
File diff suppressed because it is too large
Load diff
1190
M3U8/events.m3u8
1190
M3U8/events.m3u8
File diff suppressed because it is too large
Load diff
|
|
@ -68,7 +68,7 @@ async def main() -> None:
|
||||||
asyncio.create_task(roxie.scrape(hdl_brwsr)),
|
asyncio.create_task(roxie.scrape(hdl_brwsr)),
|
||||||
asyncio.create_task(streamcenter.scrape(hdl_brwsr)),
|
asyncio.create_task(streamcenter.scrape(hdl_brwsr)),
|
||||||
# asyncio.create_task(streamhub.scrape(xtrnl_brwsr)),
|
# asyncio.create_task(streamhub.scrape(xtrnl_brwsr)),
|
||||||
asyncio.create_task(streamsgate.scrape(xtrnl_brwsr)),
|
# asyncio.create_task(streamsgate.scrape(xtrnl_brwsr)),
|
||||||
]
|
]
|
||||||
|
|
||||||
httpx_tasks = [
|
httpx_tasks = [
|
||||||
|
|
|
||||||
|
|
@ -1,165 +1,165 @@
|
||||||
import re
|
import re
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from playwright.async_api import Browser
|
from playwright.async_api import Browser
|
||||||
|
|
||||||
from .utils import Cache, Time, get_logger, leagues, network
|
from .utils import Cache, Time, get_logger, leagues, network
|
||||||
|
|
||||||
log = get_logger(__name__)
|
log = get_logger(__name__)
|
||||||
|
|
||||||
urls: dict[str, dict[str, str | float]] = {}
|
urls: dict[str, dict[str, str | float]] = {}
|
||||||
|
|
||||||
TAG = "PPV"
|
TAG = "PPV"
|
||||||
|
|
||||||
CACHE_FILE = Cache(TAG, exp=10_800)
|
CACHE_FILE = Cache(TAG, exp=10_800)
|
||||||
|
|
||||||
API_FILE = Cache(f"{TAG}-api", exp=19_800)
|
API_FILE = Cache(f"{TAG}-api", exp=19_800)
|
||||||
|
|
||||||
API_MIRRORS = [
|
API_MIRRORS = [
|
||||||
"https://api.ppv.to/api/streams",
|
"https://api.ppv.to/api/streams",
|
||||||
"https://api.ppv.cx/api/streams",
|
"https://api.ppv.cx/api/streams",
|
||||||
"https://api.ppv.sh/api/streams",
|
"https://api.ppv.sh/api/streams",
|
||||||
"https://api.ppv.la/api/streams",
|
"https://api.ppv.la/api/streams",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def fix_url(s: str) -> str:
|
def fix_url(s: str) -> str:
|
||||||
pattern = re.compile(r"index\.m3u8$", re.I)
|
pattern = re.compile(r"index\.m3u8$", re.I)
|
||||||
|
|
||||||
return pattern.sub(r"tracks-v1a1/mono.ts.m3u8", s)
|
return pattern.sub(r"tracks-v1a1/mono.ts.m3u8", s)
|
||||||
|
|
||||||
|
|
||||||
async def get_events(url: str, cached_keys: list[str]) -> list[dict[str, str]]:
|
async def get_events(url: str, cached_keys: list[str]) -> list[dict[str, str]]:
|
||||||
now = Time.clean(Time.now())
|
now = Time.clean(Time.now())
|
||||||
|
|
||||||
if not (api_data := API_FILE.load(per_entry=False)):
|
if not (api_data := API_FILE.load(per_entry=False)):
|
||||||
log.info("Refreshing API cache")
|
log.info("Refreshing API cache")
|
||||||
|
|
||||||
api_data = {"timestamp": now.timestamp()}
|
api_data = {"timestamp": now.timestamp()}
|
||||||
|
|
||||||
if r := await network.request(url, log=log):
|
if r := await network.request(url, log=log):
|
||||||
api_data: dict = r.json()
|
api_data: dict = r.json()
|
||||||
|
|
||||||
API_FILE.write(api_data)
|
API_FILE.write(api_data)
|
||||||
|
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
start_dt = now.delta(minutes=-30)
|
start_dt = now.delta(hours=-1)
|
||||||
end_dt = now.delta(minutes=30)
|
end_dt = now.delta(minutes=5)
|
||||||
|
|
||||||
for stream_group in api_data.get("streams", []):
|
for stream_group in api_data.get("streams", []):
|
||||||
sport = stream_group["category"]
|
sport = stream_group["category"]
|
||||||
|
|
||||||
if sport == "24/7 Streams":
|
if sport == "24/7 Streams":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for event in stream_group.get("streams", []):
|
for event in stream_group.get("streams", []):
|
||||||
name = event.get("name")
|
name = event.get("name")
|
||||||
|
|
||||||
start_ts = event.get("starts_at")
|
start_ts = event.get("starts_at")
|
||||||
|
|
||||||
logo = event.get("poster")
|
logo = event.get("poster")
|
||||||
|
|
||||||
iframe = event.get("iframe")
|
iframe = event.get("iframe")
|
||||||
|
|
||||||
if not (name and start_ts and iframe):
|
if not (name and start_ts and iframe):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if f"[{sport}] {name} ({TAG})" in cached_keys:
|
if f"[{sport}] {name} ({TAG})" in cached_keys:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
event_dt = Time.from_ts(start_ts)
|
event_dt = Time.from_ts(start_ts)
|
||||||
|
|
||||||
if not start_dt <= event_dt <= end_dt:
|
if not start_dt <= event_dt <= end_dt:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
events.append(
|
events.append(
|
||||||
{
|
{
|
||||||
"sport": sport,
|
"sport": sport,
|
||||||
"event": name,
|
"event": name,
|
||||||
"link": f"{iframe}#player=clappr#autoplay=true",
|
"link": f"{iframe}#player=clappr#autoplay=true",
|
||||||
"logo": logo,
|
"logo": logo,
|
||||||
"timestamp": event_dt.timestamp(),
|
"timestamp": event_dt.timestamp(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return events
|
return events
|
||||||
|
|
||||||
|
|
||||||
async def scrape(browser: Browser) -> 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"]}
|
||||||
|
|
||||||
valid_count = cached_count = len(valid_urls)
|
valid_count = cached_count = len(valid_urls)
|
||||||
|
|
||||||
urls.update(valid_urls)
|
urls.update(valid_urls)
|
||||||
|
|
||||||
log.info(f"Loaded {cached_count} event(s) from cache")
|
log.info(f"Loaded {cached_count} event(s) from cache")
|
||||||
|
|
||||||
if not (api_url := await network.get_base(API_MIRRORS)):
|
if not (api_url := await network.get_base(API_MIRRORS)):
|
||||||
log.warning("No working PPV mirrors")
|
log.warning("No working PPV mirrors")
|
||||||
|
|
||||||
CACHE_FILE.write(cached_urls)
|
CACHE_FILE.write(cached_urls)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
log.info(f'Scraping from "{api_url}"')
|
log.info(f'Scraping from "{api_url}"')
|
||||||
|
|
||||||
if events := await get_events(api_url, cached_urls.keys()):
|
if events := await get_events(api_url, cached_urls.keys()):
|
||||||
log.info(f"Processing {len(events)} new URL(s)")
|
log.info(f"Processing {len(events)} new URL(s)")
|
||||||
|
|
||||||
async with network.event_context(browser, stealth=False) as context:
|
async with network.event_context(browser, stealth=False) 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:
|
async with network.event_page(context) as page:
|
||||||
handler = partial(
|
handler = partial(
|
||||||
network.process_event,
|
network.process_event,
|
||||||
url=(link := ev["link"]),
|
url=(link := ev["link"]),
|
||||||
url_num=i,
|
url_num=i,
|
||||||
page=page,
|
page=page,
|
||||||
timeout=6,
|
timeout=6,
|
||||||
log=log,
|
log=log,
|
||||||
)
|
)
|
||||||
|
|
||||||
url = await network.safe_process(
|
url = await network.safe_process(
|
||||||
handler,
|
handler,
|
||||||
url_num=i,
|
url_num=i,
|
||||||
semaphore=network.PW_S,
|
semaphore=network.PW_S,
|
||||||
log=log,
|
log=log,
|
||||||
)
|
)
|
||||||
|
|
||||||
sport, event, logo, ts = (
|
sport, event, logo, ts = (
|
||||||
ev["sport"],
|
ev["sport"],
|
||||||
ev["event"],
|
ev["event"],
|
||||||
ev["logo"],
|
ev["logo"],
|
||||||
ev["timestamp"],
|
ev["timestamp"],
|
||||||
)
|
)
|
||||||
|
|
||||||
key = f"[{sport}] {event} ({TAG})"
|
key = f"[{sport}] {event} ({TAG})"
|
||||||
|
|
||||||
tvg_id, pic = leagues.get_tvg_info(sport, event)
|
tvg_id, pic = leagues.get_tvg_info(sport, event)
|
||||||
|
|
||||||
entry = {
|
entry = {
|
||||||
"url": url,
|
"url": url,
|
||||||
"logo": logo or pic,
|
"logo": logo or pic,
|
||||||
"base": link,
|
"base": link,
|
||||||
"timestamp": ts,
|
"timestamp": ts,
|
||||||
"id": tvg_id or "Live.Event.us",
|
"id": tvg_id or "Live.Event.us",
|
||||||
"link": link,
|
"link": link,
|
||||||
}
|
}
|
||||||
|
|
||||||
cached_urls[key] = entry
|
cached_urls[key] = entry
|
||||||
|
|
||||||
if url:
|
if url:
|
||||||
valid_count += 1
|
valid_count += 1
|
||||||
|
|
||||||
entry["url"] = fix_url(url)
|
entry["url"] = fix_url(url)
|
||||||
|
|
||||||
urls[key] = entry
|
urls[key] = entry
|
||||||
|
|
||||||
log.info(f"Collected and cached {valid_count - cached_count} new event(s)")
|
log.info(f"Collected and cached {valid_count - cached_count} new event(s)")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.info("No new events found")
|
log.info("No new events found")
|
||||||
|
|
||||||
CACHE_FILE.write(cached_urls)
|
CACHE_FILE.write(cached_urls)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue