1
0
Fork 0
mirror of https://codeberg.org/ashley/poke.git synced 2025-02-20 17:58:49 -05:00
poke/src/libpoketube/libpoketube-fetcher.js

75 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-03-02 23:05:55 +03:00
/*
2023-02-09 16:34:45 +00:00
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
2022-03-02 23:05:55 +03:00
*/
2022-09-23 18:54:05 +02:00
2023-02-09 16:34:45 +00:00
2022-03-02 23:05:55 +03:00
const fetch = require("node-fetch"); //2.5.x
const { toJson } = require("xml2json");
2022-05-17 23:19:35 +03:00
2022-03-02 23:05:55 +03:00
var youtube_url = `https://www.youtube.com/watch?v=`;
var dislike_api = `https://returnyoutubedislikeapi.com/votes?videoId=`;
2022-12-13 18:22:51 +00:00
var new_api_url = `https://tube-srv.ashley143.gay/api/player`;
2022-03-02 23:05:55 +03:00
module.exports = async function (video_id) {
2022-12-20 13:38:25 +00:00
function getJson(str) {
try {
return JSON.parse(str);
} catch {
return null;
}
2022-12-09 19:03:28 +00:00
}
2022-12-09 19:06:19 +00:00
const headers = {};
2022-05-17 23:19:35 +03:00
/*
* Parses and fetches an xml
*/
2022-09-23 18:54:05 +02:00
async function parsexml(id) {
2022-12-24 10:48:00 +00:00
2022-12-21 15:42:06 +00:00
async function fetchxmlvideo() {
try {
const player = await fetch(`${new_api_url}?v=${id}`, headers);
var h = await player.text();
var j = toJson(h);
return getJson(j);
} catch {}
}
const a = await fetchxmlvideo();
return a;
2022-03-06 16:53:46 +03:00
}
2022-07-10 23:52:00 +03:00
2022-12-20 13:38:25 +00:00
async function ryd() {
try {
2023-02-24 15:55:48 +00:00
const engagement = await fetch(`https://p.poketube.fun/${dislike_api}${video_id}`).then((res) =>
2022-12-20 13:38:25 +00:00
res.json()
);
return engagement;
} catch {}
}
const engagement = await ryd();
2022-03-02 23:05:55 +03:00
/*
* Returner object
*/
2022-03-02 23:05:55 +03:00
const returner = {
video: await parsexml(video_id),
2022-12-20 10:59:28 +00:00
engagement,
video_url_youtube: `${youtube_url}${video_id}`,
};
2022-12-20 13:38:25 +00:00
return returner;
};