2022-03-02 21:05:55 +01:00
|
|
|
/*
|
2022-03-02 22:00:46 +01:00
|
|
|
|
2022-05-17 22:19:35 +02:00
|
|
|
Copyright (C) 2021-2022 POKETUBE (https://github.com/iamashley0/poketube)
|
2022-03-02 21:05:55 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see https://www.gnu.org/licenses/.
|
|
|
|
*/
|
2022-09-23 18:54:05 +02:00
|
|
|
|
2022-03-02 21:05:55 +01:00
|
|
|
const fetch = require("node-fetch"); //2.5.x
|
2022-06-20 11:00:10 +02:00
|
|
|
const { toJson } = require("xml2json");
|
2022-05-17 22:19:35 +02:00
|
|
|
|
2022-03-02 21:05:55 +01:00
|
|
|
var youtube_url = `https://www.youtube.com/watch?v=`;
|
2022-06-20 11:00:10 +02:00
|
|
|
var dislike_api = `https://returnyoutubedislikeapi.com/votes?videoId=`;
|
2022-12-13 19:22:51 +01:00
|
|
|
var new_api_url = `https://tube-srv.ashley143.gay/api/player`;
|
2022-03-02 21:05:55 +01:00
|
|
|
|
2022-06-20 11:00:10 +02:00
|
|
|
module.exports = async function (video_id) {
|
2022-12-20 14:38:25 +01:00
|
|
|
function getJson(str) {
|
|
|
|
try {
|
|
|
|
return JSON.parse(str);
|
|
|
|
} catch {
|
|
|
|
return null;
|
|
|
|
}
|
2022-12-09 20:03:28 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 20:06:19 +01:00
|
|
|
const headers = {};
|
2022-05-17 22:19:35 +02:00
|
|
|
/*
|
|
|
|
* Parses and fetches an xml
|
2022-06-20 11:00:10 +02:00
|
|
|
*/
|
2022-09-23 18:54:05 +02:00
|
|
|
|
2022-06-20 11:00:10 +02:00
|
|
|
async function parsexml(id) {
|
2022-12-24 11:48:00 +01:00
|
|
|
|
|
|
|
|
2022-12-21 16:42:06 +01: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 14:53:46 +01:00
|
|
|
}
|
2022-07-10 22:52:00 +02:00
|
|
|
|
2022-12-20 14:38:25 +01:00
|
|
|
async function ryd() {
|
|
|
|
try {
|
|
|
|
const engagement = await fetch(`${dislike_api}${video_id}`).then((res) =>
|
|
|
|
res.json()
|
|
|
|
);
|
|
|
|
return engagement;
|
|
|
|
} catch {}
|
|
|
|
}
|
|
|
|
|
|
|
|
const engagement = await ryd();
|
|
|
|
|
2022-03-02 21:05:55 +01:00
|
|
|
/*
|
2022-06-20 11:00:10 +02:00
|
|
|
* Returner object
|
|
|
|
*/
|
2022-03-02 21:05:55 +01:00
|
|
|
const returner = {
|
2022-06-20 11:00:10 +02:00
|
|
|
video: await parsexml(video_id),
|
2022-12-20 11:59:28 +01:00
|
|
|
engagement,
|
2022-06-20 11:00:10 +02:00
|
|
|
video_url_youtube: `${youtube_url}${video_id}`,
|
|
|
|
};
|
2022-12-20 14:38:25 +01:00
|
|
|
|
2022-06-20 11:00:10 +02:00
|
|
|
return returner;
|
|
|
|
};
|