mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-30 01:08:43 +01:00
use getjson :3
This commit is contained in:
parent
0e4782ada9
commit
b087a5181e
1 changed files with 40 additions and 45 deletions
|
@ -30,7 +30,7 @@ const config = {
|
||||||
// Util functions
|
// Util functions
|
||||||
function getJson(str) {
|
function getJson(str) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(str);
|
return getJson(str);
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,11 @@ async function channel(id, cnt) {
|
||||||
`${config.tubeApi}channel?id=${id}&tab=videos&continuation=${cnt || ""}`
|
`${config.tubeApi}channel?id=${id}&tab=videos&continuation=${cnt || ""}`
|
||||||
)
|
)
|
||||||
.then((res) => res.text())
|
.then((res) => res.text())
|
||||||
.then((xml) => JSON.parse(toJson(xml)));
|
.then((xml) => getJson(toJson(xml)));
|
||||||
|
|
||||||
const about = await fetch(`${config.tubeApi}channel?id=${id}&tab=about`)
|
const about = await fetch(`${config.tubeApi}channel?id=${id}&tab=about`)
|
||||||
.then((res) => res.text())
|
.then((res) => res.text())
|
||||||
.then((xml) => JSON.parse(toJson(xml)));
|
.then((xml) => getJson(toJson(xml)));
|
||||||
|
|
||||||
return { videos, about };
|
return { videos, about };
|
||||||
}
|
}
|
||||||
|
@ -61,40 +61,36 @@ async function video(v) {
|
||||||
|
|
||||||
let nightlyRes;
|
let nightlyRes;
|
||||||
|
|
||||||
|
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 getJson(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 getJson(video_new_info);
|
||||||
|
|
||||||
const a = await fetch(
|
const a = await fetch(`${config.tubeApi}channel?id=${vid.authorId}&tab=about`)
|
||||||
`${config.tubeApi}channel?id=${vid.authorId}&tab=about`
|
|
||||||
)
|
|
||||||
.then((res) => res.text())
|
.then((res) => res.text())
|
||||||
.then((xml) => JSON.parse(toJson(xml)));
|
.then((xml) => getJson(toJson(xml)));
|
||||||
|
|
||||||
const summary = await wiki
|
const summary = await wiki
|
||||||
.summary(vid.author + " ")
|
.summary(vid.author + " ")
|
||||||
.then((summary_) =>
|
.then((summary_) => (summary_.title !== "Not found." ? summary_ : "none"));
|
||||||
summary_.title !== "Not found." ? summary_ : "none"
|
|
||||||
);
|
|
||||||
|
|
||||||
const desc = a.Channel?.Contents.ItemSection.About.Description;
|
const desc = a.Channel?.Contents.ItemSection.About.Description;
|
||||||
|
|
||||||
|
|
||||||
const data = await fetcher(v);
|
const data = await fetcher(v);
|
||||||
|
|
||||||
const nightlyJsonData = getJson(nightlyRes);
|
const nightlyJsonData = getJson(nightlyRes);
|
||||||
return {
|
return {
|
||||||
json: data.video.Player,
|
json: data.video.Player,
|
||||||
video: await fetch(`${config.tubeApi}video?v=${v}`).then((res) => res.text()) .then((xml) => JSON.parse(toJson(xml))),
|
video: await fetch(`${config.tubeApi}video?v=${v}`)
|
||||||
|
.then((res) => res.text())
|
||||||
|
.then((xml) => getJson(toJson(xml))),
|
||||||
vid,
|
vid,
|
||||||
comments,
|
comments,
|
||||||
engagement: data.engagement,
|
engagement: data.engagement,
|
||||||
|
@ -104,7 +100,6 @@ 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()),
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function search(query, cnt) {
|
async function search(query, cnt) {
|
||||||
|
@ -114,7 +109,7 @@ async function search(query, cnt) {
|
||||||
`${config.tubeApi}search?query=${query}&continuation=${cnt || ""}`
|
`${config.tubeApi}search?query=${query}&continuation=${cnt || ""}`
|
||||||
)
|
)
|
||||||
.then((res) => res.text())
|
.then((res) => res.text())
|
||||||
.then((xml) => JSON.parse(toJson(xml)));
|
.then((xml) => getJson(toJson(xml)));
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue