mirror of
https://github.com/iptv-org/epg
synced 2026-05-07 09:57:06 -04:00
@@ -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,15 @@ 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 sites 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 +60,7 @@ program
|
||||
.parse()
|
||||
|
||||
interface GrabOptions {
|
||||
site?: string
|
||||
sites?: string[]
|
||||
channels?: string
|
||||
output?: string
|
||||
gzip?: boolean
|
||||
@@ -73,8 +77,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 +158,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)
|
||||
}
|
||||
|
||||
@@ -110,3 +110,7 @@ export async function loadIssues(props?: { labels: string[] | string }) {
|
||||
export function parseNumber(value: string): number {
|
||||
return parseInt(value)
|
||||
}
|
||||
|
||||
export function parseList(value: string): string[] {
|
||||
return value.split(',')
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ https://<DOMAIN>
|
||||
### Download the guide
|
||||
|
||||
```sh
|
||||
npm run grab --- --site=<DOMAIN>
|
||||
npm run grab --- --sites=<DOMAIN>
|
||||
```
|
||||
|
||||
### Update channel list
|
||||
|
||||
Reference in New Issue
Block a user