From e020e2707fac97f35162e04dfa1d732a55a681e2 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 31 Jan 2022 20:58:15 +0300 Subject: [PATCH 1/2] Update update-guides.js --- scripts/commands/update-guides.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/commands/update-guides.js b/scripts/commands/update-guides.js index 865b2fca..dd354110 100644 --- a/scripts/commands/update-guides.js +++ b/scripts/commands/update-guides.js @@ -24,9 +24,11 @@ async function generateGuides() { for (const key in grouped) { const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml` const criticalErrors = [] - const channels = [] + let channels = {} let programs = [] for (const item of grouped[key]) { + if (channels[item.channel.xmltv_id]) continue + if (item.error) { const error = { xmltv_id: item.channel.xmltv_id, @@ -65,17 +67,19 @@ async function generateGuides() { continue } - channels.push({ + channels[channel.id] = { xmltv_id: channel.id, name: channel.name, logo: channel.logo, site: item.channel.site - }) + } programs = programs.concat(itemPrograms) } } + channels = Object.values(channels) + logger.info(`Creating "${filepath}"...`) const output = grabber.convertToXMLTV({ channels, programs }) await file.create(filepath, output) From dfe65a9f3f99b57fb2f05f54061a8c62532af5f1 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 31 Jan 2022 20:58:17 +0300 Subject: [PATCH 2/2] Update create-queue.js --- scripts/commands/create-queue.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/commands/create-queue.js b/scripts/commands/create-queue.js index 464cd28e..07a81507 100644 --- a/scripts/commands/create-queue.js +++ b/scripts/commands/create-queue.js @@ -1,6 +1,6 @@ const { db, file, parser, logger, date, api } = require('../core') const { program } = require('commander') -const { shuffle } = require('lodash') +const _ = require('lodash') const options = program .option( @@ -97,13 +97,18 @@ async function saveToDatabase(items = []) { logger.info('Saving to the database...') await db.queue.load() await db.queue.reset() - const chunks = split(shuffle(items), options.maxClusters) + let queue = [] + const chunks = split(_.shuffle(items), options.maxClusters) for (const [i, chunk] of chunks.entries()) { for (const item of chunk) { item.cluster_id = i + 1 - await db.queue.insert(item) + queue.push(item) } } + + queue = _.sortBy(queue, ['channel.xmltv_id', 'date']) + + await db.queue.insert(queue) } function split(arr, n) {