mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
wip
This commit is contained in:
parent
e7873963c8
commit
d523210bb7
2 changed files with 63 additions and 39 deletions
|
@ -14,12 +14,14 @@ async function main() {
|
||||||
await setUp()
|
await setUp()
|
||||||
|
|
||||||
await generateChannelsJson()
|
await generateChannelsJson()
|
||||||
|
await generateProgramsJson()
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
async function setUp() {
|
async function setUp() {
|
||||||
channels = await db.channels.find({})
|
channels = await db.channels.find({})
|
||||||
|
programs = await db.programs.find({})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateChannelsJson() {
|
async function generateChannelsJson() {
|
||||||
|
@ -55,53 +57,53 @@ async function generateChannelsJson() {
|
||||||
await file.create(`${PUBLIC_DIR}/api/channels.json`, JSON.stringify(items))
|
await file.create(`${PUBLIC_DIR}/api/channels.json`, JSON.stringify(items))
|
||||||
}
|
}
|
||||||
|
|
||||||
// async function createProgramsJson() {
|
async function generateProgramsJson() {
|
||||||
// logger.info('Creating programs.json...')
|
logger.info('Generating programs.json...')
|
||||||
|
|
||||||
// let items = programs
|
let items = programs
|
||||||
|
|
||||||
// items = _.sortBy(items, ['channel', 'start'])
|
items = _.sortBy(items, ['channel', 'start'])
|
||||||
// items = _.groupBy(items, 'channel')
|
items = _.groupBy(items, 'channel')
|
||||||
|
|
||||||
// for (let channel in items) {
|
for (let channel in items) {
|
||||||
// let programs = items[channel]
|
let channelPrograms = items[channel]
|
||||||
// programs = Object.values(_.groupBy(programs, i => i.site))[0]
|
channelPrograms = Object.values(_.groupBy(channelPrograms, i => i.site))[0]
|
||||||
// let slots = _.groupBy(programs, i => `${i.start}_${i.stop}`)
|
let slots = _.groupBy(channelPrograms, i => `${i.start}_${i.stop}`)
|
||||||
|
|
||||||
// for (let slotId in slots) {
|
for (let slotId in slots) {
|
||||||
// let program = {
|
let program = {
|
||||||
// channel,
|
channel,
|
||||||
// site: null,
|
site: null,
|
||||||
// title: [],
|
title: [],
|
||||||
// description: [],
|
description: [],
|
||||||
// categories: [],
|
categories: [],
|
||||||
// icons: [],
|
icons: [],
|
||||||
// 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({
|
||||||
// lang: item.lang,
|
lang: item.lang,
|
||||||
// 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)
|
if (item.icon) program.icons.push(item.icon)
|
||||||
// program.start = item.start
|
program.start = item.start
|
||||||
// program.stop = item.stop
|
program.stop = item.stop
|
||||||
// })
|
})
|
||||||
|
|
||||||
// slots[slotId] = program
|
slots[slotId] = program
|
||||||
// }
|
}
|
||||||
|
|
||||||
// items[channel] = Object.values(slots)
|
items[channel] = Object.values(slots)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// await file.create(`${PUBLIC_PATH}/api/programs.json`, JSON.stringify(items, null, 2))
|
await file.create(`${PUBLIC_DIR}/api/programs.json`, JSON.stringify(items, null, 2))
|
||||||
// }
|
}
|
||||||
|
|
||||||
// async function generateGuideXML() {
|
// async function generateGuideXML() {
|
||||||
// logger.info(`Generating guide.xml...`)
|
// logger.info(`Generating guide.xml...`)
|
||||||
|
|
|
@ -24,3 +24,25 @@ it('can generate channels.json', () => {
|
||||||
country: 'AD'
|
country: 'AD'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('can generate programs.json', () => {
|
||||||
|
const result = execSync(
|
||||||
|
'PUBLIC_DIR=tests/__data__/output DB_DIR=tests/__data__/input/database node scripts/commands/generate-guides.js',
|
||||||
|
{ encoding: 'utf8' }
|
||||||
|
)
|
||||||
|
const json = fs.readFileSync(path.resolve('tests/__data__/output/api/programs.json'), {
|
||||||
|
encoding: 'utf8'
|
||||||
|
})
|
||||||
|
const parsed = JSON.parse(json)
|
||||||
|
const program = parsed['AndorraTV.ad'][0]
|
||||||
|
expect(Object.keys(program).sort()).toEqual([
|
||||||
|
'categories',
|
||||||
|
'channel',
|
||||||
|
'description',
|
||||||
|
'icons',
|
||||||
|
'site',
|
||||||
|
'start',
|
||||||
|
'stop',
|
||||||
|
'title'
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue