Update epg-grabber.js
This commit is contained in:
parent
0a83492b76
commit
19d206c11c
|
@ -68,52 +68,70 @@ async function main() {
|
||||||
const grabber = new EPGGrabber(config)
|
const grabber = new EPGGrabber(config)
|
||||||
|
|
||||||
const channelsXML = file.read(config.channels)
|
const channelsXML = file.read(config.channels)
|
||||||
const { channels } = parseChannels(channelsXML)
|
const { channels: parsedChannels } = parseChannels(channelsXML)
|
||||||
|
|
||||||
let programs = []
|
let template = options.output || config.output
|
||||||
let i = 1
|
const variables = file.templateVariables(template)
|
||||||
let days = config.days || 1
|
|
||||||
const total = channels.length * days
|
const groups = _.groupBy(parsedChannels, channel => {
|
||||||
const utcDate = getUTCDate()
|
let groupId = ''
|
||||||
const dates = Array.from({ length: days }, (_, i) => utcDate.add(i, 'd'))
|
for (let key in channel) {
|
||||||
for (let channel of channels) {
|
if (variables.includes(key)) {
|
||||||
if (!channel.logo && config.logo) {
|
groupId += channel[key]
|
||||||
channel.logo = await grabber.loadLogo(channel)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let date of dates) {
|
return groupId
|
||||||
await grabber
|
})
|
||||||
.grab(channel, date, (data, err) => {
|
|
||||||
logger.info(
|
|
||||||
`[${i}/${total}] ${config.site} - ${data.channel.id} - ${dayjs
|
|
||||||
.utc(data.date)
|
|
||||||
.format('MMM D, YYYY')} (${data.programs.length} programs)`
|
|
||||||
)
|
|
||||||
|
|
||||||
if (err) logger.error(err.message)
|
for (let groupId in groups) {
|
||||||
|
const channels = groups[groupId]
|
||||||
|
let programs = []
|
||||||
|
let i = 1
|
||||||
|
let days = config.days || 1
|
||||||
|
const total = channels.length * days
|
||||||
|
const utcDate = getUTCDate()
|
||||||
|
const dates = Array.from({ length: days }, (_, i) => utcDate.add(i, 'd'))
|
||||||
|
for (let channel of channels) {
|
||||||
|
if (!channel.logo && config.logo) {
|
||||||
|
channel.logo = await grabber.loadLogo(channel)
|
||||||
|
}
|
||||||
|
|
||||||
if (i < total) i++
|
for (let date of dates) {
|
||||||
})
|
await grabber
|
||||||
.then(results => {
|
.grab(channel, date, (data, err) => {
|
||||||
programs = programs.concat(results)
|
logger.info(
|
||||||
})
|
`[${i}/${total}] ${config.site} - ${data.channel.id} - ${dayjs
|
||||||
|
.utc(data.date)
|
||||||
|
.format('MMM D, YYYY')} (${data.programs.length} programs)`
|
||||||
|
)
|
||||||
|
|
||||||
|
if (err) logger.error(err.message)
|
||||||
|
|
||||||
|
if (i < total) i++
|
||||||
|
})
|
||||||
|
.then(results => {
|
||||||
|
programs = programs.concat(results)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
programs = _.uniqBy(programs, p => p.start + p.channel)
|
||||||
|
|
||||||
|
const xml = generateXMLTV({ channels, programs })
|
||||||
|
let outputPath = file.templateFormat(template, channels[0])
|
||||||
|
if (options.gzip) {
|
||||||
|
outputPath = outputPath || 'guide.xml.gz'
|
||||||
|
const compressed = await gzip(xml)
|
||||||
|
file.write(outputPath, compressed)
|
||||||
|
} else {
|
||||||
|
outputPath = outputPath || 'guide.xml'
|
||||||
|
file.write(outputPath, xml)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(`File '${outputPath}' successfully saved`)
|
||||||
}
|
}
|
||||||
|
|
||||||
programs = _.uniqBy(programs, p => p.start + p.channel)
|
|
||||||
|
|
||||||
const xml = generateXMLTV({ channels, programs })
|
|
||||||
let outputPath = options.output || config.output
|
|
||||||
if (options.gzip) {
|
|
||||||
outputPath = outputPath || 'guide.xml.gz'
|
|
||||||
const compressed = await gzip(xml)
|
|
||||||
file.write(outputPath, compressed)
|
|
||||||
} else {
|
|
||||||
outputPath = outputPath || 'guide.xml'
|
|
||||||
file.write(outputPath, xml)
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info(`File '${outputPath}' successfully saved`)
|
|
||||||
logger.info('Finish')
|
logger.info('Finish')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue