From 4ced593d751d99903ceaab2a7ff1e1a4e395613a Mon Sep 17 00:00:00 2001 From: Ashley Date: Wed, 19 Apr 2023 22:09:29 +0000 Subject: [PATCH] change objects name to fit the whole thingy :3 add uhh use the initerr function ig? --- src/libpoketube/libpoketube-fetcher.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/libpoketube/libpoketube-fetcher.js b/src/libpoketube/libpoketube-fetcher.js index 3bda5a12..c37566a0 100644 --- a/src/libpoketube/libpoketube-fetcher.js +++ b/src/libpoketube/libpoketube-fetcher.js @@ -6,7 +6,11 @@ const youtubeUrl = 'https://www.youtube.com/watch?v='; const dislikeApi = 'https://p.poketube.fun/api?v='; const newApiUrl = 'https://inner-api.poketube.fun/api/player'; -const parseXml = async (videoId, headers) => { +function initerr(args){ + console.error("[LIBPT FETCHER ERROR]" + args) +} + +const getInnerTubeData = async (videoId, headers) => { try { var { data } = await curly.get(`${newApiUrl}?v=${videoId}`, { httpHeader: Object.entries(headers).map(([k, v]) => `${k}: ${v}`) @@ -16,7 +20,7 @@ const parseXml = async (videoId, headers) => { return getJson(json); } catch (error) { - console.error(`Error parsing XML: ${error}`); + initerr(`Error parsing XML: ${error}`); return null; } }; @@ -32,33 +36,35 @@ const getJson = (str) => { const getEngagementData = async (videoId) => { + // return youtube dislike api - https://www.returnyoutubedislike.com/ const apiUrl = `${dislikeApi}${videoId}`; const fallbackUrl = `https://p.poketube.fun/${apiUrl}`; try { const engagement = await fetch(apiUrl).then((res) => res.json()); return engagement.data; + // if an error occurs - try the fallback url } catch { try { const engagement = await fetch(fallbackUrl).then((res) => res.json()); return engagement; } catch { + // if that also doesnt work do nothing lol return; } } }; - -const getPokeTubeData = async (videoId) => { +const getBasicPokeTubeData = async (videoId) => { const headers = {}; - const videoData = await parseXml(videoId, headers); + const InnerTubeData = await getInnerTubeData(videoId, headers); const engagement = await getEngagementData(videoId); return { - video: videoData, + video: InnerTubeData, engagement, videoUrlYoutube: `${youtubeUrl}${videoId}`, }; }; -module.exports = getPokeTubeData; +module.exports = getBasicPokeTubeData;