mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 01:20:08 -04:00
wip
This commit is contained in:
parent
594197954e
commit
b9be8e9d33
15 changed files with 1046 additions and 1540 deletions
|
@ -1,56 +1,32 @@
|
|||
#! /usr/bin/env node
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const axios = require('axios')
|
||||
const axiosCookieJarSupport = require('axios-cookiejar-support').default
|
||||
const tough = require('tough-cookie')
|
||||
const utils = require('./utils')
|
||||
const { Command } = require('commander')
|
||||
const program = new Command()
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.tz.setDefault('UTC')
|
||||
|
||||
axiosCookieJarSupport(axios)
|
||||
|
||||
const cookieJar = new tough.CookieJar()
|
||||
const utils = require('./utils')
|
||||
|
||||
program
|
||||
.version('0.1.0', '-v, --version')
|
||||
.name('epg-grabber')
|
||||
.description('EPG grabber')
|
||||
.usage('[options] [file-or-url]')
|
||||
.option('-c, --config <config>', 'Path to [site].config.xml file', './')
|
||||
.option('-s, --sites <sites>', 'Path to sites folder', './sites')
|
||||
.option('-c, --config <config>', 'Path to [site].config.js file')
|
||||
.parse(process.argv)
|
||||
|
||||
const options = program.opts()
|
||||
|
||||
const config = utils.parseConfig(options.config)
|
||||
const sites = utils.loadSites(options.sites)
|
||||
|
||||
const client = axios.create({
|
||||
headers: { 'User-Agent': config.userAgent, Cookie: config.cookie },
|
||||
withCredentials: true,
|
||||
jar: cookieJar
|
||||
})
|
||||
|
||||
async function main() {
|
||||
console.log('\r\nStarting...')
|
||||
console.log(`Loading '${options.config}'...`)
|
||||
const d = dayjs.utc()
|
||||
|
||||
const config = utils.loadConfig(options.config)
|
||||
const client = utils.createHttpClient(config)
|
||||
const channels = utils.parseChannels(config.channels)
|
||||
|
||||
const d = utils.getUTCDate()
|
||||
const dates = Array.from({ length: config.days }, (_, i) => d.add(i, 'd'))
|
||||
const channels = config.channels
|
||||
const requests = []
|
||||
const queue = []
|
||||
channels.forEach(channel => {
|
||||
const site = sites[channel.site]
|
||||
dates.forEach(date => {
|
||||
requests.push({
|
||||
url: site.url({ date, channel }),
|
||||
queue.push({
|
||||
url: config.url({ date, channel }),
|
||||
date,
|
||||
channel
|
||||
})
|
||||
|
@ -59,27 +35,17 @@ async function main() {
|
|||
|
||||
console.log('Parsing:')
|
||||
let programs = []
|
||||
for (let request of requests) {
|
||||
for (let item of queue) {
|
||||
const progs = await client
|
||||
.get(request.url)
|
||||
.get(item.url)
|
||||
.then(response => {
|
||||
const channel = request.channel
|
||||
const site = sites[channel.site]
|
||||
const date = request.date
|
||||
|
||||
const programs = site
|
||||
.parser({
|
||||
channel,
|
||||
content: response.data,
|
||||
date,
|
||||
lang: config.lang || 'en'
|
||||
})
|
||||
.filter(p => p)
|
||||
const parserOptions = Object.assign({}, item, config, { content: response.data })
|
||||
const programs = config.parser(parserOptions).filter(i => i)
|
||||
|
||||
console.log(
|
||||
` ${channel.site} - ${channel.xmltv_id} - ${date.format('MMM D, YYYY')} (${
|
||||
programs.length
|
||||
} programs)`
|
||||
` ${item.channel.site} - ${item.channel.xmltv_id} - ${item.date.format(
|
||||
'MMM D, YYYY'
|
||||
)} (${programs.length} programs)`
|
||||
)
|
||||
|
||||
return programs
|
||||
|
@ -91,9 +57,11 @@ async function main() {
|
|||
}
|
||||
|
||||
const xml = utils.convertToXMLTV({ config, channels, programs })
|
||||
utils.createDir(path.dirname(config.filename))
|
||||
utils.writeToFile(config.filename, xml)
|
||||
console.log(`File '${config.filename}' successfully updated`)
|
||||
const outputDir = utils.getDirectory(config.output)
|
||||
utils.createDir(outputDir)
|
||||
utils.writeToFile(config.output, xml)
|
||||
|
||||
console.log(`File '${config.output}' successfully saved`)
|
||||
console.log('Finish\r\n')
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue