Update update-guides.js

This commit is contained in:
Aleksandr Statciuk 2022-01-31 02:10:09 +03:00
parent dc07784bf9
commit 210269e7ec
2 changed files with 22 additions and 18 deletions

View file

@ -26,24 +26,15 @@ 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`
let items = grouped[key] 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 = [] const errors = []
for (const item of items) { for (const item of items) {
if (item.error) { if (item.error) {
const error = { const error = {
xmltv_id: item.xmltv_id, xmltv_id: item.channel.xmltv_id,
site: item.site, site: item.site,
site_id: item.site_id, site_id: item.channel.site_id,
lang: item.lang, lang: item.channel.lang,
date: item.date, date: item.date,
error: item.error error: item.error
} }
@ -52,10 +43,23 @@ async function generateGuides() {
} }
} }
const programs = await loadProgramsForChannels(items) const programs = await loadProgramsForItems(items)
logger.info(`Creating "${filepath}"...`) 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 file.create(filepath, output)
await logGuide({ await logGuide({
@ -92,10 +96,10 @@ async function loadQueue() {
return await db.queue.find({}).sort({ xmltv_id: 1 }) return await db.queue.find({}).sort({ xmltv_id: 1 })
} }
async function loadProgramsForChannels(channels = []) { async function loadProgramsForItems(items = []) {
const cids = channels.map(c => c._id) 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() { async function setUp() {

View file

@ -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":"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":"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"} {"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"}