Added xml.gx support for EPG

This commit is contained in:
Trevor Mears
2025-12-27 23:22:37 -08:00
parent 6a1d5b44e9
commit 79d84aa64b
+20 -1
View File
@@ -5,8 +5,10 @@
const { parseString } = require('xml2js');
const { promisify } = require('util');
const zlib = require('zlib');
const parseXml = promisify(parseString);
const gunzip = promisify(zlib.gunzip);
/**
* Parse XMLTV date format (YYYYMMDDHHmmss +ZZZZ)
@@ -164,7 +166,24 @@ async function fetchAndParse(url) {
if (!response.ok) {
throw new Error(`Failed to fetch EPG: ${response.status} ${response.statusText}`);
}
const content = await response.text();
let content;
const contentEncoding = response.headers.get('content-encoding');
const isGzipped = url.endsWith('.gz') || contentEncoding === 'gzip';
if (isGzipped) {
// Handle gzipped EPG files (.xml.gz)
const buffer = await response.arrayBuffer();
try {
const decompressed = await gunzip(Buffer.from(buffer));
content = decompressed.toString('utf-8');
} catch (err) {
throw new Error(`Failed to decompress gzipped EPG: ${err.message}`);
}
} else {
content = await response.text();
}
return parse(content);
}