2023-01-10 16:59:43 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
PokeTube is a Free/Libre youtube front-end !
|
|
|
|
|
|
|
|
Copyright (C) 2021-2023 POKETUBE
|
|
|
|
|
|
|
|
This file is Licensed under LGPL-3.0-or-later. Poketube itself is GPL, Only this file is LGPL.
|
|
|
|
|
|
|
|
see a copy here:https://www.gnu.org/licenses/lgpl-3.0.txt
|
|
|
|
|
|
|
|
please dont remove this comment while sharing this code
|
|
|
|
|
2023-02-25 18:48:15 +01:00
|
|
|
*/
|
2023-01-10 16:59:43 +01:00
|
|
|
|
|
|
|
const {
|
|
|
|
fetcher,
|
|
|
|
core,
|
|
|
|
wiki,
|
|
|
|
musicInfo,
|
|
|
|
modules,
|
|
|
|
version,
|
|
|
|
initlog,
|
|
|
|
init,
|
|
|
|
} = require("./libpoketube-initsys.js");
|
|
|
|
|
|
|
|
const {
|
|
|
|
IsJsonString,
|
|
|
|
convert,
|
|
|
|
getFirstLine,
|
|
|
|
capitalizeFirstLetter,
|
|
|
|
turntomins,
|
|
|
|
getRandomInt,
|
|
|
|
getRandomArbitrary,
|
|
|
|
} = require("./ptutils/libpt-coreutils.js");
|
|
|
|
|
|
|
|
module.exports = async function (video_id) {
|
2023-02-25 18:48:15 +01:00
|
|
|
// function to convert an array to an object, ignoring undefined values
|
2023-01-10 16:59:43 +01:00
|
|
|
function toObject(arr) {
|
2023-02-25 18:48:15 +01:00
|
|
|
return arr.reduce((acc, cur, i) => {
|
|
|
|
if (cur !== undefined) {
|
|
|
|
acc[i] = cur;
|
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
}, {});
|
2023-01-10 16:59:43 +01:00
|
|
|
}
|
|
|
|
|
2023-02-05 13:30:17 +01:00
|
|
|
try {
|
2023-02-25 18:48:15 +01:00
|
|
|
// gets invidious instances
|
|
|
|
const invUrl = "https://api.invidious.io/instances.json?sort_by=type,health";
|
|
|
|
const invInstanceList = await modules
|
|
|
|
.fetch(invUrl)
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then((json) => JSON.parse(json));
|
2023-01-10 16:59:43 +01:00
|
|
|
|
2023-02-25 18:48:15 +01:00
|
|
|
// gets random instances from the list
|
|
|
|
const instance = invInstanceList[Math.floor(Math.random() * invInstanceList.length)];
|
2023-01-10 16:59:43 +01:00
|
|
|
|
2023-02-25 18:48:15 +01:00
|
|
|
let url;
|
|
|
|
if (instance[1].type != "https") {
|
|
|
|
url = "https://invidious.weblibre.org";
|
|
|
|
} else {
|
|
|
|
url = instance[1].uri
|
|
|
|
.replace("invidious.tiekoetter.com", "invidious.weblibre.org")
|
|
|
|
.replace("yewtu.be", "invidious.sethforprivacy.com")
|
|
|
|
.replace("invidious.slipfox.xyz", "invidious.weblibre.org")
|
|
|
|
.replace("vid.priv.au", "inv.vern.cc")
|
|
|
|
.replace("invidious.snopyta.org", "invidious.sethforprivacy.com");
|
|
|
|
}
|
2023-01-10 16:59:43 +01:00
|
|
|
|
2023-02-25 18:48:15 +01:00
|
|
|
return url;
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Failed to get Invidious instance:", error);
|
|
|
|
return " ";
|
2023-02-05 13:30:17 +01:00
|
|
|
}
|
2023-01-10 16:59:43 +01:00
|
|
|
};
|