mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Create channels.js
This commit is contained in:
parent
c74e4b8641
commit
1a8248fe92
1 changed files with 34 additions and 0 deletions
34
scripts/channels.js
Normal file
34
scripts/channels.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
const { Command } = require('commander')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
const { json2xml } = require('./utils')
|
||||||
|
|
||||||
|
const program = new Command()
|
||||||
|
program
|
||||||
|
.requiredOption('-c, --config <config>', 'Config file')
|
||||||
|
.option('-o, --output <output>', 'Output file')
|
||||||
|
.parse(process.argv)
|
||||||
|
|
||||||
|
const options = program.opts()
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const config = require(path.resolve(options.config))
|
||||||
|
let channels = config.channels()
|
||||||
|
if (isPromise(channels)) {
|
||||||
|
channels = await channels
|
||||||
|
}
|
||||||
|
const xml = json2xml(channels, config.site)
|
||||||
|
|
||||||
|
const dir = path.parse(options.config).dir
|
||||||
|
const output = options.output || `${dir}/${config.site}.channels.xml`
|
||||||
|
|
||||||
|
fs.writeFileSync(path.resolve(output), xml)
|
||||||
|
|
||||||
|
console.log(`File '${output}' successfully saved`)
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
||||||
|
function isPromise(promise) {
|
||||||
|
return !!promise && typeof promise.then === 'function'
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue