mirror of
https://github.com/iptv-org/epg
synced 2026-04-21 18:17:01 -04:00
Update grab.ts
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { loadJs, parseProxy, parseNumber, parseList } from '../../core'
|
||||
import { Logger, Timer, Collection, Template } from '@freearhey/core'
|
||||
import epgGrabber, { EPGGrabber, EPGGrabberMock } from 'epg-grabber'
|
||||
import { loadJs, parseProxy, parseNumber } from '../../core'
|
||||
import { CurlBody } from 'curl-generator/dist/bodies/body'
|
||||
import { Channel, Guide, Program } from '../../models'
|
||||
import { SocksProxyAgent } from 'socks-proxy-agent'
|
||||
@@ -17,11 +17,16 @@ import merge from 'lodash.merge'
|
||||
import path from 'path'
|
||||
|
||||
program
|
||||
.addOption(new Option('-s, --site <name>', 'Name of the site to parse'))
|
||||
.addOption(
|
||||
new Option(
|
||||
'-s, --sites <names>',
|
||||
'A comma-separated list of the site names to parse'
|
||||
).argParser(parseList)
|
||||
)
|
||||
.addOption(
|
||||
new Option(
|
||||
'-c, --channels <path>',
|
||||
'Path to *.channels.xml file (required if the "--site" attribute is not specified)'
|
||||
'Path to *.channels.xml file (required if the "--sites" attribute is not specified)'
|
||||
)
|
||||
)
|
||||
.addOption(new Option('-o, --output <path>', 'Path to output file'))
|
||||
@@ -56,7 +61,7 @@ program
|
||||
.parse()
|
||||
|
||||
interface GrabOptions {
|
||||
site?: string
|
||||
sites?: string[]
|
||||
channels?: string
|
||||
output?: string
|
||||
gzip?: boolean
|
||||
@@ -73,8 +78,8 @@ interface GrabOptions {
|
||||
const options: GrabOptions = program.opts()
|
||||
|
||||
async function main() {
|
||||
if (typeof options.site !== 'string' && typeof options.channels !== 'string')
|
||||
throw new Error('One of the arguments must be presented: `--site` or `--channels`')
|
||||
if (!Array.isArray(options.sites) && typeof options.channels !== 'string')
|
||||
throw new Error('One of the arguments must be presented: `--sites` or `--channels`')
|
||||
|
||||
const LOG_LEVELS = { info: 3, debug: 4 }
|
||||
const logger = new Logger({ level: options.debug ? LOG_LEVELS['debug'] : LOG_LEVELS['info'] })
|
||||
@@ -154,10 +159,15 @@ async function main() {
|
||||
const storage = new Storage()
|
||||
|
||||
let files: string[] = []
|
||||
if (typeof options.site === 'string') {
|
||||
let pattern = path.join(SITES_DIR, options.site, '*.channels.xml')
|
||||
pattern = pattern.replace(/\\/g, '/')
|
||||
files = await storage.list(pattern)
|
||||
if (Array.isArray(options.sites)) {
|
||||
for (const site of options.sites) {
|
||||
let pattern = path.join(SITES_DIR, site, '*.channels.xml')
|
||||
pattern = pattern.replace(/\\/g, '/')
|
||||
const foundFiles = await storage.list(pattern)
|
||||
foundFiles.forEach((filepath: string) => {
|
||||
files.push(filepath)
|
||||
})
|
||||
}
|
||||
} else if (typeof options.channels === 'string') {
|
||||
files = await storage.list(options.channels)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user