mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 08:30:06 -04:00
Update grabber.ts
This commit is contained in:
parent
b8c50654f6
commit
d15b21bfd3
1 changed files with 22 additions and 1 deletions
|
@ -1,8 +1,9 @@
|
||||||
import { EPGGrabber, GrabCallbackData, EPGGrabberMock, SiteConfig, Channel } from 'epg-grabber'
|
import { EPGGrabber, GrabCallbackData, EPGGrabberMock, SiteConfig, Channel } from 'epg-grabber'
|
||||||
import { Logger, Collection } from '@freearhey/core'
|
import { Logger, Collection } from '@freearhey/core'
|
||||||
import { Queue } from './'
|
import { Queue, ProxyParser } from './'
|
||||||
import { GrabOptions } from '../commands/epg/grab'
|
import { GrabOptions } from '../commands/epg/grab'
|
||||||
import { TaskQueue, PromisyClass } from 'cwait'
|
import { TaskQueue, PromisyClass } from 'cwait'
|
||||||
|
import { SocksProxyAgent } from 'socks-proxy-agent'
|
||||||
|
|
||||||
type GrabberProps = {
|
type GrabberProps = {
|
||||||
logger: Logger
|
logger: Logger
|
||||||
|
@ -14,6 +15,7 @@ export class Grabber {
|
||||||
logger: Logger
|
logger: Logger
|
||||||
queue: Queue
|
queue: Queue
|
||||||
options: GrabOptions
|
options: GrabOptions
|
||||||
|
grabber: EPGGrabber | EPGGrabberMock
|
||||||
|
|
||||||
constructor({ logger, queue, options }: GrabberProps) {
|
constructor({ logger, queue, options }: GrabberProps) {
|
||||||
this.logger = logger
|
this.logger = logger
|
||||||
|
@ -23,6 +25,7 @@ export class Grabber {
|
||||||
}
|
}
|
||||||
|
|
||||||
async grab(): Promise<{ channels: Collection; programs: Collection }> {
|
async grab(): Promise<{ channels: Collection; programs: Collection }> {
|
||||||
|
const proxyParser = new ProxyParser()
|
||||||
const taskQueue = new TaskQueue(Promise as PromisyClass, this.options.maxConnections)
|
const taskQueue = new TaskQueue(Promise as PromisyClass, this.options.maxConnections)
|
||||||
|
|
||||||
const total = this.queue.size()
|
const total = this.queue.size()
|
||||||
|
@ -49,6 +52,24 @@ export class Grabber {
|
||||||
config.delay = delay
|
config.delay = delay
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.options.proxy !== undefined) {
|
||||||
|
const proxy = proxyParser.parse(this.options.proxy)
|
||||||
|
|
||||||
|
if (
|
||||||
|
proxy.protocol &&
|
||||||
|
['socks', 'socks5', 'socks5h', 'socks4', 'socks4a'].includes(String(proxy.protocol))
|
||||||
|
) {
|
||||||
|
const socksProxyAgent = new SocksProxyAgent(this.options.proxy)
|
||||||
|
|
||||||
|
config.request = {
|
||||||
|
...config.request,
|
||||||
|
...{ httpAgent: socksProxyAgent, httpsAgent: socksProxyAgent }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
config.request = { ...config.request, ...{ proxy } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const _programs = await this.grabber.grab(
|
const _programs = await this.grabber.grab(
|
||||||
channel,
|
channel,
|
||||||
date,
|
date,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue