mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Update parse.js
This commit is contained in:
parent
f2057dd015
commit
114ff0823b
1 changed files with 21 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
||||||
const { logger, file, xml } = require('../../core')
|
const { logger, file, xml, parser } = require('../../core')
|
||||||
const { Command } = require('commander')
|
const { Command } = require('commander')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
@ -8,31 +8,44 @@ program
|
||||||
.requiredOption('-c, --config <config>', 'Config file')
|
.requiredOption('-c, --config <config>', 'Config file')
|
||||||
.option('-s, --set [args...]', 'Set custom arguments', [])
|
.option('-s, --set [args...]', 'Set custom arguments', [])
|
||||||
.option('-o, --output <output>', 'Output file')
|
.option('-o, --output <output>', 'Output file')
|
||||||
|
.option('--clean', 'Delete the previous *.channels.xml if exists')
|
||||||
.parse(process.argv)
|
.parse(process.argv)
|
||||||
|
|
||||||
const options = program.opts()
|
const options = program.opts()
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const config = require(path.resolve(options.config))
|
const config = require(path.resolve(options.config))
|
||||||
|
const dir = file.dirname(options.config)
|
||||||
|
const outputFilepath = options.output || `${dir}/${config.site}.channels.xml`
|
||||||
|
|
||||||
|
let channels = []
|
||||||
|
if (!options.clean && (await file.exists(outputFilepath))) {
|
||||||
|
let result = await parser.parseChannels(outputFilepath)
|
||||||
|
|
||||||
|
channels = result.channels
|
||||||
|
}
|
||||||
|
|
||||||
const args = {}
|
const args = {}
|
||||||
options.set.forEach(arg => {
|
options.set.forEach(arg => {
|
||||||
const [key, value] = arg.split(':')
|
const [key, value] = arg.split(':')
|
||||||
args[key] = value
|
args[key] = value
|
||||||
})
|
})
|
||||||
|
|
||||||
let channels = config.channels(args)
|
let parsedChannels = config.channels(args)
|
||||||
if (isPromise(channels)) {
|
if (isPromise(parsedChannels)) {
|
||||||
channels = await channels
|
parsedChannels = await parsedChannels
|
||||||
}
|
}
|
||||||
channels = channels.map(c => {
|
parsedChannels = parsedChannels.map(c => {
|
||||||
c.lang = c.lang || 'en'
|
c.lang = c.lang || 'en'
|
||||||
|
|
||||||
return c
|
return c
|
||||||
})
|
})
|
||||||
channels = _.sortBy(channels, ['lang', 'xmltv_id'])
|
|
||||||
|
|
||||||
const dir = file.dirname(options.config)
|
channels = channels.concat(parsedChannels)
|
||||||
const outputFilepath = options.output || `${dir}/${config.site}.channels.xml`
|
|
||||||
|
channels = _.uniqBy(channels, c => c.site_id + c.lang)
|
||||||
|
|
||||||
|
channels = _.sortBy(channels, ['lang', 'xmltv_id'])
|
||||||
|
|
||||||
const output = xml.create(channels, config.site)
|
const output = xml.create(channels, config.site)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue