mirror of
https://github.com/Tusko/vimeo-private-downloader.git
synced 2025-08-24 07:05:55 -07:00
wait for segment request timeout and auto download retry
This commit is contained in:
parent
10f453e0e8
commit
6f7894a242
1 changed files with 29 additions and 25 deletions
|
@ -17,20 +17,20 @@ function loadVideo(num, cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const videoData = json.video
|
const videoData = json.video
|
||||||
.sort((v1, v2) => v1.avg_bitrate - v2.avg_bitrate)
|
.sort((v1, v2) => v1.avg_bitrate - v2.avg_bitrate)
|
||||||
.pop();
|
.pop();
|
||||||
const audioData = json.audio
|
const audioData = json.audio
|
||||||
.sort((a1, a2) => a1.avg_bitrate - a2.avg_bitrate)
|
.sort((a1, a2) => a1.avg_bitrate - a2.avg_bitrate)
|
||||||
.pop();
|
.pop();
|
||||||
|
|
||||||
const videoBaseUrl = url.resolve(
|
const videoBaseUrl = url.resolve(
|
||||||
url.resolve(masterUrl, json.base_url),
|
url.resolve(masterUrl, json.base_url),
|
||||||
videoData.base_url
|
videoData.base_url
|
||||||
);
|
);
|
||||||
const audioBaseUrl = url.resolve(
|
const audioBaseUrl = url.resolve(
|
||||||
url.resolve(masterUrl, json.base_url),
|
url.resolve(masterUrl, json.base_url),
|
||||||
audioData.base_url
|
audioData.base_url
|
||||||
);
|
);
|
||||||
|
|
||||||
processFile(
|
processFile(
|
||||||
"video",
|
"video",
|
||||||
|
@ -56,9 +56,9 @@ function loadVideo(num, cb) {
|
||||||
|
|
||||||
cb(null, num + 1);
|
cb(null, num + 1);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,33 +105,37 @@ function combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag
|
||||||
"📦",
|
"📦",
|
||||||
type === "video" ? "📹" : "🎧",
|
type === "video" ? "📹" : "🎧",
|
||||||
`Downloading ${type} segment ${i}/${segmentsUrl.length} of ${filename}`
|
`Downloading ${type} segment ${i}/${segmentsUrl.length} of ${filename}`
|
||||||
);
|
);
|
||||||
|
|
||||||
https
|
let req = https
|
||||||
.get(segmentsUrl[i], res => {
|
.get(segmentsUrl[i], res => {
|
||||||
res.on("data", d => output.write(d));
|
res.on("data", d => output.write(d));
|
||||||
|
|
||||||
res.on("end", () =>
|
res.on("end", () =>
|
||||||
combineSegments(type, i + 1, segmentsUrl, output, filename, downloadingFlag, cb)
|
combineSegments(type, i + 1, segmentsUrl, output, filename, downloadingFlag, cb)
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.on("error", e => {
|
.on("error", e => {
|
||||||
cb(e);
|
cb(e);
|
||||||
});
|
});
|
||||||
|
req.setTimeout(7000, function () {
|
||||||
|
console.log("Timeout. Retrying");
|
||||||
|
combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag, cb)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getJson(url, cb) {
|
function getJson(url, cb) {
|
||||||
let data = "";
|
let data = "";
|
||||||
|
|
||||||
https
|
https
|
||||||
.get(url, res => {
|
.get(url, res => {
|
||||||
res.on("data", d => (data += d));
|
res.on("data", d => (data += d));
|
||||||
|
|
||||||
res.on("end", () => cb(null, JSON.parse(data)));
|
res.on("end", () => cb(null, JSON.parse(data)));
|
||||||
})
|
})
|
||||||
.on("error", e => {
|
.on("error", e => {
|
||||||
cb(e);
|
cb(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initJs(n = 0) {
|
function initJs(n = 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue