use libcurl owowowowowowow

This commit is contained in:
Ashley 2023-03-12 06:41:06 +00:00
parent 0f1c9cb9aa
commit 91299a551e

View file

@ -1,4 +1,4 @@
/* /*
PokeTube is a Free/Libre youtube front-end ! PokeTube is a Free/Libre youtube front-end !
@ -14,6 +14,7 @@
const fetch = require("node-fetch"); const fetch = require("node-fetch");
const { toJson } = require("xml2json"); const { toJson } = require("xml2json");
const { curly } = require("node-libcurl");
const fetcher = require("../libpoketube/libpoketube-fetcher.js"); const fetcher = require("../libpoketube/libpoketube-fetcher.js");
const getColors = require("get-image-colors"); const getColors = require("get-image-colors");
@ -72,7 +73,7 @@ async function video(v) {
if (v == null) return "Gib ID"; if (v == null) return "Gib ID";
// Check if result is already cached // Check if result is already cached
if (cache[v] && (Date.now() - cache[v].timestamp) < 3600000) { if (cache[v] && Date.now() - cache[v].timestamp < 3600000) {
console.log("Returning cached result"); console.log("Returning cached result");
return cache[v].result; return cache[v].result;
} }
@ -94,15 +95,18 @@ async function video(v) {
let vid; let vid;
try { try {
const videoInfo = await fetch(`${config.invapi}/videos/${v}`).then(res => res.text()); const videoInfo = await fetch(`${config.invapi}/videos/${v}`).then((res) =>
res.text()
);
vid = await getJson(videoInfo); vid = await getJson(videoInfo);
} catch (error) { } catch (error) {
console.error("Error getting video info", error); console.error("Error getting video info", error);
} }
if (!vid) { 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)) {
@ -127,27 +131,27 @@ async function video(v) {
desc = a.Channel?.Contents?.ItemSection?.About?.Description; desc = a.Channel?.Contents?.ItemSection?.About?.Description;
const data = await fetcher(v); const fe = await fetcher(v);
const nightlyJsonData = getJson(nightlyRes); const nightlyJsonData = getJson(nightlyRes);
try { try {
const video = await fetch(`${config.tubeApi}video?v=${v}`) const headers = {};
.then((res) => res.text())
.then((xml) => getJson(toJson(xml))) var { data } = await curly.get(`${config.tubeApi}video?v=${v}`, {
.catch(error => { httpHeader: Object.entries(headers).map(([k, v]) => `${k}: ${v}`),
console.error("Error getting video", error); });
return " "; var json = toJson(data);
}); const video = getJson(json);
// Store result in cache // Store result in cache
cache[v] = { cache[v] = {
result: { result: {
json: data?.video?.Player, json: fe?.video?.Player,
video, video,
vid, vid,
comments, comments,
engagement: data.engagement, engagement: fe.engagement,
wiki: summary, wiki: summary,
desc: desc, desc: desc,
color: await getColors( color: await getColors(
@ -157,7 +161,7 @@ async function video(v) {
`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() timestamp: Date.now(),
}; };
return cache[v].result; return cache[v].result;
@ -167,7 +171,6 @@ async function video(v) {
} }
} }
async function search(query, cnt) { async function search(query, cnt) {
if (query == null) return "Gib Query"; if (query == null) return "Gib Query";