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) {
|
for (const channel of channels) {
|
||||||
guides.push({
|
guides.push({
|
||||||
channel: channel.xmltv_id,
|
channel: channel.id,
|
||||||
site,
|
site: channel.site,
|
||||||
lang: channel.lang,
|
lang: channel.lang,
|
||||||
url: `https://iptv-org.github.io/epg/guides/${suffix}/${site}.epg.xml`
|
url: `https://iptv-org.github.io/epg/guides/${suffix}/${site}.epg.xml`
|
||||||
})
|
})
|
||||||
|
|
|
@ -24,15 +24,15 @@ async function main() {
|
||||||
const buffer = {}
|
const buffer = {}
|
||||||
const errors = []
|
const errors = []
|
||||||
for (const channel of channels) {
|
for (const channel of channels) {
|
||||||
if (!buffer[channel.xmltv_id]) {
|
if (!buffer[channel.id]) {
|
||||||
buffer[channel.xmltv_id] = channel
|
buffer[channel.id] = channel
|
||||||
} else {
|
} else {
|
||||||
errors.push({ type: 'duplicate', ...channel })
|
errors.push({ type: 'duplicate', xmltv_id: channel.id, ...channel })
|
||||||
stats.errors++
|
stats.errors++
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!api.channels.find({ id: channel.xmltv_id })) {
|
if (!api.channels.find({ id: channel.id })) {
|
||||||
errors.push({ type: 'wrong_xmltv_id', ...channel })
|
errors.push({ type: 'wrong_xmltv_id', xmltv_id: channel.id, ...channel })
|
||||||
stats.errors++
|
stats.errors++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
const EPGGrabber = require('epg-grabber')
|
const { EPGGrabber } = require('epg-grabber')
|
||||||
const { program } = require('commander')
|
const { program } = require('commander')
|
||||||
const { db, logger, timer, file, parser } = require('../../core')
|
const { db, logger, timer, file, parser } = require('../../core')
|
||||||
|
const dayjs = require('dayjs')
|
||||||
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
|
||||||
|
dayjs.extend(utc)
|
||||||
|
|
||||||
const options = program
|
const options = program
|
||||||
.requiredOption('-c, --cluster-id <cluster-id>', 'The ID of cluster to load', parser.parseNumber)
|
.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 file.create(CLUSTER_PATH)
|
||||||
await db.queue.load()
|
await db.queue.load()
|
||||||
let items = await db.queue.find({ cluster_id: options.clusterId })
|
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
|
const total = items.length
|
||||||
|
|
||||||
logger.info('Loading...')
|
logger.info('Loading...')
|
||||||
|
@ -45,9 +49,9 @@ async function main() {
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
await grabber.grab(item.channel, item.date, async (data, err) => {
|
await grabber.grab(item.channel, item.date, async (data, err) => {
|
||||||
logger.info(
|
logger.info(
|
||||||
`[${i}/${total}] ${item.channel.site} (${item.channel.lang}) - ${
|
`[${i}/${total}] ${item.channel.site} (${item.channel.lang}) - ${item.channel.id} - ${dayjs
|
||||||
item.channel.xmltv_id
|
.utc(data.date)
|
||||||
} - ${data.date.format('MMM D, YYYY')} (${data.programs.length} programs)`
|
.format('MMM D, YYYY')} (${data.programs.length} programs)`
|
||||||
)
|
)
|
||||||
|
|
||||||
if (err) logger.error(err.message)
|
if (err) logger.error(err.message)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const { db, logger, file, api, zip } = require('../../core')
|
const { db, logger, file, api, zip } = require('../../core')
|
||||||
const grabber = require('epg-grabber')
|
const { generateXMLTV, Program, Channel } = require('epg-grabber')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
|
||||||
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages'
|
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages'
|
||||||
|
@ -23,25 +23,21 @@ async function main() {
|
||||||
const itemPrograms = await loadProgramsForItem(item)
|
const itemPrograms = await loadProgramsForItem(item)
|
||||||
programs = programs.concat(itemPrograms)
|
programs = programs.concat(itemPrograms)
|
||||||
|
|
||||||
if (channels[item.channel.xmltv_id]) continue
|
if (channels[item.channel.id]) continue
|
||||||
const channel = api.channels.find({ id: item.channel.xmltv_id })
|
const found = api.channels.find({ id: item.channel.id })
|
||||||
if (channel) {
|
if (found) {
|
||||||
channels[channel.id] = {
|
channels[item.channel.id] = new Channel(item.channel)
|
||||||
xmltv_id: channel.id,
|
|
||||||
name: item.channel.display_name,
|
|
||||||
logo: channel.logo,
|
|
||||||
site: item.channel.site
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
channels = Object.values(channels)
|
channels = Object.values(channels)
|
||||||
channels = _.sortBy(channels, 'xmltv_id')
|
channels = _.sortBy(channels, 'id')
|
||||||
programs = _.sortBy(programs, ['channel', 'start'])
|
programs = _.sortBy(programs, ['channel', 'start'])
|
||||||
|
programs = programs.map(p => new Program(p))
|
||||||
total += programs.length
|
total += programs.length
|
||||||
|
|
||||||
const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml`
|
const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml`
|
||||||
logger.info(`Creating "${filepath}"...`)
|
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)
|
await file.create(filepath, output)
|
||||||
const compressed = await zip.compress(output)
|
const compressed = await zip.compress(output)
|
||||||
await file.create(filepath + '.gz', compressed)
|
await file.create(filepath + '.gz', compressed)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const { db, logger, file, parser } = require('../../core')
|
const { db, logger, file, parser } = require('../../core')
|
||||||
|
const { Program } = require('epg-grabber')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
|
||||||
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
|
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)
|
const queue = await db.queue.find({ _id: result._qid }).limit(1)
|
||||||
if (!queue.length) continue
|
if (!queue.length) continue
|
||||||
const item = queue[0]
|
const item = queue[0]
|
||||||
const programs = result.programs.map(program => {
|
const programs = result.programs.map(p => {
|
||||||
return {
|
p = new Program(p)
|
||||||
title: program.title,
|
p._qid = result._qid
|
||||||
description: program.description || null,
|
|
||||||
category: program.category || null,
|
return p
|
||||||
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
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
await db.programs.insert(programs)
|
await db.programs.insert(programs)
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ async function createQueue() {
|
||||||
for (const filepath of files) {
|
for (const filepath of files) {
|
||||||
try {
|
try {
|
||||||
const dir = file.dirname(filepath)
|
const dir = file.dirname(filepath)
|
||||||
const { site, channels: items } = await parser.parseChannels(filepath)
|
const { site, channels } = await parser.parseChannels(filepath)
|
||||||
if (!site) continue
|
if (!site) continue
|
||||||
const configPath = `${dir}/${site}.config.js`
|
const configPath = `${dir}/${site}.config.js`
|
||||||
const config = require(file.resolve(configPath))
|
const config = require(file.resolve(configPath))
|
||||||
|
@ -47,22 +47,16 @@ async function createQueue() {
|
||||||
const filename = file.basename(filepath)
|
const filename = file.basename(filepath)
|
||||||
const [__, region] = filename.match(/_([a-z-]+)\.channels\.xml/i) || [null, null]
|
const [__, region] = filename.match(/_([a-z-]+)\.channels\.xml/i) || [null, null]
|
||||||
const groupId = `${region}/${site}`
|
const groupId = `${region}/${site}`
|
||||||
for (const item of items) {
|
for (const channel of channels) {
|
||||||
if (!item.site || !item.xmltv_id) continue
|
if (!channel.site || !channel.id) continue
|
||||||
const channel = api.channels.find({ id: item.xmltv_id })
|
const found = api.channels.find({ id: channel.id })
|
||||||
if (!channel) continue
|
if (!found) continue
|
||||||
for (const d of dates) {
|
for (const d of dates) {
|
||||||
const dString = d.toJSON()
|
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]) {
|
if (!queue[key]) {
|
||||||
queue[key] = {
|
queue[key] = {
|
||||||
channel: {
|
channel,
|
||||||
lang: item.lang,
|
|
||||||
xmltv_id: item.xmltv_id,
|
|
||||||
display_name: item.name,
|
|
||||||
site_id: item.site_id,
|
|
||||||
site: item.site
|
|
||||||
},
|
|
||||||
date: dString,
|
date: dString,
|
||||||
configPath,
|
configPath,
|
||||||
groups: [],
|
groups: [],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue