#!/usr/bin/env bun // One tool (Bun), end to end: build playlist -> bind EPG ids -> grab guide.xml. // Uses Bun Shell ($). Clones of iptv-org/iptv & iptv-org/epg + node_modules all // live in /tmp (throwaway — nothing but the served files lands in the repo). // // bun refresh.ts # full refresh (playlist + EPG) // bun refresh.ts --revalidate # also re-probe every stream from scratch import { $ } from 'bun'; import { existsSync } from 'node:fs'; const HERE = import.meta.dir; const TMP = '/tmp/iptv-org-build'; const EPG = `${TMP}/epg`; const args = process.argv.slice(2); console.log('==> 1/3 build playlist (validate streams)'); await $`bun ${HERE}/build-iptv.mjs ${args}`; console.log('==> 2/3 bind EPG ids + write channels.xml'); if (!existsSync(`${EPG}/.git`)) await $`git clone --depth 1 https://github.com/iptv-org/epg.git ${EPG}`; await $`bun ${HERE}/make-epg.mjs`; console.log('==> 3/3 grab guide.xml'); if (!existsSync(`${EPG}/node_modules`)) { await $`bun install`.cwd(EPG); // run epg's postinstall ourselves — it fetches the iptv-org API data the // grabber needs (bun install doesn't run that lifecycle hook for us). await $`bun run scripts/commands/api/load.ts`.cwd(EPG); } await $`bun ${HERE}/grab-epg.ts`; // batched grab (bounded memory) -> guide.xml console.log(`==> done: ${HERE}/iptv.m3u + ${HERE}/guide.xml`);