/* PokeTube is a Free/Libre youtube front-end ! Copyright (C) 2021-2023 POKETUBE This file is Licensed under LGPL-3.0-or-later. Poketube itself is GPL, Only this file is LGPL. see a copy here:https://www.gnu.org/licenses/lgpl-3.0.txt please dont remove this comment while sharing this code */ const fetch = require("node-fetch"); //2.5.x const { toJson } = require("xml2json"); const youtubeUrl = "https://www.youtube.com/watch?v="; const dislikeApi = "https://returnyoutubedislikeapi.com/votes?videoId="; const newApiUrl = "https://tube-srv.ashley143.gay/api/player"; const parseXml = async (videoId, headers) => { const player = await fetch(`${newApiUrl}?v=${videoId}`, headers); const xml = await player.text(); const json = toJson(xml); return getJson(json); }; const getJson = (str) => { try { return JSON.parse(str); } catch { return null; } }; const getEngagement = async (videoId) => { 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); const engagement = await getEngagement(videoId); return { video: videoData, engagement, videoUrlYoutube: `${youtubeUrl}${videoId}`, }; }; module.exports = getPokeTubeData