mirror of
https://github.com/Tusko/vimeo-private-downloader.git
synced 2025-08-21 05:44:04 -07:00
undo file identation changes
This commit is contained in:
parent
266a44bbd8
commit
85db8c5885
1 changed files with 73 additions and 72 deletions
|
@ -9,9 +9,9 @@ function loadVideo(num, cb) {
|
|||
let masterUrl = list[num].url;
|
||||
if (!masterUrl.endsWith("?base64_init=1")) {
|
||||
masterUrl += "?base64_init=1";
|
||||
}
|
||||
}
|
||||
|
||||
getJson(masterUrl, (err, json) => {
|
||||
getJson(masterUrl, (err, json) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ getJson(masterUrl, (err, json) => {
|
|||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function processFile(type, baseUrl, initData, segments, filename, cb) {
|
||||
|
@ -68,30 +68,30 @@ function processFile(type, baseUrl, initData, segments, filename, cb) {
|
|||
|
||||
if(fs.existsSync(downloadingFlag)) {
|
||||
log("⚠️", ` ${filename} - ${type} is incomplete, restarting the download`);
|
||||
} else if (fs.existsSync(filePath)) {
|
||||
} else if (fs.existsSync(filePath)) {
|
||||
log("⚠️", ` ${filename} - ${type} already exists`);
|
||||
return cb();
|
||||
} else {
|
||||
} else {
|
||||
fs.writeFileSync(downloadingFlag, '');
|
||||
}
|
||||
}
|
||||
|
||||
const segmentsUrl = segments.map(seg => baseUrl + seg.url);
|
||||
const segmentsUrl = segments.map(seg => baseUrl + seg.url);
|
||||
|
||||
const initBuffer = Buffer.from(initData, "base64");
|
||||
fs.writeFileSync(filePath, initBuffer);
|
||||
const initBuffer = Buffer.from(initData, "base64");
|
||||
fs.writeFileSync(filePath, initBuffer);
|
||||
|
||||
const output = fs.createWriteStream(filePath, {
|
||||
const output = fs.createWriteStream(filePath, {
|
||||
flags: "a"
|
||||
});
|
||||
});
|
||||
|
||||
combineSegments(type, 0, segmentsUrl, output, filePath, downloadingFlag, err => {
|
||||
combineSegments(type, 0, segmentsUrl, output, filePath, downloadingFlag, err => {
|
||||
if (err) {
|
||||
log("⚠️", ` ${err}`);
|
||||
}
|
||||
|
||||
output.end();
|
||||
cb();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag, cb) {
|
||||
|
@ -99,43 +99,44 @@ function combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag
|
|||
fs.unlinkSync(downloadingFlag);
|
||||
log("🏁", ` ${filename} - ${type} done`);
|
||||
return cb();
|
||||
}
|
||||
}
|
||||
|
||||
log(
|
||||
log(
|
||||
"📦",
|
||||
type === "video" ? "📹" : "🎧",
|
||||
`Downloading ${type} segment ${i}/${segmentsUrl.length} of ${filename}`
|
||||
);
|
||||
|
||||
let req = https
|
||||
.get(segmentsUrl[i], res => {
|
||||
https
|
||||
.get(segmentsUrl[i], res => {
|
||||
res.on("data", d => output.write(d));
|
||||
|
||||
res.on("end", () =>
|
||||
combineSegments(type, i + 1, segmentsUrl, output, filename, downloadingFlag, cb)
|
||||
);
|
||||
})
|
||||
.on("error", e => {
|
||||
})
|
||||
.on("error", e => {
|
||||
cb(e);
|
||||
});
|
||||
req.setTimeout(7000, function () {
|
||||
console.log("Timeout. Retrying");
|
||||
combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag, cb)
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function getJson(url, cb) {
|
||||
let data = "";
|
||||
|
||||
https
|
||||
let req = https
|
||||
.get(url, res => {
|
||||
res.on("data", d => (data += d));
|
||||
|
||||
res.on("end", () => cb(null, JSON.parse(data)));
|
||||
})
|
||||
})
|
||||
.on("error", e => {
|
||||
cb(e);
|
||||
});
|
||||
});
|
||||
|
||||
req.setTimeout(7000, function () {
|
||||
console.log("Timeout. Retrying");
|
||||
combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag, cb)
|
||||
});
|
||||
}
|
||||
|
||||
function initJs(n = 0) {
|
||||
|
@ -150,7 +151,7 @@ function initJs(n = 0) {
|
|||
if (list[num]) {
|
||||
initJs(num);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
initJs();
|
Loading…
Add table
Add a link
Reference in a new issue