mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update parse.ts
This commit is contained in:
parent
6c5032ccb3
commit
05d8185f8e
1 changed files with 20 additions and 12 deletions
|
@ -9,7 +9,6 @@ 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)
|
||||||
|
|
||||||
type ParseOptions = {
|
type ParseOptions = {
|
||||||
|
@ -31,7 +30,7 @@ async function main() {
|
||||||
const outputFilepath = options.output || `${dir}/${config.site}.channels.xml`
|
const outputFilepath = options.output || `${dir}/${config.site}.channels.xml`
|
||||||
|
|
||||||
let channels = new Collection()
|
let channels = new Collection()
|
||||||
if (!options.clean && (await storage.exists(outputFilepath))) {
|
if (await storage.exists(outputFilepath)) {
|
||||||
channels = await parser.parse(outputFilepath)
|
channels = await parser.parse(outputFilepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,18 +55,27 @@ async function main() {
|
||||||
return channel
|
return channel
|
||||||
})
|
})
|
||||||
|
|
||||||
channels = channels
|
let output = new Collection()
|
||||||
.mergeBy(
|
parsedChannels.forEach((channel: Channel) => {
|
||||||
new Collection(parsedChannels),
|
const found: Channel | undefined = channels.first(
|
||||||
(channel: Channel) => channel.site_id.toString() + channel.lang
|
(_channel: Channel) => _channel.site_id === channel.site_id
|
||||||
)
|
)
|
||||||
.orderBy([
|
|
||||||
(channel: Channel) => channel.lang,
|
|
||||||
(channel: Channel) => (channel.xmltv_id ? channel.xmltv_id.toLowerCase() : '_'),
|
|
||||||
(channel: Channel) => channel.site_id
|
|
||||||
])
|
|
||||||
|
|
||||||
const xml = new XML(channels)
|
if (found) {
|
||||||
|
channel.name = found.name
|
||||||
|
channel.xmltv_id = found.xmltv_id
|
||||||
|
}
|
||||||
|
|
||||||
|
output.add(channel)
|
||||||
|
})
|
||||||
|
|
||||||
|
output = output.orderBy([
|
||||||
|
(channel: Channel) => channel.lang,
|
||||||
|
(channel: Channel) => (channel.xmltv_id ? channel.xmltv_id.toLowerCase() : '_'),
|
||||||
|
(channel: Channel) => channel.site_id
|
||||||
|
])
|
||||||
|
|
||||||
|
const xml = new XML(output)
|
||||||
|
|
||||||
await storage.save(outputFilepath, xml.toString())
|
await storage.save(outputFilepath, xml.toString())
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue