From 7f16913fd539d00872f3eaa9dd8a49a18590ef80 Mon Sep 17 00:00:00 2001 From: Eridanus Sora Date: Tue, 25 Jan 2022 23:40:33 +0800 Subject: [PATCH] improve stream end detect --- npm-shrinkwrap.json | 4 ++-- package.json | 2 +- src/core/archive.ts | 1 - src/core/live.ts | 8 ++++++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 7b49933..bcbfacc 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "minyami", - "version": "4.4.14", + "version": "4.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "minyami", - "version": "4.4.14", + "version": "4.5.0", "license": "GPL-3.0-or-later", "dependencies": { "@eridanussora/reconnecting-websocket": "^4.4.2", diff --git a/package.json b/package.json index a649004..734ec53 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minyami", - "version": "4.4.14", + "version": "4.5.0", "description": "", "main": "dist/exports.js", "types": "dist/exports.d.ts", diff --git a/src/core/archive.ts b/src/core/archive.ts index 84995b1..17edcaf 100644 --- a/src/core/archive.ts +++ b/src/core/archive.ts @@ -81,7 +81,6 @@ class ArchiveDownloader extends Downloader { */ async parse() { // parse m3u8 - console.log(this.m3u8); if (this.m3u8.encryptKeys.length > 0) { // Encrypted const key = this.m3u8.encryptKeys[0]; diff --git a/src/core/live.ts b/src/core/live.ts index 4fb227a..dc220a9 100644 --- a/src/core/live.ts +++ b/src/core/live.ts @@ -60,8 +60,12 @@ export default class LiveDownloader extends Downloader { this.m3u8 = (await loadM3U8(this.m3u8Path, this.retries, this.timeout)) as Playlist; } catch (e) { if (this.finishedChunkCount > 0) { - // Stop downloading - this.isEnd = true; + const responseStatus = e?.response?.status; + if (!!responseStatus && responseStatus >= 400 && responseStatus <= 599) { + logger.info("M3U8 file is no longer available. Stop downloading."); + // Stop downloading + this.isEnd = true; + } } else { logger.error("Aborted due to critical error.", e); this.emit("critical-error", e);