mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-23 01:37:47 +01:00
use libcurl instead
This commit is contained in:
parent
4a2d836cda
commit
49f3c59825
1 changed files with 13 additions and 25 deletions
|
@ -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 !
|
const youtubeUrl = 'https://www.youtube.com/watch?v=';
|
||||||
|
const dislikeApi = 'https://p.poketube.fun/api?v=';
|
||||||
Copyright (C) 2021-2023 POKETUBE
|
const newApiUrl = 'https://inner-api.poketube.fun/api/player';
|
||||||
|
|
||||||
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 parseXml = async (videoId, headers) => {
|
const parseXml = async (videoId, headers) => {
|
||||||
try {
|
try {
|
||||||
const player = await fetch(`${newApiUrl}?v=${videoId}`, headers);
|
var { data } = await curly.get(`${newApiUrl}?v=${videoId}`, {
|
||||||
const xml = await player.text();
|
httpHeader: Object.entries(headers).map(([k, v]) => `${k}: ${v}`)
|
||||||
const json = toJson(xml);
|
});
|
||||||
|
const json = toJson(data);
|
||||||
return getJson(json);
|
return getJson(json);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error parsing XML: ${error}`);
|
console.error(`Error parsing XML: ${error}`);
|
||||||
|
@ -32,6 +19,7 @@ const parseXml = async (videoId, headers) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const getJson = (str) => {
|
const getJson = (str) => {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(str);
|
return JSON.parse(str);
|
||||||
|
@ -40,6 +28,7 @@ const getJson = (str) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const getEngagementData = async (videoId) => {
|
const getEngagementData = async (videoId) => {
|
||||||
const apiUrl = `${dislikeApi}${videoId}`;
|
const apiUrl = `${dislikeApi}${videoId}`;
|
||||||
const fallbackUrl = `https://p.poketube.fun/${apiUrl}`;
|
const fallbackUrl = `https://p.poketube.fun/${apiUrl}`;
|
||||||
|
@ -70,5 +59,4 @@ const getPokeTubeData = async (videoId) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = getPokeTubeData
|
module.exports = getPokeTubeData;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue