iptv/M3U8/fetch.py

161 lines
4 KiB
Python
Raw Normal View History

2025-12-08 13:21:43 -05:00
#!/usr/bin/env python3
import asyncio
import re
from pathlib import Path
from scrapers import (
2025-12-25 12:14:29 -05:00
cdnlivetv,
2025-12-22 18:26:47 -05:00
embedhd,
2025-12-08 13:21:43 -05:00
fawa,
2025-12-17 20:57:35 -05:00
istreameast,
pawa,
2025-12-08 13:21:43 -05:00
pixel,
ppv,
roxie,
shark,
sport9,
2025-12-22 19:59:39 -05:00
streambtw,
2025-12-08 13:21:43 -05:00
streamcenter,
streamfree,
2025-12-13 16:57:14 -05:00
streamhub,
2025-12-08 13:21:43 -05:00
streamsgate,
strmd,
2025-12-24 01:54:02 -05:00
totalsportek,
2025-12-08 13:21:43 -05:00
tvpass,
2025-12-22 17:08:41 -05:00
watchfooty,
2025-12-08 13:21:43 -05:00
webcast,
)
from scrapers.utils import get_logger, network
log = get_logger(__name__)
BASE_FILE = Path(__file__).parent / "base.m3u8"
EVENTS_FILE = Path(__file__).parent / "events.m3u8"
COMBINED_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")
pattern = re.compile(r'tvg-chno="(\d+)"')
last_chnl_num = max(map(int, pattern.findall(data)), default=0)
return data.splitlines(), last_chnl_num
async def main() -> None:
2026-01-06 18:24:02 -05:00
log.info(f"{'=' * 10} Scraper Started {'=' * 10}")
2025-12-08 13:21:43 -05:00
base_m3u8, tvg_chno = load_base()
tasks = [
2025-12-27 08:03:19 -05:00
asyncio.create_task(cdnlivetv.scrape()),
2025-12-22 18:26:47 -05:00
asyncio.create_task(embedhd.scrape()),
2025-12-18 03:04:11 -05:00
asyncio.create_task(fawa.scrape()),
asyncio.create_task(istreameast.scrape()),
asyncio.create_task(pawa.scrape()),
2025-12-25 01:45:49 -05:00
asyncio.create_task(pixel.scrape()),
2025-12-18 03:04:11 -05:00
asyncio.create_task(ppv.scrape()),
asyncio.create_task(roxie.scrape()),
asyncio.create_task(shark.scrape()),
asyncio.create_task(sport9.scrape()),
2026-01-07 15:31:23 -05:00
asyncio.create_task(streambtw.scrape()),
2025-12-18 03:04:11 -05:00
asyncio.create_task(streamcenter.scrape()),
asyncio.create_task(streamfree.scrape()),
2025-12-22 13:00:54 -05:00
asyncio.create_task(streamhub.scrape()),
2025-12-18 03:04:11 -05:00
asyncio.create_task(streamsgate.scrape()),
asyncio.create_task(strmd.scrape()),
2026-01-08 09:02:28 -05:00
# asyncio.create_task(totalsportek.scrape()),
2025-12-18 03:04:11 -05:00
asyncio.create_task(tvpass.scrape()),
asyncio.create_task(webcast.scrape()),
2025-12-08 13:21:43 -05:00
]
await asyncio.gather(*tasks)
2025-12-23 13:28:56 -05:00
await watchfooty.scrape()
2025-12-08 13:21:43 -05:00
additions = (
2025-12-25 12:14:29 -05:00
cdnlivetv.urls
| embedhd.urls
2025-12-22 18:26:47 -05:00
| fawa.urls
2025-12-17 20:57:35 -05:00
| istreameast.urls
| pawa.urls
2025-12-08 13:21:43 -05:00
| pixel.urls
| ppv.urls
| roxie.urls
| shark.urls
| sport9.urls
2025-12-22 19:59:39 -05:00
| streambtw.urls
2025-12-08 13:21:43 -05:00
| streamcenter.urls
| streamfree.urls
2025-12-13 16:57:14 -05:00
| streamhub.urls
2025-12-08 13:21:43 -05:00
| streamsgate.urls
2025-12-24 01:54:02 -05:00
| strmd.urls
| totalsportek.urls
2025-12-08 13:21:43 -05:00
| tvpass.urls
2025-12-22 17:08:41 -05:00
| watchfooty.urls
2025-12-08 13:21:43 -05:00
| webcast.urls
)
live_events: list[str] = []
combined_channels: list[str] = []
for i, (event, info) in enumerate(
sorted(additions.items()),
start=1,
):
extinf_all = (
f'#EXTINF:-1 tvg-chno="{tvg_chno + i}" tvg-id="{info["id"]}" '
f'tvg-name="{event}" tvg-logo="{info["logo"]}" group-title="Live Events",{event}'
)
extinf_live = (
f'#EXTINF:-1 tvg-chno="{i}" tvg-id="{info["id"]}" '
f'tvg-name="{event}" tvg-logo="{info["logo"]}" group-title="Live Events",{event}'
)
vlc_block = [
f'#EXTVLCOPT:http-referrer={info["base"]}',
f'#EXTVLCOPT:http-origin={info["base"]}',
f"#EXTVLCOPT:http-user-agent={network.UA}",
info["url"],
]
combined_channels.extend(["\n" + extinf_all, *vlc_block])
live_events.extend(["\n" + extinf_live, *vlc_block])
COMBINED_FILE.write_text(
"\n".join(base_m3u8 + combined_channels),
encoding="utf-8",
)
log.info(f"Base + Events saved to {COMBINED_FILE.resolve()}")
EVENTS_FILE.write_text(
'#EXTM3U url-tvg="https://raw.githubusercontent.com/doms9/iptv/refs/heads/default/EPG/TV.xml"\n'
+ "\n".join(live_events),
encoding="utf-8",
)
log.info(f"Events saved to {EVENTS_FILE.resolve()}")
2026-01-06 18:24:02 -05:00
for hndlr in log.handlers:
hndlr.flush()
hndlr.stream.write("\n")
2025-12-08 13:21:43 -05:00
if __name__ == "__main__":
asyncio.run(main())
try:
asyncio.run(network.client.aclose())
except Exception:
pass