stremio/apps/master-api/src/viewer/epg-parse.test.ts
Jos Vooges | STH 388962e6d1 Fix Live TV EPG by using bulk XMLTV instead of partial short_epg.
Category now/next titles were incomplete because warmup capped streams and per-channel fetches timed out; load xmltv.php once, fix timezone parsing, and fill remaining gaps in the background.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-05 16:10:46 +02:00

33 lines
1.1 KiB
TypeScript

import { decodeEpgText, epgToIso, parseAmsterdamLocalMs, parseXmltvTimeMs } from "../iptv/xtream";
import { parseNowNextPrograms } from "./iptv-client";
function assert(cond: unknown, msg: string) {
if (!cond) throw new Error(msg);
}
const startMs = parseXmltvTimeMs("20260905140000 +0200");
assert(startMs === Date.UTC(2026, 8, 5, 12, 0, 0), `offset parse got ${startMs}`);
const local = parseAmsterdamLocalMs("2026-09-05 14:00:00");
assert(local != null && Number.isFinite(local), "amsterdam local");
const iso = epgToIso(
{ title: "X", start: "2026-09-05 14:00:00", end: "2026-09-05 15:00:00" },
"start"
);
assert(iso != null, "epgToIso naive");
assert(decodeEpgText(Buffer.from("Hallo").toString("base64")).includes("Hallo"), "b64");
const listed = parseNowNextPrograms([
{
title: Buffer.from("Nu live").toString("base64"),
start: "2000-01-01 00:00:00",
end: "2100-01-01 00:00:00",
start_timestamp: Math.floor(Date.now() / 1000) - 60,
stop_timestamp: Math.floor(Date.now() / 1000) + 3600,
},
]);
assert(listed.now?.title === "Nu live", `now title=${listed.now?.title}`);
console.log("epg-parse tests ok");