2022-10-22 16:58:54 +02:00
|
|
|
/*
|
2022-10-09 12:37:45 +02:00
|
|
|
|
2022-10-09 14:58:53 +02:00
|
|
|
PokeTube is a Free/Libre youtube front-end !
|
2022-10-09 12:37:45 +02:00
|
|
|
|
|
|
|
Copyright (C) 2021-2022 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
|
2022-10-12 16:40:31 +02:00
|
|
|
|
|
|
|
please dont remove this comment while sharing this code
|
|
|
|
|
2022-10-09 14:58:53 +02:00
|
|
|
*/
|
|
|
|
|
2022-10-09 12:37:45 +02:00
|
|
|
const fetch = require("node-fetch");
|
|
|
|
const { toJson } = require("xml2json");
|
|
|
|
|
2022-10-27 11:30:49 +02:00
|
|
|
const fetcher = require("../libpoketube/libpoketube-fetcher.js");
|
2022-10-09 12:37:45 +02:00
|
|
|
const getColors = require("get-image-colors");
|
|
|
|
|
|
|
|
const wiki = require("wikipedia");
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
tubeApi: "https://tube.kuylar.dev/api/",
|
2022-10-28 17:34:08 +02:00
|
|
|
invapi: "https://vid.puffyan.us/api/v1",
|
2022-10-09 12:37:45 +02:00
|
|
|
dislikes: "https://returnyoutubedislikeapi.com/votes?videoId=",
|
2022-10-09 14:58:53 +02:00
|
|
|
t_url: "https://t.poketube.fun/", // def matomo url
|
2022-10-09 12:37:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Util functions
|
2022-10-09 14:30:08 +02:00
|
|
|
function getJson(str) {
|
2022-10-09 12:37:45 +02:00
|
|
|
try {
|
2022-10-09 14:30:08 +02:00
|
|
|
return JSON.parse(str);
|
|
|
|
} catch {
|
|
|
|
return null;
|
2022-10-09 12:37:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Api functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function channel(id, cnt) {
|
2022-10-09 14:30:08 +02:00
|
|
|
if (id == null) return "Gib ID";
|
2022-10-09 12:37:45 +02:00
|
|
|
|
2022-10-09 14:30:08 +02:00
|
|
|
const videos = await fetch(
|
|
|
|
`${config.tubeApi}channel?id=${id}&tab=videos&continuation=${cnt || ""}`
|
|
|
|
)
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then((xml) => JSON.parse(toJson(xml)));
|
2022-10-09 12:37:45 +02:00
|
|
|
|
2022-10-09 14:30:08 +02:00
|
|
|
const about = await fetch(`${config.tubeApi}channel?id=${id}&tab=about`)
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then((xml) => JSON.parse(toJson(xml)));
|
2022-10-09 12:37:45 +02:00
|
|
|
|
2022-10-09 14:30:08 +02:00
|
|
|
return { videos, about };
|
2022-10-09 12:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function video(v) {
|
2022-11-07 17:49:21 +01:00
|
|
|
try {
|
|
|
|
if (v == null) return "Gib ID";
|
2022-10-09 12:37:45 +02:00
|
|
|
|
2022-11-07 17:49:21 +01:00
|
|
|
let nightlyRes;
|
2022-10-09 12:37:45 +02:00
|
|
|
|
2022-11-07 17:49:21 +01:00
|
|
|
const video = await fetch(`${config.tubeApi}video?v=${v}`)
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then((xml) => JSON.parse(toJson(xml)));
|
2022-10-12 16:40:31 +02:00
|
|
|
|
2022-11-07 17:49:21 +01:00
|
|
|
var inv_comments = await fetch(`${config.invapi}/comments/${v}`).then(
|
|
|
|
(res) => res.text()
|
|
|
|
);
|
2022-10-12 17:03:43 +02:00
|
|
|
|
2022-11-07 17:49:21 +01:00
|
|
|
var comments = await JSON.parse(inv_comments);
|
2022-10-12 16:40:31 +02:00
|
|
|
|
2022-11-07 17:49:21 +01:00
|
|
|
var video_new_info = await fetch(`${config.invapi}/videos/${v}`).then(
|
|
|
|
(res) => res.text()
|
|
|
|
);
|
2022-10-13 17:49:10 +02:00
|
|
|
|
2022-11-07 17:49:21 +01:00
|
|
|
var vid = await JSON.parse(video_new_info);
|
|
|
|
|
|
|
|
const a = await fetch(
|
|
|
|
`${config.tubeApi}channel?id=${video.Video.Channel.id}&tab=about`
|
|
|
|
)
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then((xml) => JSON.parse(toJson(xml)));
|
|
|
|
|
|
|
|
const summary = await wiki
|
|
|
|
.summary(video.Video.Channel.Name + " ")
|
|
|
|
.then((summary_) =>
|
|
|
|
summary_.title !== "Not found." ? summary_ : "none"
|
|
|
|
);
|
|
|
|
|
|
|
|
const data = await fetcher(v);
|
2022-10-09 12:37:45 +02:00
|
|
|
|
2022-11-07 17:49:21 +01:00
|
|
|
const nightlyJsonData = getJson(nightlyRes);
|
|
|
|
|
|
|
|
return {
|
|
|
|
json: data.video.Player,
|
|
|
|
video,
|
|
|
|
vid,
|
|
|
|
comments,
|
|
|
|
engagement: data.engagement,
|
|
|
|
wiki: summary,
|
|
|
|
desc: a.Channel.Contents.ItemSection.About.Description,
|
|
|
|
color: await getColors(
|
|
|
|
`https://i.ytimg.com/vi/${v}/maxresdefault.jpg`
|
|
|
|
).then((colors) => colors[0].hex()),
|
2022-10-22 16:58:54 +02:00
|
|
|
};
|
2022-11-07 17:49:21 +01:00
|
|
|
} catch (err) {}
|
2022-10-09 12:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function search(query, cnt) {
|
2022-10-09 14:30:08 +02:00
|
|
|
if (query == null) return "Gib Query";
|
2022-10-09 12:37:45 +02:00
|
|
|
|
2022-10-09 14:30:08 +02:00
|
|
|
const data = await fetch(
|
|
|
|
`${config.tubeApi}search?query=${query}&continuation=${cnt || ""}`
|
|
|
|
)
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then((xml) => JSON.parse(toJson(xml)));
|
2022-10-09 12:37:45 +02:00
|
|
|
|
2022-10-09 14:30:08 +02:00
|
|
|
return data;
|
2022-10-09 12:37:45 +02:00
|
|
|
}
|
|
|
|
|
2022-11-07 17:49:21 +01:00
|
|
|
async function isvalidvideo(v) {
|
|
|
|
var status;
|
|
|
|
const vld = await fetch(`${config.dislikes}${v}`).then((res) => {
|
|
|
|
status = res.status;
|
|
|
|
return res.json();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (status == 400) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-09 12:37:45 +02:00
|
|
|
module.exports = {
|
|
|
|
search,
|
|
|
|
video,
|
2022-11-07 17:49:21 +01:00
|
|
|
isvalidvideo,
|
2022-10-09 14:58:53 +02:00
|
|
|
channel,
|
2022-10-12 17:03:43 +02:00
|
|
|
};
|