From 189a370f3d836303b4c50a18794143cdf78817f6 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 20 Jan 2022 19:22:53 +0300 Subject: [PATCH] Update parse-channels.js --- scripts/commands/parse-channels.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/commands/parse-channels.js b/scripts/commands/parse-channels.js index d8920ad2..76fe5954 100644 --- a/scripts/commands/parse-channels.js +++ b/scripts/commands/parse-channels.js @@ -1,6 +1,8 @@ const { Command } = require('commander') -const fs = require('fs') +const { db } = require('../core') const path = require('path') +const _ = require('lodash') +const fs = require('fs') const program = new Command() program @@ -12,6 +14,7 @@ program const options = program.opts() async function main() { + await db.channels.load() const config = require(path.resolve(options.config)) const args = {} options.set.forEach(arg => { @@ -22,12 +25,19 @@ async function main() { if (isPromise(channels)) { channels = await channels } - channels = channels.map(channel => { - if (!channel.xmltv_id) { - channel.xmltv_id = channel.name + channels = _.uniqBy(channels, 'site_id') + + for (const channel of channels) { + const data = await db.channels + .find({ site: config.site, site_id: channel.site_id.toString() }) + .limit(1) + if (data.length) { + const first = data[0] + channel.xmltv_id = first.xmltv_id + channel.name = first.name } - return channel - }) + } + const xml = json2xml(channels, config.site) const dir = path.parse(options.config).dir