This commit is contained in:
Aleksandr Statciuk 2022-01-09 21:43:57 +03:00
parent d523210bb7
commit aeecc61bd7
4 changed files with 139393 additions and 25 deletions

127493
.gh-pages/api/channels.json Normal file

File diff suppressed because it is too large Load diff

11871
.gh-pages/api/programs.json Normal file

File diff suppressed because it is too large Load diff

View file

@ -20,41 +20,39 @@ async function main() {
main() main()
async function setUp() { async function setUp() {
channels = await db.channels.find({}) channels = await db.channels.find({}).sort({ xmltv_id: 1 })
programs = await db.programs.find({}) programs = await db.programs.find({})
} }
async function generateChannelsJson() { async function generateChannelsJson() {
logger.info('Generating channels.json...') logger.info('Generating channels.json...')
let items = channels let output = {}
items = _.sortBy(items, item => item.name) channels.forEach(channel => {
if (!output[channel.xmltv_id]) {
const countryCode = channel.xmltv_id.split('.')[1]
let buffer = {} output[channel.xmltv_id] = {
items.forEach(item => { id: channel.xmltv_id,
if (!buffer[item.xmltv_id]) { name: [channel.name],
const countryCode = item.xmltv_id.split('.')[1] logo: channel.logo || null,
buffer[item.xmltv_id] = {
id: item.xmltv_id,
name: [item.name],
logo: item.logo || null,
country: countryCode ? countryCode.toUpperCase() : null country: countryCode ? countryCode.toUpperCase() : null
} }
} else { } else {
if (!buffer[item.xmltv_id].logo && item.logo) { if (!output[channel.xmltv_id].logo && channel.logo) {
buffer[item.xmltv_id].logo = item.logo output[channel.xmltv_id].logo = channel.logo
} }
if (!buffer[item.xmltv_id].name.includes(item.name)) { if (!output[channel.xmltv_id].name.includes(channel.name)) {
buffer[item.xmltv_id].name.push(item.name) output[channel.xmltv_id].name.push(channel.name)
} }
} }
}) })
items = Object.values(buffer) await file.create(
`${PUBLIC_DIR}/api/channels.json`,
await file.create(`${PUBLIC_DIR}/api/channels.json`, JSON.stringify(items)) JSON.stringify(Object.values(output), null, 2)
)
} }
async function generateProgramsJson() { async function generateProgramsJson() {
@ -73,17 +71,16 @@ async function generateProgramsJson() {
for (let slotId in slots) { for (let slotId in slots) {
let program = { let program = {
channel, channel,
site: null,
title: [], title: [],
description: [], description: [],
categories: [], categories: [],
icons: [], image: null,
start: null, start: null,
stop: null stop: null
} }
slots[slotId].forEach(item => { slots[slotId].forEach(item => {
program.site = item.site // program.site = item.site
if (item.title) program.title.push({ lang: item.lang, value: item.title }) if (item.title) program.title.push({ lang: item.lang, value: item.title })
if (item.description) if (item.description)
program.description.push({ program.description.push({
@ -91,11 +88,15 @@ async function generateProgramsJson() {
value: item.description value: item.description
}) })
if (item.category) program.categories.push({ lang: item.lang, value: item.category }) if (item.category) program.categories.push({ lang: item.lang, value: item.category })
if (item.icon) program.icons.push(item.icon) program.image = program.image || item.icon
program.start = item.start program.start = item.start
program.stop = item.stop program.stop = item.stop
}) })
program.title = _.uniqBy(program.title, 'lang')
program.description = _.uniqBy(program.description, 'lang')
program.categories = _.uniqBy(program.categories, 'lang')
slots[slotId] = program slots[slotId] = program
} }

View file

@ -39,10 +39,13 @@ it('can generate programs.json', () => {
'categories', 'categories',
'channel', 'channel',
'description', 'description',
'icons', 'image',
'site',
'start', 'start',
'stop', 'stop',
'title' 'title'
]) ])
expect(Array.isArray(program.title)).toBe(true)
expect(Array.isArray(program.description)).toBe(true)
expect(Array.isArray(program.categories)).toBe(true)
expect(program.image === null || typeof program.image === 'string').toBe(true)
}) })