From 210269e7ec1bf697cb2698dac76d958398fe69e9 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 31 Jan 2022 02:10:09 +0300 Subject: [PATCH] Update update-guides.js --- scripts/commands/update-guides.js | 38 ++++++++++++++------------ tests/__data__/input/database/queue.db | 2 +- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/scripts/commands/update-guides.js b/scripts/commands/update-guides.js index 624973a3..c74a4204 100644 --- a/scripts/commands/update-guides.js +++ b/scripts/commands/update-guides.js @@ -26,24 +26,15 @@ async function generateGuides() { for (const key in grouped) { const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml` let items = grouped[key] - items = items - .map(i => { - const channel = api.channels.find({ id: i.xmltv_id }) - i.name = channel.name - i.logo = channel.logo - - return i - }) - .filter(i => i) const errors = [] for (const item of items) { if (item.error) { const error = { - xmltv_id: item.xmltv_id, + xmltv_id: item.channel.xmltv_id, site: item.site, - site_id: item.site_id, - lang: item.lang, + site_id: item.channel.site_id, + lang: item.channel.lang, date: item.date, error: item.error } @@ -52,10 +43,23 @@ async function generateGuides() { } } - const programs = await loadProgramsForChannels(items) + const programs = await loadProgramsForItems(items) logger.info(`Creating "${filepath}"...`) - const output = grabber.convertToXMLTV({ channels: items, programs }) + const channels = items + .map(item => { + const channel = api.channels.find({ id: item.channel.xmltv_id }) + if (!channel) return null + + return { + id: channel.id, + display_name: channel.name, + url: item.site, + icon: channel.logo + } + }) + .filter(i => i) + const output = grabber.convertToXMLTV({ channels, programs }) await file.create(filepath, output) await logGuide({ @@ -92,10 +96,10 @@ async function loadQueue() { return await db.queue.find({}).sort({ xmltv_id: 1 }) } -async function loadProgramsForChannels(channels = []) { - const cids = channels.map(c => c._id) +async function loadProgramsForItems(items = []) { + const qids = items.map(i => i._id) - return await db.programs.find({ _cid: { $in: cids } }).sort({ channel: 1, start: 1 }) + return await db.programs.find({ _qid: { $in: qids } }).sort({ channel: 1, start: 1 }) } async function setUp() { diff --git a/tests/__data__/input/database/queue.db b/tests/__data__/input/database/queue.db index d92002c2..2e274a6d 100644 --- a/tests/__data__/input/database/queue.db +++ b/tests/__data__/input/database/queue.db @@ -1,4 +1,4 @@ -{"channel":{"lang":"en","xmltv_id":"BravoEast.us","site_id":"237"},"site":"directv.com","configPath":"sites/directv.com/directv.com.config.js","groups":["us/directv.com"],"error":null,"cluster_id":84,"date":"2022-01-21T00:00:00Z","_id":"00AluKCrCnfgrl8W"} +{"channel":{"lang":"en","xmltv_id":"BravoEast.us","site_id":"237"},"site":"directv.com","configPath":"sites/directv.com/directv.com.config.js","groups":["us/directv.com"],"error":"Invalid header value char","cluster_id":84,"date":"2022-01-21T00:00:00Z","_id":"00AluKCrCnfgrl8W"} {"channel":{"lang":"fr","xmltv_id":"CNNInternationalEurope.us","site_id":"53"},"site":"chaines-tv.orange.fr","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["fr/chaines-tv.orange.fr", "bh/chaines-tv.orange.fr"],"error":null,"cluster_id":1,"date":"2022-01-21T00:00:00Z","_id":"0Wefq0oMR3feCcuY"} {"channel":{"lang":"ru","xmltv_id":"CNNInternationalEurope.us","site_id":"140"},"site":"magticom.ge","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["ge/magticom.ge"],"error":null,"cluster_id":1,"date":"2022-01-21T00:00:00Z","_id":"1XzrxNkSF2AQNBrT"} {"channel":{"lang":"en","xmltv_id":"MNetMovies2.za","site_id":"404a052b-3dea-4cac-a19c-de9a7d6f191d#MAP"},"site":"dstv.com","configPath":"sites/dstv.com/dstv.com.config.js","groups":["zw/dstv.com"],"error":null,"cluster_id":120,"date":"2022-01-21T00:00:00Z","_id":"1lnhXpN7g0ER5XwN"}