From 11cea4fcfaca4cc1778daf851268e96c1fbc3bd0 Mon Sep 17 00:00:00 2001 From: stratumadev Date: Tue, 30 Sep 2025 16:01:33 +0200 Subject: [PATCH] disabled resume download after 24 hours --- modules/hls-download.ts | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/modules/hls-download.ts b/modules/hls-download.ts index abca990..f000c50 100644 --- a/modules/hls-download.ts +++ b/modules/hls-download.ts @@ -109,18 +109,30 @@ class hlsDownload { // try load resume file if (fsp.existsSync(fn) && fsp.existsSync(`${fn}.resume`) && this.data.offset < 1) { try { - console.info('Resume data found! Trying to resume...'); - const resumeData = JSON.parse(await fs.readFile(`${fn}.resume`, 'utf-8')); - if (resumeData.total == this.data.m3u8json.segments.length && resumeData.completed != resumeData.total && !isNaN(resumeData.completed)) { - console.info('Resume data is ok!'); - this.data.offset = resumeData.completed; - this.data.isResume = true; + const stats = await fs.stat(`${fn}.resume`); + const age = Date.now() - stats.mtimeMs; + + // Only resume download if data is not older than 24 hours + if (age < 24 * 60 * 60 * 1000) { + console.info('Resume data found! Trying to resume...'); + const resumeData = JSON.parse(await fs.readFile(`${fn}.resume`, 'utf-8')); + if (resumeData.total == this.data.m3u8json.segments.length && resumeData.completed != resumeData.total && !isNaN(resumeData.completed)) { + console.info('Resume data is ok!'); + this.data.offset = resumeData.completed; + this.data.isResume = true; + } else { + console.warn(' Resume data is wrong!'); + console.warn({ + resume: { total: resumeData.total, dled: resumeData.completed }, + current: { total: this.data.m3u8json.segments.length } + }); + } } else { - console.warn(' Resume data is wrong!'); - console.warn({ - resume: { total: resumeData.total, dled: resumeData.completed }, - current: { total: this.data.m3u8json.segments.length } - }); + console.warn('Resume data found, but too old! Redownloading everything...'); + try { + await fs.unlink(fn); + await fs.unlink(`${fn}.resume`); + } catch (e) {} } } catch (e) { console.error('Resume failed, downloading will be not resumed!');