wip
This commit is contained in:
@@ -16,8 +16,8 @@ program
|
||||
.name('epg-grabber')
|
||||
.description('EPG grabber')
|
||||
.usage('[options] [file-or-url]')
|
||||
.option('-c, --config <config>', 'Path to config.xml file', './config.xml')
|
||||
.option('-s, --sites <sites>', 'Path to /sites folder', './sites')
|
||||
.option('-c, --config <config>', 'Path to [site].config.xml file', './')
|
||||
.option('-s, --sites <sites>', 'Path to sites folder', './sites')
|
||||
.parse(process.argv)
|
||||
|
||||
const options = program.opts()
|
||||
@@ -31,6 +31,8 @@ const client = axios.create({
|
||||
})
|
||||
|
||||
async function main() {
|
||||
console.log('\r\nStarting...')
|
||||
console.log(`Loading '${options.config}'...`)
|
||||
const d = dayjs.utc()
|
||||
const dates = Array.from({ length: config.days }, (_, i) => d.add(i, 'd'))
|
||||
const channels = config.channels
|
||||
@@ -46,6 +48,7 @@ async function main() {
|
||||
})
|
||||
})
|
||||
|
||||
console.log('Parsing:')
|
||||
let programs = []
|
||||
for (let request of requests) {
|
||||
const progs = await client
|
||||
@@ -53,13 +56,16 @@ async function main() {
|
||||
.then(response => {
|
||||
const channel = request.channel
|
||||
const site = sites[channel.site]
|
||||
console.log(`${channel.site} - ${channel.xmltv_id}`)
|
||||
|
||||
return site.parser({
|
||||
const programs = site.parser({
|
||||
channel,
|
||||
content: response.data,
|
||||
date: request.date
|
||||
})
|
||||
|
||||
console.log(` ${channel.site} - ${channel.xmltv_id} (${programs.length} programs)`)
|
||||
|
||||
return programs
|
||||
})
|
||||
.then(utils.sleep(3000))
|
||||
.catch(console.log)
|
||||
@@ -68,7 +74,10 @@ async function main() {
|
||||
}
|
||||
|
||||
const xml = utils.convertToXMLTV({ channels, programs })
|
||||
fs.writeFileSync(path.resolve(__dirname, config.filename), xml)
|
||||
utils.createDir(path.dirname(config.filename))
|
||||
utils.writeToFile(config.filename, xml)
|
||||
console.log(`File '${config.filename}' successfully updated`)
|
||||
console.log('Finish')
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
@@ -84,4 +84,14 @@ utils.sleep = function (ms) {
|
||||
}
|
||||
}
|
||||
|
||||
utils.createDir = function (dir) {
|
||||
if (!fs.existsSync(path.resolve(__dirname, dir))) {
|
||||
fs.mkdirSync(path.resolve(__dirname, dir))
|
||||
}
|
||||
}
|
||||
|
||||
utils.writeToFile = function (filename, data) {
|
||||
fs.writeFileSync(path.resolve(__dirname, filename), data)
|
||||
}
|
||||
|
||||
module.exports = utils
|
||||
|
||||
Reference in New Issue
Block a user