Merge branch 'patch-02.2022' into workflow-per-site

This commit is contained in:
Aleksandr Statciuk 2022-01-31 20:58:35 +03:00
commit 8d4e92370d
2 changed files with 15 additions and 6 deletions

View file

@ -1,6 +1,6 @@
const { db, file, parser, logger, date, api } = require('../core') const { db, file, parser, logger, date, api } = require('../core')
const { program } = require('commander') const { program } = require('commander')
const { shuffle } = require('lodash') const _ = require('lodash')
const options = program const options = program
.option( .option(
@ -97,13 +97,18 @@ async function saveToDatabase(items = []) {
logger.info('Saving to the database...') logger.info('Saving to the database...')
await db.queue.load() await db.queue.load()
await db.queue.reset() 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 [i, chunk] of chunks.entries()) {
for (const item of chunk) { for (const item of chunk) {
item.cluster_id = i + 1 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) { function split(arr, n) {

View file

@ -24,9 +24,11 @@ async function generateGuides() {
for (const key in grouped) { for (const key in grouped) {
const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml` const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml`
const criticalErrors = [] const criticalErrors = []
const channels = [] let channels = {}
let programs = [] let programs = []
for (const item of grouped[key]) { for (const item of grouped[key]) {
if (channels[item.channel.xmltv_id]) continue
if (item.error) { if (item.error) {
const error = { const error = {
xmltv_id: item.channel.xmltv_id, xmltv_id: item.channel.xmltv_id,
@ -65,17 +67,19 @@ async function generateGuides() {
continue continue
} }
channels.push({ channels[channel.id] = {
xmltv_id: channel.id, xmltv_id: channel.id,
name: channel.name, name: channel.name,
logo: channel.logo, logo: channel.logo,
site: item.channel.site site: item.channel.site
}) }
programs = programs.concat(itemPrograms) programs = programs.concat(itemPrograms)
} }
} }
channels = Object.values(channels)
logger.info(`Creating "${filepath}"...`) logger.info(`Creating "${filepath}"...`)
const output = grabber.convertToXMLTV({ channels, programs }) const output = grabber.convertToXMLTV({ channels, programs })
await file.create(filepath, output) await file.create(filepath, output)