use local json instead because api.inv.io slooooooooooooooow

This commit is contained in:
Ashley 2023-03-09 18:50:38 +00:00
parent 6cb3ad5fb1
commit bfafd7a01e

View file

@ -44,32 +44,25 @@ module.exports = async function (video_id) {
}, {}); }, {});
} }
try { // gets invidious instances
// gets invidious instances const invInstanceList = require("./invapi.json");
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));
// gets random instances from the list // gets random instances from the list
const instance = invInstanceList[Math.floor(Math.random() * invInstanceList.length)]; const instance =
invInstanceList[Math.floor(Math.random() * invInstanceList.length)];
let url; let url;
if (instance[1].type != "https") { if (instance[1].type != "https") {
url = "https://invidious.weblibre.org"; url = "https://invidious.sethforprivacy.com";
} else { } else {
url = instance[1].uri url = instance[1].uri
.replace("invidious.tiekoetter.com", "invidious.weblibre.org") .replace("invidious.tiekoetter.com", "invidious.sethforprivacy.com")
.replace("yewtu.be", "invidious.sethforprivacy.com") .replace("yewtu.be", "invidious.sethforprivacy.com")
.replace("invidious.slipfox.xyz", "invidious.weblibre.org") .replace("invidious.slipfox.xyz", "invidious.sethforprivacy.com")
.replace("vid.priv.au", "inv.vern.cc") .replace("vid.priv.au", "inv.vern.cc")
.replace("invidious.snopyta.org", "invidious.sethforprivacy.com"); .replace("invidious.snopyta.org", "invidious.sethforprivacy.com")
} .replace("invidious.weblibre.org", "invidious.sethforprivacy.com");
return url;
} catch (error) {
console.error("Failed to get Invidious instance:", error);
return " ";
} }
return url;
}; };