Update epg-grabber.js

This commit is contained in:
Aleksandr Statciuk 2023-05-11 04:12:49 +03:00
parent 0a83492b76
commit 19d206c11c
1 changed files with 56 additions and 38 deletions

View File

@ -68,8 +68,24 @@ async function main() {
const grabber = new EPGGrabber(config)
const channelsXML = file.read(config.channels)
const { channels } = parseChannels(channelsXML)
const { channels: parsedChannels } = parseChannels(channelsXML)
let template = options.output || config.output
const variables = file.templateVariables(template)
const groups = _.groupBy(parsedChannels, channel => {
let groupId = ''
for (let key in channel) {
if (variables.includes(key)) {
groupId += channel[key]
}
}
return groupId
})
for (let groupId in groups) {
const channels = groups[groupId]
let programs = []
let i = 1
let days = config.days || 1
@ -103,7 +119,7 @@ async function main() {
programs = _.uniqBy(programs, p => p.start + p.channel)
const xml = generateXMLTV({ channels, programs })
let outputPath = options.output || config.output
let outputPath = file.templateFormat(template, channels[0])
if (options.gzip) {
outputPath = outputPath || 'guide.xml.gz'
const compressed = await gzip(xml)
@ -114,6 +130,8 @@ async function main() {
}
logger.info(`File '${outputPath}' successfully saved`)
}
logger.info('Finish')
}