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