72 lines
2 KiB
Python
72 lines
2 KiB
Python
#!/usr/bin/env python3
|
|
import asyncio
|
|
from pathlib import Path
|
|
|
|
from scrapers import fstv, livetvsx, ppv, streambtw, streameast, streamed, tvpass
|
|
from scrapers.utils import get_logger, network
|
|
|
|
log = get_logger(__name__)
|
|
|
|
BASE_FILE = Path(__file__).parent / "base.m3u8"
|
|
|
|
M3U8_FILE = Path(__file__).parent / "TV.m3u8"
|
|
|
|
|
|
def load_base() -> tuple[list[str], int]:
|
|
log.info("Fetching base M3U8")
|
|
|
|
data = BASE_FILE.read_text(encoding="utf-8")
|
|
|
|
last_chnl_num = int(data.split("tvg-chno=")[-1].split('"')[1])
|
|
|
|
return data.splitlines(), last_chnl_num
|
|
|
|
|
|
async def main() -> None:
|
|
base_m3u8, tvg_chno = load_base()
|
|
|
|
tasks = [
|
|
asyncio.create_task(fstv.scrape(network.client)),
|
|
# asyncio.create_task(livetvsx.scrape(network.client)),
|
|
asyncio.create_task(ppv.scrape(network.client)),
|
|
asyncio.create_task(streambtw.scrape(network.client)),
|
|
asyncio.create_task(streameast.scrape(network.client)),
|
|
asyncio.create_task(streamed.scrape(network.client)),
|
|
asyncio.create_task(tvpass.scrape(network.client)),
|
|
]
|
|
|
|
await asyncio.gather(*tasks, return_exceptions=True)
|
|
|
|
additions = (
|
|
fstv.urls
|
|
| livetvsx.urls
|
|
| ppv.urls
|
|
| streambtw.urls
|
|
| streameast.urls
|
|
| streamed.urls
|
|
| tvpass.urls
|
|
)
|
|
|
|
live_events = []
|
|
|
|
for chnl_num, (event, info) in enumerate(
|
|
sorted(additions.items()),
|
|
start=tvg_chno + 1,
|
|
):
|
|
live_events.extend(
|
|
(
|
|
f'\n#EXTINF:-1 tvg-chno="{chnl_num}" tvg-id="{info["id"]}" tvg-name="{event}" tvg-logo="{info["logo"]}" group-title="Live Events",{event}',
|
|
f'#EXTVLCOPT:http-referrer={info["base"]}',
|
|
f'#EXTVLCOPT:http-origin={info["base"]}',
|
|
f"#EXTVLCOPT:http-user-agent={network.UA}",
|
|
info["url"],
|
|
)
|
|
)
|
|
|
|
M3U8_FILE.write_text("\n".join(base_m3u8 + live_events), encoding="utf-8")
|
|
|
|
log.info(f"M3U8 saved to {M3U8_FILE.name}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|