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
af41021b99
commit
870ac11e70
12 changed files with 159 additions and 148 deletions
|
@ -33,10 +33,16 @@ async function loadChannels() {
|
|||
const files = await file.list(options.channels)
|
||||
for (const filepath of files) {
|
||||
const dir = file.dirname(filepath)
|
||||
const filename = file.basename(filepath)
|
||||
const [_, code] = filename.match(/_(.*).channels.xml/i) || ['', '']
|
||||
const [country, __] = code.split('-') || [null, null]
|
||||
const items = await parser.parseChannels(filepath)
|
||||
for (const item of items) {
|
||||
// const countryCode = item.xmltv_id.split('.')[1]
|
||||
// item.country = countryCode ? countryCode.toUpperCase() : null
|
||||
item.channelsPath = filepath
|
||||
item.configPath = `${dir}/${item.site}.config.js`
|
||||
item.country = country.toUpperCase()
|
||||
channels.push(item)
|
||||
}
|
||||
}
|
||||
|
@ -50,9 +56,7 @@ async function saveToDatabase() {
|
|||
const chunks = split(_.shuffle(channels), options.maxClusters)
|
||||
for (const [i, chunk] of chunks.entries()) {
|
||||
for (const item of chunk) {
|
||||
const countryCode = item.xmltv_id.split('.')[1]
|
||||
item.cluster_id = i + 1
|
||||
item.country = countryCode ? countryCode.toUpperCase() : null
|
||||
await db.channels.insert(item)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,18 +18,18 @@ async function main() {
|
|||
logger.info(`Loading cluster: ${options.clusterId}`)
|
||||
logger.info(`Creating '${clusterLog}'...`)
|
||||
await file.create(clusterLog)
|
||||
const items = await db.channels.find({ cluster_id: options.clusterId })
|
||||
const channels = await db.channels.find({ cluster_id: options.clusterId })
|
||||
const days = options.days || 1
|
||||
const total = days * items.length
|
||||
const total = days * channels.length
|
||||
logger.info(`Total ${total} requests`)
|
||||
|
||||
logger.info('Loading...')
|
||||
const results = {}
|
||||
let i = 1
|
||||
for (const item of items) {
|
||||
const config = require(file.resolve(item.configPath))
|
||||
for (const channel of channels) {
|
||||
const config = require(file.resolve(channel.configPath))
|
||||
config.days = config.days || days
|
||||
const programs = await grabber.grab(item, config, (data, err) => {
|
||||
const programs = await grabber.grab(channel, config, (data, err) => {
|
||||
logger.info(
|
||||
`[${i}/${total}] ${config.site} - ${data.channel.xmltv_id} - ${data.date.format(
|
||||
'MMM D, YYYY'
|
||||
|
@ -42,7 +42,8 @@ async function main() {
|
|||
})
|
||||
await file.append(
|
||||
clusterLog,
|
||||
JSON.stringify({ _id: item._id, site: config.site, programs }) + '\n'
|
||||
JSON.stringify({ _id: channel._id, site: config.site, country: channel.country, programs }) +
|
||||
'\n'
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,11 @@ async function main() {
|
|||
for (const filepath of files) {
|
||||
const results = await parser.parseLogs(filepath)
|
||||
results.forEach(result => {
|
||||
const programs = result.programs.map(p => {
|
||||
p.site = result.site
|
||||
return p
|
||||
const programs = result.programs.map(program => {
|
||||
program.site = result.site
|
||||
program.country = result.country
|
||||
|
||||
return program
|
||||
})
|
||||
db.programs.insert(programs)
|
||||
})
|
||||
|
|
|
@ -1,25 +1,24 @@
|
|||
const { db, logger, file, xml } = require('../core')
|
||||
const _ = require('lodash')
|
||||
|
||||
let channels = {}
|
||||
let programs = {}
|
||||
let sources = {}
|
||||
|
||||
const DB_DIR = process.env.DB_DIR || 'scripts/database'
|
||||
const GUIDES_DIR = process.env.GUIDES_DIR || '.gh-pages/guides'
|
||||
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages'
|
||||
|
||||
async function main() {
|
||||
await setUp()
|
||||
|
||||
await generateMainXML()
|
||||
await generateCountries()
|
||||
await generateEpgXML()
|
||||
await generateGuides()
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
async function generateMainXML() {
|
||||
async function generateEpgXML() {
|
||||
logger.info(`Generating epg.xml...`)
|
||||
|
||||
const channels = await loadChannels()
|
||||
const programs = await loadPrograms()
|
||||
|
||||
const output = {}
|
||||
const filteredChannels = Object.keys(programs)
|
||||
output.channels = _.flatten(Object.values(channels))
|
||||
|
@ -30,41 +29,28 @@ async function generateMainXML() {
|
|||
})
|
||||
output.programs = _.flatten(Object.values(programs))
|
||||
|
||||
await file.create(`${GUIDES_DIR}/epg.xml`, xml.create(output))
|
||||
await file.create(`${PUBLIC_DIR}/epg.xml`, xml.create(output))
|
||||
}
|
||||
|
||||
async function generateCountries() {
|
||||
logger.info(`Generating countries/...`)
|
||||
async function generateGuides() {
|
||||
logger.info(`Generating guides/...`)
|
||||
|
||||
const filteredChannels = Object.keys(programs).map(id => channels[id])
|
||||
let channels = await db.channels.find({}).sort({ xmltv_id: 1 })
|
||||
const programs = await db.programs.find({}).sort({ channel: 1, start: 1 })
|
||||
const grouped = _.groupBy(programs, i => `${i.country.toLowerCase()}/${i.site}`)
|
||||
|
||||
for (let channel of filteredChannels) {
|
||||
const code = channel.country
|
||||
const output = {
|
||||
channels: [],
|
||||
programs: []
|
||||
}
|
||||
|
||||
output.channels = filteredChannels
|
||||
.filter(c => c.country === code)
|
||||
.map(c => {
|
||||
c.site = sources[c.id]
|
||||
return c
|
||||
})
|
||||
|
||||
for (let channel of output.channels) {
|
||||
output.programs = output.programs.concat(programs[channel.id])
|
||||
}
|
||||
|
||||
await file.create(`${GUIDES_DIR}/countries/${code.toLowerCase()}.epg.xml`, xml.create(output))
|
||||
for (let groupId in grouped) {
|
||||
const filepath = `${PUBLIC_DIR}/guides/${groupId}.epg.xml`
|
||||
const groupProgs = grouped[groupId]
|
||||
const groupChannels = Object.keys(_.groupBy(groupProgs, 'channel')).map(key => {
|
||||
let [_, site] = groupId.split('/')
|
||||
return channels.find(i => i.xmltv_id === key && i.site === site)
|
||||
})
|
||||
const output = xml.create({ channels: groupChannels, programs: groupProgs })
|
||||
await file.create(filepath, output)
|
||||
}
|
||||
}
|
||||
|
||||
async function setUp() {
|
||||
channels = await loadChannels()
|
||||
programs = await loadPrograms()
|
||||
}
|
||||
|
||||
async function loadChannels() {
|
||||
let items = await db.channels.find({}).sort({ xmltv_id: 1 })
|
||||
|
||||
|
@ -89,50 +75,66 @@ async function loadChannels() {
|
|||
}
|
||||
|
||||
async function loadPrograms() {
|
||||
let items = await db.programs.find({})
|
||||
let programs = await db.programs.find({})
|
||||
|
||||
items = _.sortBy(items, ['channel', 'start'])
|
||||
items = _.groupBy(items, 'channel')
|
||||
|
||||
for (let channel in items) {
|
||||
let channelPrograms = items[channel]
|
||||
channelPrograms = Object.values(_.groupBy(channelPrograms, i => i.site))[0]
|
||||
let slots = _.groupBy(channelPrograms, i => `${i.start}_${i.stop}`)
|
||||
|
||||
for (let slotId in slots) {
|
||||
let program = {
|
||||
channel,
|
||||
title: [],
|
||||
description: [],
|
||||
categories: [],
|
||||
image: null,
|
||||
start: null,
|
||||
stop: null
|
||||
}
|
||||
|
||||
slots[slotId].forEach(item => {
|
||||
if (item.title) program.title.push({ lang: item.lang, value: item.title })
|
||||
if (item.description)
|
||||
program.description.push({
|
||||
lang: item.lang,
|
||||
value: item.description
|
||||
})
|
||||
if (item.category) program.categories.push({ lang: item.lang, value: item.category })
|
||||
program.image = program.image || item.icon
|
||||
program.start = item.start
|
||||
program.stop = item.stop
|
||||
sources[channel] = item.site
|
||||
})
|
||||
|
||||
program.title = _.uniqBy(program.title, 'lang')
|
||||
program.description = _.uniqBy(program.description, 'lang')
|
||||
program.categories = _.uniqBy(program.categories, 'lang')
|
||||
|
||||
slots[slotId] = program
|
||||
programs = programs.map(program => {
|
||||
return {
|
||||
title: program.title ? [{ lang: program.lang, value: program.title }] : [],
|
||||
description: program.description ? [{ lang: program.lang, value: program.description }] : [],
|
||||
categories: program.category ? [{ lang: program.lang, value: program.category }] : [],
|
||||
icon: program.icon,
|
||||
channel: program.channel,
|
||||
lang: program.lang,
|
||||
start: program.start,
|
||||
stop: program.stop,
|
||||
site: program.site,
|
||||
country: program.country,
|
||||
_id: program._id
|
||||
}
|
||||
})
|
||||
|
||||
items[channel] = Object.values(slots)
|
||||
}
|
||||
programs = _.sortBy(programs, ['channel', 'start'])
|
||||
programs = _.groupBy(programs, 'channel')
|
||||
|
||||
return items
|
||||
// for (let channel in items) {
|
||||
// let channelPrograms = items[channel]
|
||||
// channelPrograms = Object.values(_.groupBy(channelPrograms, i => i.site))[0]
|
||||
// let slots = _.groupBy(channelPrograms, i => `${i.start}_${i.stop}`)
|
||||
|
||||
// for (let slotId in slots) {
|
||||
// let program = {
|
||||
// channel,
|
||||
// title: [],
|
||||
// description: [],
|
||||
// categories: [],
|
||||
// image: null,
|
||||
// start: null,
|
||||
// stop: null
|
||||
// }
|
||||
|
||||
// slots[slotId].forEach(item => {
|
||||
// if (item.title) program.title.push({ lang: item.lang, value: item.title })
|
||||
// if (item.description)
|
||||
// program.description.push({
|
||||
// lang: item.lang,
|
||||
// value: item.description
|
||||
// })
|
||||
// if (item.category) program.categories.push({ lang: item.lang, value: item.category })
|
||||
// program.image = program.image || item.icon
|
||||
// program.start = item.start
|
||||
// program.stop = item.stop
|
||||
// sources[channel] = item.site
|
||||
// })
|
||||
|
||||
// program.title = _.uniqBy(program.title, 'lang')
|
||||
// program.description = _.uniqBy(program.description, 'lang')
|
||||
// program.categories = _.uniqBy(program.categories, 'lang')
|
||||
|
||||
// slots[slotId] = program
|
||||
// }
|
||||
|
||||
// items[channel] = Object.values(slots)
|
||||
// }
|
||||
|
||||
return programs
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue