From f20a7bf1911c4ac9d73fa35d2a9b421ca9f0e324 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Sun, 9 Jul 2023 16:31:00 +0300 Subject: [PATCH] Update epg-grabber.js --- bin/epg-grabber.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/bin/epg-grabber.js b/bin/epg-grabber.js index 831f3f3..684ea85 100755 --- a/bin/epg-grabber.js +++ b/bin/epg-grabber.js @@ -65,18 +65,31 @@ async function main() { if (options.timeout) config.request.timeout = options.timeout if (options.cacheTtl) config.request.cache.ttl = options.cacheTtl + if (options.channels) config.channels = options.channels - else if (config.channels) - config.channels = file.join(file.dirname(options.config), config.channels) - else throw new Error("The required 'channels' property is missing") - if (!config.channels) return logger.error('Path to [site].channels.xml is missing') - logger.info(`Loading '${config.channels}'...`) + let parsedChannels = [] + if (config.channels) { + let files = [] + if (Array.isArray(config.channels)) { + files = config.channels + } else if (typeof config.channels === 'string') { + files = await file.list(config.channels) + } else { + throw new Error('The "channels" attribute must be of type array or string') + } + + const dir = file.dirname(options.config) + for (let filepath of files) { + logger.info(`Loading '${filepath}'...`) + const channelsXML = file.read(filepath) + const { channels } = parseChannels(channelsXML) + parsedChannels = parsedChannels.concat(channels) + } + } else throw new Error('Path to [site].channels.xml is missing') + const grabber = new EPGGrabber(config) - const channelsXML = file.read(config.channels) - const { channels: parsedChannels } = parseChannels(channelsXML) - let template = options.output || config.output const variables = file.templateVariables(template)