mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Merge branch 'master' into fix-deploy
This commit is contained in:
commit
3bf8e54dae
18 changed files with 149 additions and 212 deletions
|
@ -16,11 +16,21 @@ async function main() {
|
|||
await db.channels.update({ _id: result._id }, { $set: { logo: result.logo } })
|
||||
|
||||
const programs = result.programs.map(program => {
|
||||
program.site = result.site
|
||||
program.country = result.country
|
||||
program.gid = result.gid
|
||||
|
||||
return program
|
||||
return {
|
||||
title: program.title,
|
||||
description: program.description || null,
|
||||
category: program.category || [],
|
||||
season: program.season || null,
|
||||
episode: program.episode || null,
|
||||
icon: program.icon || null,
|
||||
channel: program.channel,
|
||||
lang: program.lang,
|
||||
start: program.start,
|
||||
stop: program.stop,
|
||||
site: result.site,
|
||||
country: result.country,
|
||||
gid: result.gid
|
||||
}
|
||||
})
|
||||
|
||||
await db.programs.insert(programs)
|
||||
|
|
|
@ -50,6 +50,8 @@ async function loadPrograms() {
|
|||
title: item.title,
|
||||
desc: item.description || null,
|
||||
categories: item.category || [],
|
||||
season: item.season || null,
|
||||
episode: item.episode || null,
|
||||
image: item.icon || null,
|
||||
start: item.start,
|
||||
stop: item.stop
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const { db, logger, file, xml } = require('../core')
|
||||
const { db, logger, file } = require('../core')
|
||||
const grabber = require('epg-grabber')
|
||||
const _ = require('lodash')
|
||||
|
||||
const DB_DIR = process.env.DB_DIR || 'scripts/database'
|
||||
|
@ -32,7 +33,7 @@ async function generateGuides() {
|
|||
}
|
||||
)
|
||||
|
||||
const output = xml.create({ channels: groupChannels, programs: groupProgs })
|
||||
const output = grabber.convertToXMLTV({ channels: groupChannels, programs: groupProgs })
|
||||
|
||||
logger.info(`Creating "${filepath}"...`)
|
||||
await file.create(filepath, output)
|
||||
|
@ -67,9 +68,9 @@ async function loadPrograms() {
|
|||
|
||||
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 }] : [],
|
||||
title: program.title,
|
||||
description: program.description,
|
||||
categories: program.category,
|
||||
icon: program.icon,
|
||||
channel: program.channel,
|
||||
lang: program.lang,
|
||||
|
@ -77,6 +78,8 @@ async function loadPrograms() {
|
|||
stop: program.stop,
|
||||
site: program.site,
|
||||
country: program.country,
|
||||
season: program.season,
|
||||
episode: program.episode,
|
||||
gid: program.gid,
|
||||
_id: program._id
|
||||
}
|
||||
|
|
|
@ -3,5 +3,4 @@ exports.logger = require('./logger')
|
|||
exports.file = require('./file')
|
||||
exports.parser = require('./parser')
|
||||
exports.timer = require('./timer')
|
||||
exports.xml = require('./xml')
|
||||
exports.markdown = require('./markdown')
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
dayjs.extend(utc)
|
||||
|
||||
const xml = {}
|
||||
|
||||
xml.create = function ({ channels, programs }) {
|
||||
let output = `<?xml version="1.0" encoding="UTF-8" ?><tv>\n`
|
||||
for (let channel of channels) {
|
||||
output += `<channel id="${escapeString(channel.xmltv_id)}">`
|
||||
output += `<display-name>${escapeString(channel.name)}</display-name>`
|
||||
if (channel.logo) output += `<icon src="${escapeString(channel.logo)}"/>`
|
||||
if (channel.site) output += `<url>https://${channel.site}</url>`
|
||||
output += `</channel>\n`
|
||||
}
|
||||
|
||||
for (let program of programs) {
|
||||
if (!program) continue
|
||||
|
||||
const start = program.start ? dayjs.unix(program.start).utc().format('YYYYMMDDHHmmss ZZ') : ''
|
||||
const stop = program.stop ? dayjs.unix(program.stop).utc().format('YYYYMMDDHHmmss ZZ') : ''
|
||||
|
||||
if (start && stop) {
|
||||
output += `<programme start="${start}" stop="${stop}" channel="${escapeString(
|
||||
program.channel
|
||||
)}">`
|
||||
|
||||
program.title.forEach(title => {
|
||||
output += `<title lang="${title.lang}">${escapeString(title.value)}</title>`
|
||||
})
|
||||
|
||||
program.description.forEach(description => {
|
||||
output += `<desc lang="${description.lang}">${escapeString(description.value)}</desc>`
|
||||
})
|
||||
|
||||
program.categories.forEach(category => {
|
||||
output += `<category lang="${category.lang}">${escapeString(category.value)}</category>`
|
||||
})
|
||||
|
||||
if (program.image) output += `<icon src="${escapeString(program.image)}"/>`
|
||||
|
||||
output += '</programme>\n'
|
||||
}
|
||||
}
|
||||
|
||||
output += '</tv>'
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
module.exports = xml
|
||||
|
||||
function escapeString(string, defaultValue = '') {
|
||||
if (!string) return defaultValue
|
||||
|
||||
const regex = new RegExp(
|
||||
'((?:[\0-\x08\x0B\f\x0E-\x1F\uFFFD\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))|([\\x7F-\\x84]|[\\x86-\\x9F]|[\\uFDD0-\\uFDEF]|(?:\\uD83F[\\uDFFE\\uDFFF])|(?:\\uD87F[\\uDF' +
|
||||
'FE\\uDFFF])|(?:\\uD8BF[\\uDFFE\\uDFFF])|(?:\\uD8FF[\\uDFFE\\uDFFF])|(?:\\uD93F[\\uDFFE\\uD' +
|
||||
'FFF])|(?:\\uD97F[\\uDFFE\\uDFFF])|(?:\\uD9BF[\\uDFFE\\uDFFF])|(?:\\uD9FF[\\uDFFE\\uDFFF])' +
|
||||
'|(?:\\uDA3F[\\uDFFE\\uDFFF])|(?:\\uDA7F[\\uDFFE\\uDFFF])|(?:\\uDABF[\\uDFFE\\uDFFF])|(?:\\' +
|
||||
'uDAFF[\\uDFFE\\uDFFF])|(?:\\uDB3F[\\uDFFE\\uDFFF])|(?:\\uDB7F[\\uDFFE\\uDFFF])|(?:\\uDBBF' +
|
||||
'[\\uDFFE\\uDFFF])|(?:\\uDBFF[\\uDFFE\\uDFFF])(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\' +
|
||||
'uE000-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|' +
|
||||
'(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]))',
|
||||
'g'
|
||||
)
|
||||
|
||||
string = String(string || '').replace(regex, '')
|
||||
|
||||
return string
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/\n|\r/g, ' ')
|
||||
.replace(/ +/g, ' ')
|
||||
.trim()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue