This commit is contained in:
Tusko 2021-02-22 11:42:13 +02:00
parent 3f3e69b102
commit e6901e7294
2 changed files with 16 additions and 15 deletions

View file

@ -12,7 +12,7 @@ function loadVideo(num, cb) {
getJson(masterUrl, num, (err, json) => {
if (err) {
cb(err);
return cb(err);
}
const videoData = json.video
@ -62,13 +62,14 @@ function loadVideo(num, cb) {
}
function processFile(type, baseUrl, initData, segments, filename, cb) {
const filePath = `./parts/${filename}`;
const downloadingFlag = `./parts/.${filename}~`;
const file = filename.replace(/[^\w.]/gi, '-');
const filePath = `./parts/${file}`;
const downloadingFlag = `./parts/.${file}~`;
if (fs.existsSync(downloadingFlag)) {
log("⚠️", ` ${filename} - ${type} is incomplete, restarting the download`);
log("⚠️", ` ${file} - ${type} is incomplete, restarting the download`);
} else if (fs.existsSync(filePath)) {
log("⚠️", ` ${filename} - ${type} already exists`);
log("⚠️", ` ${file} - ${type} already exists`);
cb();
} else {
fs.writeFileSync(downloadingFlag, '');
@ -95,9 +96,11 @@ function processFile(type, baseUrl, initData, segments, filename, cb) {
function combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag, cb) {
if (i >= segmentsUrl.length) {
fs.unlinkSync(downloadingFlag);
if (fs.existsSync(downloadingFlag)) {
fs.unlinkSync(downloadingFlag);
}
log("🏁", ` ${filename} - ${type} done`);
cb();
return cb();
}
log(
@ -129,15 +132,15 @@ function getJson(url, n, cb) {
https
.get(url, res => {
if (res.statusCode === 200) {
if (res.statusMessage.toLowerCase() !== 'gone') {
res.on("data", d => (data += d));
res.on("end", () => cb(null, JSON.parse(data)));
} else {
log("⏱️", ` The master.json file is expired or crushed. Please update or remove it from the sequence (broken on ` + n + ` position)`);
return cb(`The master.json file is expired or crushed. Please update or remove it from the sequence (broken on ` + n + ` position)`);
}
})
.on("error", e => {
cb(e);
return cb(e);
});
}

View file

@ -1,8 +1,8 @@
const list = [
module.exports = [
{
name: "Beluga test",
url:
"https://33vod-adaptive.akamaized.net/exp=1612606615~acl=%2F84112832%2F%2A~hmac=e59eb3562ab8f318d99ffa8b9047fc13471414ae6a2fbb91d31963e640f8a7ff/84112832/sep/video/219068532,219068533/master.json?base64_init=1"
"https://33vod-adaptive.akamaized.net/exp=1613990546~acl=%2F84112832%2F%2A~hmac=89fbc453a492d1b13bf076b234673b590a103c049fea16801ad9fa537fb5d9b9/84112832/sep/video/219068532,219068533/master.json?base64_init=1"
},
{
name: "1. Introduction",
@ -273,6 +273,4 @@ const list = [
name: "",
url: ""
}
];
module.exports = list;
];