Improvements owowowowowo

This commit is contained in:
Ashley 2022-11-07 17:49:21 +01:00
parent a031c09b9e
commit 3ba4f3d44a

View file

@ -57,49 +57,27 @@ async function channel(id, cnt) {
} }
async function video(v) { async function video(v) {
try {
if (v == null) return "Gib ID"; if (v == null) return "Gib ID";
let nightlyRes; let nightlyRes;
for (let i = 0; i < 2; i++) {
try {
const nightly = await fetch(
`https://lighttube-nightly.kuylar.dev/api/video?v=${v}`
).then((res) => res.text());
nightlyRes = nightly;
break;
} catch (err) {
if (err.status === 500)
// Retry after a second.
await new Promise((resolve) => setTimeout(resolve, 1000));
else return "";
}
}
const video = await fetch(`${config.tubeApi}video?v=${v}`) const video = await fetch(`${config.tubeApi}video?v=${v}`)
.then((res) => res.text()) .then((res) => res.text())
.then((xml) => JSON.parse(toJson(xml))); .then((xml) => JSON.parse(toJson(xml)));
var inv_comments = await fetch(`${config.invapi}/comments/${v}`).then((res) => var inv_comments = await fetch(`${config.invapi}/comments/${v}`).then(
res.text() (res) => res.text()
); );
var comments = await JSON.parse(inv_comments); var comments = await JSON.parse(inv_comments);
var video_new_info = await fetch(`${config.invapi}/videos/${v}`).then(
var video_new_info = await fetch(`${config.invapi}/videos/${v}`).then((res) => (res) => res.text()
res.text()
); );
var vid = await JSON.parse(video_new_info); var vid = await JSON.parse(video_new_info);
const c = await fetch(
`${config.tubeApi}channel?id=${video.Video.Channel.id}&tab=videos`
)
.then((res) => res.text())
.then((xml) => JSON.parse(toJson(xml)));
const a = await fetch( const a = await fetch(
`${config.tubeApi}channel?id=${video.Video.Channel.id}&tab=about` `${config.tubeApi}channel?id=${video.Video.Channel.id}&tab=about`
) )
@ -108,7 +86,9 @@ async function video(v) {
const summary = await wiki const summary = await wiki
.summary(video.Video.Channel.Name + " ") .summary(video.Video.Channel.Name + " ")
.then((summary_) => (summary_.title !== "Not found." ? summary_ : "none")); .then((summary_) =>
summary_.title !== "Not found." ? summary_ : "none"
);
const data = await fetcher(v); const data = await fetcher(v);
@ -118,7 +98,6 @@ async function video(v) {
json: data.video.Player, json: data.video.Player,
video, video,
vid, vid,
channel: c,
comments, comments,
engagement: data.engagement, engagement: data.engagement,
wiki: summary, wiki: summary,
@ -127,6 +106,7 @@ async function video(v) {
`https://i.ytimg.com/vi/${v}/maxresdefault.jpg` `https://i.ytimg.com/vi/${v}/maxresdefault.jpg`
).then((colors) => colors[0].hex()), ).then((colors) => colors[0].hex()),
}; };
} catch (err) {}
} }
async function search(query, cnt) { async function search(query, cnt) {
@ -141,8 +121,23 @@ async function search(query, cnt) {
return data; return data;
} }
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;
}
}
module.exports = { module.exports = {
search, search,
video, video,
isvalidvideo,
channel, channel,
}; };