1
Fork 0

use libcurl instead

This commit is contained in:
Ashley 2023-03-12 06:38:21 +00:00
parent 4a2d836cda
commit 49f3c59825

View file

@ -1,30 +1,17 @@
/*
const { curly } = require('node-libcurl');
const { toJson } = require('xml2json');
const fetch = require("node-fetch");
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://p.poketube.fun/api?v=";
const newApiUrl = "https://inner-api.poketube.fun/api/player";
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) => {
try {
const player = await fetch(`${newApiUrl}?v=${videoId}`, headers);
const xml = await player.text();
const json = toJson(xml);
var { data } = await curly.get(`${newApiUrl}?v=${videoId}`, {
httpHeader: Object.entries(headers).map(([k, v]) => `${k}: ${v}`)
});
const json = toJson(data);
return getJson(json);
} catch (error) {
console.error(`Error parsing XML: ${error}`);
@ -32,6 +19,7 @@ const parseXml = async (videoId, headers) => {
}
};
const getJson = (str) => {
try {
return JSON.parse(str);
@ -40,6 +28,7 @@ const getJson = (str) => {
}
};
const getEngagementData = async (videoId) => {
const apiUrl = `${dislikeApi}${videoId}`;
const fallbackUrl = `https://p.poketube.fun/${apiUrl}`;
@ -70,5 +59,4 @@ const getPokeTubeData = async (videoId) => {
};
};
module.exports = getPokeTubeData
module.exports = getPokeTubeData;