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) {