mirror of
https://github.com/iptv-org/iptv
synced 2025-12-17 19:07:37 -05:00
Add --timeout option
This commit is contained in:
@@ -30,6 +30,12 @@ program
|
|||||||
os.cpus().length
|
os.cpus().length
|
||||||
)
|
)
|
||||||
.option('-x, --proxy <url>', 'Use the specified proxy')
|
.option('-x, --proxy <url>', 'Use the specified proxy')
|
||||||
|
.option(
|
||||||
|
'-t, --timeout <number>',
|
||||||
|
'The number of milliseconds before the request will be aborted',
|
||||||
|
(value: string) => parseInt(value),
|
||||||
|
30000
|
||||||
|
)
|
||||||
.parse(process.argv)
|
.parse(process.argv)
|
||||||
|
|
||||||
const options: OptionValues = program.opts()
|
const options: OptionValues = program.opts()
|
||||||
@@ -96,7 +102,7 @@ async function runTest(stream: Stream) {
|
|||||||
const result: TestResult = await tester.test(stream)
|
const result: TestResult = await tester.test(stream)
|
||||||
|
|
||||||
let status = ''
|
let status = ''
|
||||||
const errorStatusCodes = ['HTTP_404_NOT_FOUND']
|
const errorStatusCodes = ['ENOTFOUND', 'HTTP_404_NOT_FOUND']
|
||||||
if (result.status.ok) status = chalk.green('OK')
|
if (result.status.ok) status = chalk.green('OK')
|
||||||
else if (errorStatusCodes.includes(result.status.code)) {
|
else if (errorStatusCodes.includes(result.status.code)) {
|
||||||
status = chalk.red(result.status.code)
|
status = chalk.red(result.status.code)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export type StreamTesterProps = {
|
|||||||
|
|
||||||
export class StreamTester {
|
export class StreamTester {
|
||||||
client: AxiosInstance
|
client: AxiosInstance
|
||||||
|
options: OptionValues
|
||||||
|
|
||||||
constructor({ options }: StreamTesterProps) {
|
constructor({ options }: StreamTesterProps) {
|
||||||
const proxyParser = new ProxyParser()
|
const proxyParser = new ProxyParser()
|
||||||
@@ -42,6 +43,7 @@ export class StreamTester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.client = axios.create(request)
|
this.client = axios.create(request)
|
||||||
|
this.options = options
|
||||||
}
|
}
|
||||||
|
|
||||||
async test(stream: Stream): Promise<TestResult> {
|
async test(stream: Stream): Promise<TestResult> {
|
||||||
@@ -51,10 +53,8 @@ export class StreamTester {
|
|||||||
return results[stream.url as keyof typeof results]
|
return results[stream.url as keyof typeof results]
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const timeout = 10000
|
|
||||||
|
|
||||||
const res = await this.client(stream.url, {
|
const res = await this.client(stream.url, {
|
||||||
signal: AbortSignal.timeout(timeout),
|
signal: AbortSignal.timeout(this.options.timeout),
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': stream.getUserAgent() || 'Mozilla/5.0',
|
'User-Agent': stream.getUserAgent() || 'Mozilla/5.0',
|
||||||
Referer: stream.getReferrer()
|
Referer: stream.getReferrer()
|
||||||
|
|||||||
Reference in New Issue
Block a user