mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
wip
This commit is contained in:
parent
ce525ed13c
commit
b9ab8ee78e
10 changed files with 126 additions and 3030 deletions
4
scripts/.gitignore
vendored
4
scripts/.gitignore
vendored
|
@ -1,2 +1,2 @@
|
|||
edit.js
|
||||
channels.db
|
||||
database/
|
||||
logs/
|
|
@ -1,7 +1,6 @@
|
|||
const { Command } = require('commander')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { json2xml } = require('./utils')
|
||||
|
||||
const program = new Command()
|
||||
program
|
||||
|
@ -44,3 +43,51 @@ main()
|
|||
function isPromise(promise) {
|
||||
return !!promise && typeof promise.then === 'function'
|
||||
}
|
||||
|
||||
function json2xml(items, site) {
|
||||
let output = `<?xml version="1.0" encoding="UTF-8"?>\r\n<site site="${site}">\r\n <channels>\r\n`
|
||||
|
||||
items.forEach(channel => {
|
||||
const logo = channel.logo ? ` logo="${channel.logo}"` : ''
|
||||
const xmltv_id = channel.xmltv_id || ''
|
||||
const lang = channel.lang || ''
|
||||
const site_id = channel.site_id || ''
|
||||
output += ` <channel lang="${lang}" xmltv_id="${escapeString(
|
||||
xmltv_id
|
||||
)}" site_id="${site_id}"${logo}>${escapeString(channel.name)}</channel>\r\n`
|
||||
})
|
||||
|
||||
output += ` </channels>\r\n</site>\r\n`
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
module.exports = { json2xml }
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
const { Command } = require('commander')
|
||||
const file = require('./file')
|
||||
const path = require('path')
|
||||
|
||||
const program = new Command()
|
||||
program
|
||||
.option('--include <include>', 'List of files to include', parseList)
|
||||
.option('--exclude <exclude>', 'List of files to exclude', parseList)
|
||||
.parse(process.argv)
|
||||
|
||||
const options = program.opts()
|
||||
|
||||
file.list('sites/*/*.channels.xml', options.include, options.exclude).then(files => {
|
||||
const matrix = {
|
||||
guide: []
|
||||
}
|
||||
|
||||
files.forEach(filename => {
|
||||
const [_, site, country] = filename.match(/sites\/.*\/(.*)_(.*)\.channels\.xml/i)
|
||||
const config = require(path.resolve(`./sites/${site}/${site}.config.js`))
|
||||
|
||||
if (config.ignore) return
|
||||
|
||||
matrix.guide.push({ site, country })
|
||||
})
|
||||
|
||||
const output = `::set-output name=matrix::${JSON.stringify(matrix)}`
|
||||
console.log(output)
|
||||
})
|
||||
|
||||
function parseList(str) {
|
||||
if (!str) return []
|
||||
|
||||
return str.split(',')
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,46 +0,0 @@
|
|||
const glob = require('glob')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const wcmatch = require('wildcard-match')
|
||||
|
||||
function list(pattern, include = [], exclude = []) {
|
||||
return new Promise(resolve => {
|
||||
glob(pattern, function (err, files) {
|
||||
if (include.length) {
|
||||
files = files.filter(filename => include.some(item => wcmatch(item)(filename)))
|
||||
}
|
||||
|
||||
if (exclude.length) {
|
||||
files = files.filter(filename => !exclude.some(item => wcmatch(item)(filename)))
|
||||
}
|
||||
|
||||
resolve(files)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function load(filename) {
|
||||
const filePath = path.resolve(filename)
|
||||
|
||||
return require(filePath)
|
||||
}
|
||||
|
||||
function read(filename) {
|
||||
return fs.readFileSync(filename, { encoding: 'utf8' })
|
||||
}
|
||||
|
||||
function write(filename, data) {
|
||||
const dir = path.resolve(path.dirname(filename))
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true })
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.resolve(filename), data)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
list,
|
||||
read,
|
||||
write,
|
||||
load
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
function json2xml(items, site) {
|
||||
let output = `<?xml version="1.0" encoding="UTF-8"?>\r\n<site site="${site}">\r\n <channels>\r\n`
|
||||
|
||||
items.forEach(channel => {
|
||||
const logo = channel.logo ? ` logo="${channel.logo}"` : ''
|
||||
const xmltv_id = channel.xmltv_id || ''
|
||||
const lang = channel.lang || ''
|
||||
const site_id = channel.site_id || ''
|
||||
output += ` <channel lang="${lang}" xmltv_id="${escapeString(
|
||||
xmltv_id
|
||||
)}" site_id="${site_id}"${logo}>${escapeString(channel.name)}</channel>\r\n`
|
||||
})
|
||||
|
||||
output += ` </channels>\r\n</site>\r\n`
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
module.exports = { json2xml }
|
Loading…
Add table
Add a link
Reference in a new issue