mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 18:18:13 +01:00
fix some issues regarding the api :3
This commit is contained in:
parent
4fd817e999
commit
1e1b9fd628
1 changed files with 43 additions and 15 deletions
54
server.js
54
server.js
|
@ -85,6 +85,15 @@ const config = {
|
||||||
// pages
|
// pages
|
||||||
|
|
||||||
|
|
||||||
|
function IsJsonString(str) {
|
||||||
|
try {
|
||||||
|
JSON.parse(str);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
|
|
||||||
|
@ -168,22 +177,41 @@ app.get("/watch", async function (req, res) {
|
||||||
const info = await fetch("http://ip-api.com/json/");
|
const info = await fetch("http://ip-api.com/json/");
|
||||||
const jj = await info.text();
|
const jj = await info.text();
|
||||||
const ip = JSON.parse(jj);
|
const ip = JSON.parse(jj);
|
||||||
|
var badges = ""
|
||||||
|
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
try {
|
||||||
|
const nightly = await fetch(
|
||||||
|
`https://lighttube-nightly.kuylar.dev/api/video?v=${v}`
|
||||||
|
);
|
||||||
|
var n = await nightly.text();
|
||||||
|
} catch (err) {
|
||||||
|
if (err.status === 503) {
|
||||||
|
// retry after a bit
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
} else {
|
||||||
|
return (n = "none");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const nightly = await fetch(`https://lighttube-nightly.kuylar.dev/api/video?v=${v}`);
|
|
||||||
var n = await nightly.text().catch(() => null);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var nn = "";
|
var nn = "";
|
||||||
|
|
||||||
var badges = ""
|
if (n === "none") {badges = "";}
|
||||||
if (n === undefined) {badges = "";}
|
if(IsJsonString(n)){
|
||||||
if (n !== undefined) {badges = JSON.parse(n).channel.badges[0]}
|
|
||||||
|
if (n !== "none") {badges = JSON.parse(n).channel.badges[0]}
|
||||||
|
}
|
||||||
|
|
||||||
var comments = ""
|
var comments = ""
|
||||||
if (n === undefined) { comments = ""; }
|
if (n === "none") { comments = ""; }
|
||||||
if (n !== undefined) { comments = JSON.parse(n).commentCount }
|
if(IsJsonString(n)){
|
||||||
|
if (n !== "none") { comments = JSON.parse(n).commentCount }
|
||||||
|
}
|
||||||
|
|
||||||
var fetching = await fetcher(v);
|
var fetching = await fetcher(v);
|
||||||
|
|
||||||
|
@ -197,20 +225,20 @@ app.get("/watch", async function (req, res) {
|
||||||
if (q === "medium") {
|
if (q === "medium") {
|
||||||
var url = `https://tube.kuylar.dev/proxy/media/${v}/18`;
|
var url = `https://tube.kuylar.dev/proxy/media/${v}/18`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// encryption
|
// encryption
|
||||||
const url_e =
|
const url_e =
|
||||||
url +
|
url +
|
||||||
"?e=" +
|
"?e=" +
|
||||||
sha384(json.Title) +
|
sha384(k.Video.Channel.id) +
|
||||||
sha384(json.Channel.id) +
|
sha384(k.Video.Channel.id) +
|
||||||
sha384(json.Channel.id) +
|
|
||||||
"Piwik" +
|
"Piwik" +
|
||||||
sha384(config.t_url);
|
sha384(config.t_url);
|
||||||
|
|
||||||
// channel info
|
// channel info
|
||||||
const engagement = fetching.engagement;
|
const engagement = fetching.engagement;
|
||||||
const channel = await fetch(
|
const channel = await fetch(
|
||||||
config.tubeApi + `channel?id=${json.Channel.id}&tab=videos`
|
config.tubeApi + `channel?id=${k.Video.Channel.id}&tab=videos`
|
||||||
);
|
);
|
||||||
const c = await channel.text();
|
const c = await channel.text();
|
||||||
const tj = JSON.parse(toJson(c));
|
const tj = JSON.parse(toJson(c));
|
||||||
|
@ -218,7 +246,7 @@ app.get("/watch", async function (req, res) {
|
||||||
// lyrics
|
// lyrics
|
||||||
const lyrics = await lyricsFinder(json.Title);
|
const lyrics = await lyricsFinder(json.Title);
|
||||||
|
|
||||||
const summary = await wiki.summary(json.Channel.Name);
|
const summary = await wiki.summary(k.Video.Channel.Name);
|
||||||
|
|
||||||
var w = ""
|
var w = ""
|
||||||
if(summary.title === "Not found.") { w = "none" }
|
if(summary.title === "Not found.") { w = "none" }
|
||||||
|
|
Loading…
Reference in a new issue