mirror of
https://github.com/Tusko/vimeo-private-downloader.git
synced 2025-08-20 21:34:03 -07:00
Merge pull request #15 from linomassarani/14-feature/incompleted-downloads
14 feature/incompleted downloads
This commit is contained in:
commit
10f453e0e8
1 changed files with 11 additions and 4 deletions
|
@ -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();
|
||||
}
|
||||
|
@ -105,7 +112,7 @@ function combineSegments(type, i, segmentsUrl, output, filename, cb) {
|
|||
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 => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue