From c5b059930138fca070c256dad3ddf5c1154916b4 Mon Sep 17 00:00:00 2001 From: ditie193ch Date: Sat, 11 Jul 2020 18:51:08 -0300 Subject: [PATCH 1/2] Feature identify, after a restart, if last downloaded file is complete, if it's not the download is restarted --- vimeomaster.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/vimeomaster.js b/vimeomaster.js index 0048067..2d4ef1c 100644 --- a/vimeomaster.js +++ b/vimeomaster.js @@ -64,9 +64,15 @@ function loadVideo(num, cb) { function processFile(type, baseUrl, initData, segments, filename, cb) { const filePath = `./parts/${filename}`; - if (fs.existsSync(filePath)) { + const downloadingFlag = `./parts/.${filename}~` + + if(fs.existsSync(downloadingFlag)) { + log("⚠️", ` ${filename} - ${type} is incomplete, restarting the download`); + } else if (fs.existsSync(filePath)) { log("⚠️", ` ${filename} - ${type} already exists`); return cb(); + } else { + fs.writeFileSync(downloadingFlag, ''); } const segmentsUrl = segments.map(seg => baseUrl + seg.url); @@ -78,7 +84,7 @@ function processFile(type, baseUrl, initData, segments, filename, cb) { flags: "a" }); - combineSegments(type, 0, segmentsUrl, output, filePath, err => { + combineSegments(type, 0, segmentsUrl, output, filePath, downloadingFlag, err => { if (err) { log("⚠️", ` ${err}`); } @@ -88,8 +94,9 @@ function processFile(type, baseUrl, initData, segments, filename, cb) { }); } -function combineSegments(type, i, segmentsUrl, output, filename, cb) { +function combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag, cb) { if (i >= segmentsUrl.length) { + fs.unlinkSync(downloadingFlag); log("🏁", ` ${filename} - ${type} done`); return cb(); } From 7c20a113d4733161fd8be6ffa2115a198851f198 Mon Sep 17 00:00:00 2001 From: ditie193ch Date: Sat, 11 Jul 2020 19:09:16 -0300 Subject: [PATCH 2/2] Feature identify, after a restart, if last downloaded file is complete, if it's not the download is restarted --- vimeomaster.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vimeomaster.js b/vimeomaster.js index 2d4ef1c..d48a00e 100644 --- a/vimeomaster.js +++ b/vimeomaster.js @@ -64,7 +64,7 @@ function loadVideo(num, cb) { function processFile(type, baseUrl, initData, segments, filename, cb) { const filePath = `./parts/${filename}`; - const downloadingFlag = `./parts/.${filename}~` + const downloadingFlag = `./parts/.${filename}~`; if(fs.existsSync(downloadingFlag)) { log("⚠️", ` ${filename} - ${type} is incomplete, restarting the download`); @@ -112,7 +112,7 @@ function combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag res.on("data", d => output.write(d)); res.on("end", () => - combineSegments(type, i + 1, segmentsUrl, output, filename, cb) + combineSegments(type, i + 1, segmentsUrl, output, filename, downloadingFlag, cb) ); }) .on("error", e => {