mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 17:58:17 +01:00
add cache!!
This commit is contained in:
parent
851f768cb5
commit
abba478763
1 changed files with 46 additions and 50 deletions
|
@ -24,7 +24,7 @@ const sqp =
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
tubeApi: "https://tube-srv.ashley143.gay/api/",
|
tubeApi: "https://tube-srv.ashley143.gay/api/",
|
||||||
invapi: "https://inv.zzls.xyz/api/v1",
|
invapi: "https://yt.oelrichsgarcia.de/api/v1",
|
||||||
dislikes: "https://returnyoutubedislikeapi.com/votes?videoId=",
|
dislikes: "https://returnyoutubedislikeapi.com/votes?videoId=",
|
||||||
t_url: "https://t.poketube.fun/", // def matomo url
|
t_url: "https://t.poketube.fun/", // def matomo url
|
||||||
};
|
};
|
||||||
|
@ -66,12 +66,19 @@ async function channel(id, cnt) {
|
||||||
return { videos, about };
|
return { videos, about };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cache = {};
|
||||||
|
|
||||||
async function video(v) {
|
async function video(v) {
|
||||||
if (v == null) return "Gib ID";
|
if (v == null) return "Gib ID";
|
||||||
|
|
||||||
|
// Check if result is already cached
|
||||||
|
if (cache[v] && (Date.now() - cache[v].timestamp) < 3600000) {
|
||||||
|
console.log("Returning cached result");
|
||||||
|
return cache[v].result;
|
||||||
|
}
|
||||||
|
|
||||||
let nightlyRes;
|
let nightlyRes;
|
||||||
var desc = "";
|
var desc = "";
|
||||||
var iurl = "invidious.privacydev.net";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var inv_comments = await fetch(`${config.invapi}/comments/${v}`).then(
|
var inv_comments = await fetch(`${config.invapi}/comments/${v}`).then(
|
||||||
|
@ -83,30 +90,13 @@ async function video(v) {
|
||||||
var comments = "";
|
var comments = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const urls = [
|
|
||||||
"invidious.sethforprivacy.com",
|
|
||||||
"invidious.weblibre.org",
|
|
||||||
"inv.zzls.xyz",
|
|
||||||
"invidious.privacydev.net"
|
|
||||||
];
|
|
||||||
|
|
||||||
let vid;
|
let vid;
|
||||||
|
|
||||||
for (const url of urls) {
|
|
||||||
try {
|
try {
|
||||||
const videoInfo = await fetch(`https://${url}/api/v1/videos/${v}`).then(res => res.text());
|
const videoInfo = await fetch(`https://yt.oelrichsgarcia.de/api/v1/videos/${v}`).then(res => res.text());
|
||||||
vid = await getJson(videoInfo);
|
vid = await getJson(videoInfo);
|
||||||
|
|
||||||
switch (true) {
|
|
||||||
case vid?.descriptionHtml !== "<p></p>":
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,7 +104,6 @@ if (!vid) {
|
||||||
console.log(`Sorry nya, we couldn't find any information about that video qwq`);
|
console.log(`Sorry nya, we couldn't find any information about that video qwq`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (checkUnexistingObject(vid)) {
|
if (checkUnexistingObject(vid)) {
|
||||||
var a;
|
var a;
|
||||||
|
|
||||||
|
@ -140,7 +129,9 @@ if (!vid) {
|
||||||
|
|
||||||
const nightlyJsonData = getJson(nightlyRes);
|
const nightlyJsonData = getJson(nightlyRes);
|
||||||
|
|
||||||
return {
|
// Store result in cache
|
||||||
|
cache[v] = {
|
||||||
|
result: {
|
||||||
json: data?.video?.Player,
|
json: data?.video?.Player,
|
||||||
video: await fetch(`${config.tubeApi}video?v=${v}`)
|
video: await fetch(`${config.tubeApi}video?v=${v}`)
|
||||||
.then((res) => res.text())
|
.then((res) => res.text())
|
||||||
|
@ -157,10 +148,15 @@ if (!vid) {
|
||||||
color2: await getColors(
|
color2: await getColors(
|
||||||
`https://i.ytimg.com/vi/${v}/hqdefault.jpg?sqp=${sqp}`
|
`https://i.ytimg.com/vi/${v}/hqdefault.jpg?sqp=${sqp}`
|
||||||
).then((colors) => colors[1].hex()),
|
).then((colors) => colors[1].hex()),
|
||||||
|
},
|
||||||
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return cache[v].result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function search(query, cnt) {
|
async function search(query, cnt) {
|
||||||
if (query == null) return "Gib Query";
|
if (query == null) return "Gib Query";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue