From 05d8185f8e72478a9baf2628669008e28d1e05ee Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Fri, 17 Nov 2023 17:48:28 +0300 Subject: [PATCH] Update parse.ts --- scripts/commands/channels/parse.ts | 32 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/scripts/commands/channels/parse.ts b/scripts/commands/channels/parse.ts index c9185652..a141db3d 100644 --- a/scripts/commands/channels/parse.ts +++ b/scripts/commands/channels/parse.ts @@ -9,7 +9,6 @@ program .requiredOption('-c, --config ', 'Config file') .option('-s, --set [args...]', 'Set custom arguments') .option('-o, --output ', 'Output file') - .option('--clean', 'Delete the previous *.channels.xml if exists') .parse(process.argv) type ParseOptions = { @@ -31,7 +30,7 @@ async function main() { const outputFilepath = options.output || `${dir}/${config.site}.channels.xml` let channels = new Collection() - if (!options.clean && (await storage.exists(outputFilepath))) { + if (await storage.exists(outputFilepath)) { channels = await parser.parse(outputFilepath) } @@ -56,18 +55,27 @@ async function main() { return channel }) - channels = channels - .mergeBy( - new Collection(parsedChannels), - (channel: Channel) => channel.site_id.toString() + channel.lang + let output = new Collection() + parsedChannels.forEach((channel: Channel) => { + const found: Channel | undefined = channels.first( + (_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())