From e8839b0cbd4e3f0438c94ff51f0f395f328219e3 Mon Sep 17 00:00:00 2001 From: renxia Date: Thu, 6 Jul 2023 14:33:09 +0800 Subject: [PATCH] =?UTF-8?q?wip:=20http=20=E8=AF=B7=E6=B1=82=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=97=B6=E6=89=93=E5=8D=B0=E5=85=B7=E4=BD=93=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/parseM3u8.ts | 4 ++++ src/lib/ts-download.ts | 3 ++- src/lib/utils.ts | 10 +++++++++- src/lib/worker_pool.ts | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lib/parseM3u8.ts b/src/lib/parseM3u8.ts index f2e4512..209dd29 100644 --- a/src/lib/parseM3u8.ts +++ b/src/lib/parseM3u8.ts @@ -14,6 +14,10 @@ export async function parseM3U8(content: string, url = process.cwd(), cacheDir = } } + if (!content) { + logger.error('获取播放列表为空!', url); + } + logger.debug('starting parsing m3u8 file:', url); let parser = new Parser(); diff --git a/src/lib/ts-download.ts b/src/lib/ts-download.ts index 1f59f28..2bc5789 100644 --- a/src/lib/ts-download.ts +++ b/src/lib/ts-download.ts @@ -25,7 +25,7 @@ export async function tsDownload(info: TsItemInfo, cryptoInfo: M3u8Crypto) { logger.warn('[TS-Download][failed]', r.response.statusCode, info.uri); } catch (e) { - logger.error('[TS-Download][error]', (e as Error).message || e); + logger.error('[TS-Download][error]', (e as Error)?.message || e || 'unkown'); } return false; @@ -39,6 +39,7 @@ function aesDecrypt(data: Buffer, cryptoInfo: M3u8Crypto) { if (!isMainThread && parentPort) { parentPort.on('message', (data: WorkerTaskInfo) => { + if (data.options.debug) logger.updateOptions({ levelType: 'debug' }); if (data.options?.headers) request.setHeaders(data.options.headers); tsDownload(data.info, data.crypto).then(success => { parentPort.postMessage({ success, info: data.info }); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 2adb471..0d038f1 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -10,7 +10,15 @@ export const getRetry = (url: string, retries = 3) => () => request.get(url, null, {}, { rejectUnauthorized: false }), 1000, retries, - r => r.response.statusCode === 200 + r => { + if (r.response.statusCode !== 200) { + console.log(); + logger.warn(`[retry][${url}][${r.response.statusCode}]`, r.response.statusMessage || r.data); + // throw Error(`[${r.response.statusCode}]${r.response.statusMessage || r.data}`); + } + + return r.response.statusCode === 200; + } ); export const logger = NLogger.getLogger('[M3U8-DL]', { color }); diff --git a/src/lib/worker_pool.ts b/src/lib/worker_pool.ts index 5c36315..7b764c0 100644 --- a/src/lib/worker_pool.ts +++ b/src/lib/worker_pool.ts @@ -70,6 +70,7 @@ export class WorkerPool extends EventEmitter { }); worker.on('error', err => { + console.error('worker error', err); // 如果发生未捕获的异常:调用传递给 `runTask` 并出现错误的回调。 const r = this.workerTaskInfo.get(worker); if (r) {