refresh.ts 1.3 KB

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