mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Update scripts/commands
This commit is contained in:
parent
33be6946c3
commit
487c0e2e30
6 changed files with 37 additions and 65 deletions
|
@ -21,8 +21,8 @@ async function main() {
|
|||
|
||||
for (const channel of channels) {
|
||||
guides.push({
|
||||
channel: channel.xmltv_id,
|
||||
site,
|
||||
channel: channel.id,
|
||||
site: channel.site,
|
||||
lang: channel.lang,
|
||||
url: `https://iptv-org.github.io/epg/guides/${suffix}/${site}.epg.xml`
|
||||
})
|
||||
|
|
|
@ -24,15 +24,15 @@ async function main() {
|
|||
const buffer = {}
|
||||
const errors = []
|
||||
for (const channel of channels) {
|
||||
if (!buffer[channel.xmltv_id]) {
|
||||
buffer[channel.xmltv_id] = channel
|
||||
if (!buffer[channel.id]) {
|
||||
buffer[channel.id] = channel
|
||||
} else {
|
||||
errors.push({ type: 'duplicate', ...channel })
|
||||
errors.push({ type: 'duplicate', xmltv_id: channel.id, ...channel })
|
||||
stats.errors++
|
||||
}
|
||||
|
||||
if (!api.channels.find({ id: channel.xmltv_id })) {
|
||||
errors.push({ type: 'wrong_xmltv_id', ...channel })
|
||||
if (!api.channels.find({ id: channel.id })) {
|
||||
errors.push({ type: 'wrong_xmltv_id', xmltv_id: channel.id, ...channel })
|
||||
stats.errors++
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
const _ = require('lodash')
|
||||
const EPGGrabber = require('epg-grabber')
|
||||
const { EPGGrabber } = require('epg-grabber')
|
||||
const { program } = require('commander')
|
||||
const { db, logger, timer, file, parser } = require('../../core')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
const options = program
|
||||
.requiredOption('-c, --cluster-id <cluster-id>', 'The ID of cluster to load', parser.parseNumber)
|
||||
|
@ -27,7 +31,7 @@ async function main() {
|
|||
await file.create(CLUSTER_PATH)
|
||||
await db.queue.load()
|
||||
let items = await db.queue.find({ cluster_id: options.clusterId })
|
||||
items = _.orderBy(items, [i => i.channel.xmltv_id.toLowerCase(), 'date'])
|
||||
items = _.orderBy(items, [i => i.channel.id.toLowerCase(), 'date'])
|
||||
const total = items.length
|
||||
|
||||
logger.info('Loading...')
|
||||
|
@ -45,9 +49,9 @@ async function main() {
|
|||
for (const item of items) {
|
||||
await grabber.grab(item.channel, item.date, async (data, err) => {
|
||||
logger.info(
|
||||
`[${i}/${total}] ${item.channel.site} (${item.channel.lang}) - ${
|
||||
item.channel.xmltv_id
|
||||
} - ${data.date.format('MMM D, YYYY')} (${data.programs.length} programs)`
|
||||
`[${i}/${total}] ${item.channel.site} (${item.channel.lang}) - ${item.channel.id} - ${dayjs
|
||||
.utc(data.date)
|
||||
.format('MMM D, YYYY')} (${data.programs.length} programs)`
|
||||
)
|
||||
|
||||
if (err) logger.error(err.message)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const { db, logger, file, api, zip } = require('../../core')
|
||||
const grabber = require('epg-grabber')
|
||||
const { generateXMLTV, Program, Channel } = require('epg-grabber')
|
||||
const _ = require('lodash')
|
||||
|
||||
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages'
|
||||
|
@ -23,25 +23,21 @@ async function main() {
|
|||
const itemPrograms = await loadProgramsForItem(item)
|
||||
programs = programs.concat(itemPrograms)
|
||||
|
||||
if (channels[item.channel.xmltv_id]) continue
|
||||
const channel = api.channels.find({ id: item.channel.xmltv_id })
|
||||
if (channel) {
|
||||
channels[channel.id] = {
|
||||
xmltv_id: channel.id,
|
||||
name: item.channel.display_name,
|
||||
logo: channel.logo,
|
||||
site: item.channel.site
|
||||
}
|
||||
if (channels[item.channel.id]) continue
|
||||
const found = api.channels.find({ id: item.channel.id })
|
||||
if (found) {
|
||||
channels[item.channel.id] = new Channel(item.channel)
|
||||
}
|
||||
}
|
||||
channels = Object.values(channels)
|
||||
channels = _.sortBy(channels, 'xmltv_id')
|
||||
channels = _.sortBy(channels, 'id')
|
||||
programs = _.sortBy(programs, ['channel', 'start'])
|
||||
programs = programs.map(p => new Program(p))
|
||||
total += programs.length
|
||||
|
||||
const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml`
|
||||
logger.info(`Creating "${filepath}"...`)
|
||||
const output = grabber.convertToXMLTV({ channels, programs, date: CURR_DATE })
|
||||
const output = generateXMLTV({ channels, programs, date: CURR_DATE })
|
||||
await file.create(filepath, output)
|
||||
const compressed = await zip.compress(output)
|
||||
await file.create(filepath + '.gz', compressed)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const { db, logger, file, parser } = require('../../core')
|
||||
const { Program } = require('epg-grabber')
|
||||
const _ = require('lodash')
|
||||
|
||||
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
|
||||
|
@ -15,34 +16,11 @@ async function main() {
|
|||
const queue = await db.queue.find({ _id: result._qid }).limit(1)
|
||||
if (!queue.length) continue
|
||||
const item = queue[0]
|
||||
const programs = result.programs.map(program => {
|
||||
return {
|
||||
title: program.title,
|
||||
description: program.description || null,
|
||||
category: program.category || null,
|
||||
season: program.season || null,
|
||||
episode: program.episode || null,
|
||||
url: program.url || null,
|
||||
icon: program.icon || null,
|
||||
channel: program.channel,
|
||||
sub_title: program.sub_title || null,
|
||||
date: program.date || null,
|
||||
lang: program.lang,
|
||||
start: program.start,
|
||||
stop: program.stop,
|
||||
director: program.director || null,
|
||||
actor: program.actor || null,
|
||||
writer: program.writer || null,
|
||||
adapter: program.adapter || null,
|
||||
producer: program.producer || null,
|
||||
composer: program.composer || null,
|
||||
editor: program.editor || null,
|
||||
presenter: program.presenter || null,
|
||||
commentator: program.commentator || null,
|
||||
guest: program.guest || null,
|
||||
site: item.channel.site,
|
||||
_qid: result._qid
|
||||
}
|
||||
const programs = result.programs.map(p => {
|
||||
p = new Program(p)
|
||||
p._qid = result._qid
|
||||
|
||||
return p
|
||||
})
|
||||
await db.programs.insert(programs)
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ async function createQueue() {
|
|||
for (const filepath of files) {
|
||||
try {
|
||||
const dir = file.dirname(filepath)
|
||||
const { site, channels: items } = await parser.parseChannels(filepath)
|
||||
const { site, channels } = await parser.parseChannels(filepath)
|
||||
if (!site) continue
|
||||
const configPath = `${dir}/${site}.config.js`
|
||||
const config = require(file.resolve(configPath))
|
||||
|
@ -47,22 +47,16 @@ async function createQueue() {
|
|||
const filename = file.basename(filepath)
|
||||
const [__, region] = filename.match(/_([a-z-]+)\.channels\.xml/i) || [null, null]
|
||||
const groupId = `${region}/${site}`
|
||||
for (const item of items) {
|
||||
if (!item.site || !item.xmltv_id) continue
|
||||
const channel = api.channels.find({ id: item.xmltv_id })
|
||||
if (!channel) continue
|
||||
for (const channel of channels) {
|
||||
if (!channel.site || !channel.id) continue
|
||||
const found = api.channels.find({ id: channel.id })
|
||||
if (!found) continue
|
||||
for (const d of dates) {
|
||||
const dString = d.toJSON()
|
||||
const key = `${item.site}:${item.lang}:${item.xmltv_id}:${dString}`
|
||||
const key = `${channel.site}:${channel.lang}:${channel.id}:${dString}`
|
||||
if (!queue[key]) {
|
||||
queue[key] = {
|
||||
channel: {
|
||||
lang: item.lang,
|
||||
xmltv_id: item.xmltv_id,
|
||||
display_name: item.name,
|
||||
site_id: item.site_id,
|
||||
site: item.site
|
||||
},
|
||||
channel,
|
||||
date: dString,
|
||||
configPath,
|
||||
groups: [],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue