This commit is contained in:
Dongho Kim
2026-06-22 15:43:04 +02:00
parent 5e45cde568
commit b2b5a40606
+29 -15
View File
@@ -159,26 +159,33 @@ app.get('/epg.xml', async (req, res) => {
xml += ` </channel>\n`; xml += ` </channel>\n`;
}); });
// Programme entries for live channels // Programme entries live channels show stream info, offline show "Off Air"
const now = new Date();
const pad = n => String(n).padStart(2, '0');
const toXmltvDate = (d) =>
`${d.getFullYear()}${pad(d.getMonth()+1)}${pad(d.getDate())}${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())} +0000`;
// Start of today (UTC) and end of today for Off Air block
const dayStart = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
const dayEnd = new Date(dayStart.getTime() + 24 * 60 * 60 * 1000);
results.forEach(r => { results.forEach(r => {
if (r.status !== 'fulfilled') return; if (r.status !== 'fulfilled') return;
const { ch, content } = r.value; const { ch, content } = r.value;
if (!content || content.status !== 'OPEN') return; const isLive = content && content.status === 'OPEN';
const openDate = content.openDate if (isLive) {
? content.openDate.replace(/[-: ]/g, '').substring(0, 14) + ' +0900' const openDate = content.openDate
: null; ? content.openDate.replace(/[-: ]/g, '').substring(0, 14) + ' +0900'
// Assume a 6-hour window for the programme end (no real end time available) : toXmltvDate(now);
const endDate = content.openDate const endDate = content.openDate
? (() => { ? (() => {
const d = new Date(content.openDate); const d = new Date(content.openDate);
d.setHours(d.getHours() + 6); d.setHours(d.getHours() + 6);
const pad = n => String(n).padStart(2, '0'); return `${d.getFullYear()}${pad(d.getMonth()+1)}${pad(d.getDate())}${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())} +0900`;
return `${d.getFullYear()}${pad(d.getMonth()+1)}${pad(d.getDate())}${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())} +0900`; })()
})() : toXmltvDate(dayEnd);
: null;
if (openDate && endDate) {
xml += ` <programme start="${openDate}" stop="${endDate}" channel="${escapeXml(ch.id)}">\n`; xml += ` <programme start="${openDate}" stop="${endDate}" channel="${escapeXml(ch.id)}">\n`;
xml += ` <title>${escapeXml(content.liveTitle || ch.name)}</title>\n`; xml += ` <title>${escapeXml(content.liveTitle || ch.name)}</title>\n`;
if (content.liveCategoryValue || content.liveCategory) { if (content.liveCategoryValue || content.liveCategory) {
@@ -188,9 +195,16 @@ app.get('/epg.xml', async (req, res) => {
xml += ` <icon src="${escapeXml(content.liveImageUrl)}" />\n`; xml += ` <icon src="${escapeXml(content.liveImageUrl)}" />\n`;
} }
xml += ` </programme>\n`; xml += ` </programme>\n`;
} else {
// Offline — fill today with an "Off Air" block
xml += ` <programme start="${toXmltvDate(dayStart)}" stop="${toXmltvDate(dayEnd)}" channel="${escapeXml(ch.id)}">\n`;
xml += ` <title>Off Air</title>\n`;
xml += ` <desc>${escapeXml(ch.name)} is not currently live.</desc>\n`;
xml += ` </programme>\n`;
} }
}); });
xml += '</tv>\n'; xml += '</tv>\n';
res.header('Content-Type', 'application/xml'); res.header('Content-Type', 'application/xml');
res.send(xml); res.send(xml);