From ec33351990e6ea6c99c691a37a5d0e2a3114d2c0 Mon Sep 17 00:00:00 2001 From: Ashley Date: Tue, 28 Feb 2023 14:12:57 +0000 Subject: [PATCH] add engagement thingy --- src/libpoketube/libpoketube-fetcher.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libpoketube/libpoketube-fetcher.js b/src/libpoketube/libpoketube-fetcher.js index 566b8056..bc7e19fb 100644 --- a/src/libpoketube/libpoketube-fetcher.js +++ b/src/libpoketube/libpoketube-fetcher.js @@ -17,7 +17,7 @@ const fetch = require("node-fetch"); //2.5.x const { toJson } = require("xml2json"); const youtubeUrl = "https://www.youtube.com/watch?v="; -const dislikeApi = "https://p.poketube.fun/https://returnyoutubedislikeapi.com/votes?videoId="; +const dislikeApi = "https://returnyoutubedislikeapi.com/votes?videoId="; const newApiUrl = "https://tube-srv.ashley143.gay/api/player"; const parseXml = async (videoId, headers) => { @@ -36,10 +36,23 @@ const getJson = (str) => { }; const getEngagement = async (videoId) => { - const engagement = await fetch(`${dislikeApi}${videoId}`).then((res) => res.json()); - return engagement; + const apiUrl = `${dislikeApi}${videoId}`; + const fallbackUrl = `https://p.poketube.fun/${apiUrl}`; + + try { + const engagement = await fetch(apiUrl).then((res) => res.json()); + return engagement; + } catch { + try { + const engagement = await fetch(fallbackUrl).then((res) => res.json()); + return engagement; + } catch { + return; + } + } }; + const getPokeTubeData = async (videoId) => { const headers = {}; const videoData = await parseXml(videoId, headers);