From da23d7e2676bbfe174a1750d49904e60725cf8c2 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 30 Jan 2022 04:02:29 +0300 Subject: [PATCH] Update update-guides.js --- scripts/commands/update-guides.js | 23 +++++++++++++------ scripts/core/api.js | 15 ++++++++++++ scripts/core/index.js | 1 + .../guides/bh/chaines-tv.orange.fr.epg.xml | 2 +- .../guides/fr/chaines-tv.orange.fr.epg.xml | 2 +- tests/commands/update-guides.test.js | 5 +--- 6 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 scripts/core/api.js diff --git a/scripts/commands/update-guides.js b/scripts/commands/update-guides.js index b9211cfe..0bbe7c52 100644 --- a/scripts/commands/update-guides.js +++ b/scripts/commands/update-guides.js @@ -1,4 +1,4 @@ -const { db, logger, file } = require('../core') +const { db, logger, file, api } = require('../core') const grabber = require('epg-grabber') const _ = require('lodash') @@ -17,14 +17,23 @@ main() async function generateGuides() { logger.info(`Generating guides/...`) - const grouped = groupByGroup(await loadChannels()) + const grouped = groupByGroup(await loadQueue()) logger.info('Loading "database/programs.db"...') await db.programs.load() for (const key in grouped) { const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml` - const channels = grouped[key] + const items = grouped[key] + const channels = items + .map(i => { + const channel = api.channels.get(i.xmltv_id) + i.name = channel.name + i.logo = channel.logo + return i + }) + .filter(i => i) + const programs = await loadProgramsForChannels(channels) const output = grabber.convertToXMLTV({ channels, programs }) @@ -56,12 +65,12 @@ function groupByGroup(channels = []) { return groups } -async function loadChannels() { - logger.info('Loading channels...') +async function loadQueue() { + logger.info('Loading queue...') - await db.channels.load() + await db.queue.load() - return await db.channels.find({ programCount: { $gt: 0 } }).sort({ xmltv_id: 1 }) + return await db.queue.find({ programCount: { $gt: 0 } }).sort({ xmltv_id: 1 }) } async function loadProgramsForChannels(channels = []) { diff --git a/scripts/core/api.js b/scripts/core/api.js new file mode 100644 index 00000000..db9c9160 --- /dev/null +++ b/scripts/core/api.js @@ -0,0 +1,15 @@ +class API { + constructor(filepath) { + this.collection = require(filepath) + } + + get(id) { + return this.collection.find(c => c.id === id) + } +} + +const api = {} + +api.channels = new API('../data/channels.json') + +module.exports = api diff --git a/scripts/core/index.js b/scripts/core/index.js index d6ac705f..6003c058 100644 --- a/scripts/core/index.js +++ b/scripts/core/index.js @@ -4,3 +4,4 @@ exports.file = require('./file') exports.parser = require('./parser') exports.timer = require('./timer') exports.markdown = require('./markdown') +exports.api = require('./api') diff --git a/tests/__data__/expected/guides/bh/chaines-tv.orange.fr.epg.xml b/tests/__data__/expected/guides/bh/chaines-tv.orange.fr.epg.xml index 9b28bc7d..353ba7df 100644 --- a/tests/__data__/expected/guides/bh/chaines-tv.orange.fr.epg.xml +++ b/tests/__data__/expected/guides/bh/chaines-tv.orange.fr.epg.xml @@ -1,5 +1,5 @@ -CNN International Europehttps://chaines-tv.orange.fr +CNN International Europehttps://chaines-tv.orange.fr CNN Newsroom SundayСвежая мировая информационная сводка от CNN. О политике, экономике, общественной жизни, культуре, спорте.Category1Category2 Fareed Zakaria GPSИнтервью с главными игроками мировой политики.Category1 African Voices Changemakers. 114-я серия114-я серия. Африка сегодня - люди, новости, события. diff --git a/tests/__data__/expected/guides/fr/chaines-tv.orange.fr.epg.xml b/tests/__data__/expected/guides/fr/chaines-tv.orange.fr.epg.xml index 9b28bc7d..353ba7df 100644 --- a/tests/__data__/expected/guides/fr/chaines-tv.orange.fr.epg.xml +++ b/tests/__data__/expected/guides/fr/chaines-tv.orange.fr.epg.xml @@ -1,5 +1,5 @@ -CNN International Europehttps://chaines-tv.orange.fr +CNN International Europehttps://chaines-tv.orange.fr CNN Newsroom SundayСвежая мировая информационная сводка от CNN. О политике, экономике, общественной жизни, культуре, спорте.Category1Category2 Fareed Zakaria GPSИнтервью с главными игроками мировой политики.Category1 African Voices Changemakers. 114-я серия114-я серия. Африка сегодня - люди, новости, события. diff --git a/tests/commands/update-guides.test.js b/tests/commands/update-guides.test.js index 391bf252..38ba387d 100644 --- a/tests/commands/update-guides.test.js +++ b/tests/commands/update-guides.test.js @@ -6,10 +6,7 @@ beforeEach(() => { fs.rmdirSync('tests/__data__/output', { recursive: true }) fs.mkdirSync('tests/__data__/output') fs.mkdirSync('tests/__data__/temp/database', { recursive: true }) - fs.copyFileSync( - 'tests/__data__/input/database/channels.db', - 'tests/__data__/temp/database/channels.db' - ) + fs.copyFileSync('tests/__data__/input/database/queue.db', 'tests/__data__/temp/database/queue.db') fs.copyFileSync( 'tests/__data__/input/database/programs.db', 'tests/__data__/temp/database/programs.db'