fix expired links

This commit is contained in:
Tusko 2021-02-06 11:24:21 +02:00
commit b662f20d4b
2 changed files with 20 additions and 24 deletions

View file

@ -1,19 +1,14 @@
const list = [
{
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"
},
{
name: "1. Introduction",
url:
"https://60vod-adaptive.akamaized.net/exp=1585642273~acl=%2F290272859%2F%2A~hmac=83af394043c1f9e24e0b1ffdd22e771c0ef2106a6a6ce4cf5e6a288dba76ceef/290272859/sep/video/1099558424,1099558420,1099557256,1099557251/master.json?base64_init=1"
},
{
name: "2.1. Интро",
url:
"https://117vod-adaptive.akamaized.net/exp=1585640053~acl=%2F207987916%2F%2A~hmac=9834e76445d49081a3b04c7e40f656ec256a04e1f53e7e7594d228a117f27ac0/207987916/sep/video/710158253,710158251,710158247,710158246/master.json?base64_init=1"
},
{
name: "2.2. Mindset",
url:
"https://120vod-adaptive.akamaized.net/exp=1585640068~acl=%2F207987919%2F%2A~hmac=b7e36ce71b8b679653141a51acbd5d8f7ca49d6c687704ad14d7c195f441dc80/207987919/sep/video/710158304,710158302,710158298,710158294/master.json?base64_init=1"
},
// {
// name: '2.3. Точка А и точка В',
// url: 'https://122vod-adaptive.akamaized.net/exp=1581672008~acl=%2F207987921%2F%2A~hmac=b444cacf99794d91a4b6b4d9df1e3e5b262980920ff21e809b7fe8f939fec49a/207987921/sep/video/710158242,710158240,710158238,710158235/master.json?base64_init=1'

View file

@ -3,7 +3,6 @@ const url = require("url");
const https = require("https");
const log = (...args) => console.log("→", ...args);
const list = require("./videojson.js");
const promises = [];
function loadVideo(num, cb) {
let masterUrl = list[num].url;
@ -11,9 +10,9 @@ function loadVideo(num, cb) {
masterUrl += "?base64_init=1";
}
getJson(masterUrl, (err, json) => {
getJson(masterUrl, num, (err, json) => {
if (err) {
return cb(err);
cb(err);
}
const videoData = json.video
@ -40,7 +39,7 @@ function loadVideo(num, cb) {
list[num].name + ".m4v",
err => {
if (err) {
return cb(err);
cb(err);
}
processFile(
@ -51,7 +50,7 @@ function loadVideo(num, cb) {
list[num].name + ".m4a",
err => {
if (err) {
return cb(err);
cb(err);
}
cb(null, num + 1);
@ -65,12 +64,12 @@ function loadVideo(num, cb) {
function processFile(type, baseUrl, initData, segments, filename, cb) {
const filePath = `./parts/${filename}`;
const downloadingFlag = `./parts/.${filename}~`;
if(fs.existsSync(downloadingFlag)) {
if (fs.existsSync(downloadingFlag)) {
log("⚠️", ` ${filename} - ${type} is incomplete, restarting the download`);
} else if (fs.existsSync(filePath)) {
log("⚠️", ` ${filename} - ${type} already exists`);
return cb();
cb();
} else {
fs.writeFileSync(downloadingFlag, '');
}
@ -98,7 +97,7 @@ function combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag
if (i >= segmentsUrl.length) {
fs.unlinkSync(downloadingFlag);
log("🏁", ` ${filename} - ${type} done`);
return cb();
cb();
}
log(
@ -125,14 +124,17 @@ function combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag
});
}
function getJson(url, cb) {
function getJson(url, n, cb) {
let data = "";
https
.get(url, res => {
res.on("data", d => (data += d));
res.on("end", () => cb(null, JSON.parse(data)));
if (res.statusCode === 200) {
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)`);
}
})
.on("error", e => {
cb(e);
@ -145,7 +147,6 @@ function initJs(n = 0) {
loadVideo(n, (err, num) => {
if (err) {
log("⚠️", ` ${err}`);
return;
}
if (list[num]) {