This commit is contained in:
doms9 2025-09-17 23:52:37 -04:00
parent eb51119f78
commit 00000d9cc3
5 changed files with 220 additions and 36 deletions

View file

@ -2,39 +2,29 @@
import asyncio
from pathlib import Path
import httpx
from scrapers import fstv, livetvsx, ppv, streambtw, streameast, tvpass
from scrapers.utils import UA, get_logger
from scrapers.utils import CLIENT, UA, get_logger
log = get_logger(__name__)
BASE_URL = "https://s.id/ePwXT"
BASE_FILE = Path(__file__).parent / "Base.m3u8"
M3U8_FILE = Path(__file__).parent / "TV.m3u8"
CLIENT = httpx.AsyncClient(
timeout=5,
follow_redirects=True,
headers={"User-Agent": UA},
)
async def vanilla_fetch() -> tuple[list[str], int]:
def vanilla_fetch() -> tuple[list[str], int]:
log.info("Fetching base M3U8")
try:
r = await CLIENT.get(BASE_URL)
r.raise_for_status()
except Exception as e:
log.error(f'Failed to fetch "{BASE_URL}"\n{e}')
raise SystemExit(e) from e
data = BASE_FILE.read_text(encoding="utf-8")
last_chnl_num = int(r.text.split("tvg-chno=")[-1].split('"')[1])
last_chnl_num = int(data.split("tvg-chno=")[-1].split('"')[1])
return r.text.splitlines()[1:], last_chnl_num
return data.splitlines(), last_chnl_num
async def main() -> None:
base_m3u8, tvg_chno = vanilla_fetch()
tasks = [
asyncio.create_task(fstv.main(CLIENT)),
asyncio.create_task(livetvsx.main(CLIENT)),
@ -42,12 +32,9 @@ async def main() -> None:
asyncio.create_task(streambtw.main(CLIENT)),
asyncio.create_task(streameast.main(CLIENT)),
asyncio.create_task(tvpass.main(CLIENT)),
vanilla_fetch(),
]
results = await asyncio.gather(*tasks)
base_m3u8, tvg_chno = results[-1]
await asyncio.gather(*tasks)
additions = (
fstv.urls
@ -74,15 +61,7 @@ async def main() -> None:
)
)
m3u8_content = "\n".join(
[
'#EXTM3U url-tvg="https://raw.githubusercontent.com/doms9/iptv/refs/heads/default/EPG/TV.xml"\n'
]
+ base_m3u8
+ live_events
)
M3U8_FILE.write_text(m3u8_content, encoding="utf-8")
M3U8_FILE.write_text("\n".join(base_m3u8 + live_events), encoding="utf-8")
log.info(f"M3U8 saved to {M3U8_FILE.name}")