reformat file

This commit is contained in:
Ashley 2022-09-29 21:15:42 +02:00
parent 99501793c2
commit 84f8759522

View file

@ -93,9 +93,9 @@ function IsJsonString(str) {
} }
function convert(value) { function convert(value) {
return new Intl.NumberFormat('en-GB', { return new Intl.NumberFormat("en-GB", {
notation: "compact" notation: "compact",
}).format(value); }).format(value);
} }
function getFirstLine(text) { function getFirstLine(text) {
@ -104,7 +104,6 @@ function getFirstLine(text) {
return text.substring(0, index); return text.substring(0, index);
} }
///////////////////////////////// /////////////////////////////////
app.use(function (req, res, next) { app.use(function (req, res, next) {
@ -178,17 +177,28 @@ app.get("/watch", async function (req, res) {
var badges = ""; var badges = "";
// try few times, thanks kuylar // try few times, thanks kuylar
for (let i = 0; i < 5; i++) { for (let i = 0; i < 3; i++) {
try { try {
const nightly = await fetch( const nightly = await fetch(
`https://lighttube-nightly.kuylar.dev/api/video?v=${v}` `https://lighttube-nightly.kuylar.dev/api/video?v=${v}`
); );
var n = await nightly.text(); var n = await nightly.text();
if (n == undefined) {
if(n == undefined) { for (let i = 0; i < 6; i++) {
for(let i=0;i<3;i+=1){try{const nightly=await fetch(`https://lighttube-nightly.kuylar.dev/api/video?v=${ v }`);var n=await nightly.text()}catch(err){if(err.status===500){await new Promise((resolve)=>setTimeout(resolve,1000))}else{return(n="")}}} try {
const nightly = await fetch(
`https://lighttube-nightly.kuylar.dev/api/video?v=${v}`
);
var n = await nightly.text();
} catch (err) {
if (err.status === 500) {
await new Promise((resolve) => setTimeout(resolve, 1000));
} else {
return (n = "");
}
}
}
} }
} catch (err) { } catch (err) {
if (err.status === 500) { if (err.status === 500) {
// retry after a bit // retry after a bit
@ -204,7 +214,7 @@ app.get("/watch", async function (req, res) {
var comments = ""; var comments = "";
if (n == "") { if (n == "") {
badges, nnn, comments = ""; badges, nnn, (comments = "");
} }
if (IsJsonString(n)) { if (IsJsonString(n)) {
@ -270,7 +280,7 @@ app.get("/watch", async function (req, res) {
w = summary; w = summary;
} }
/*********** /***********
* URL = Video URl * URL = Video URl
* color= embed color * color= embed color
* engagement = engagement data * engagement = engagement data
@ -297,7 +307,9 @@ app.get("/watch", async function (req, res) {
*/ */
renderTemplate(res, req, "poketube.ejs", { renderTemplate(res, req, "poketube.ejs", {
url: url_e, url: url_e,
color: await getColors( `https://i.ytimg.com/vi/${v}/maxresdefault.jpg` ).then((colors) => colors[0].hex()), color: await getColors(
`https://i.ytimg.com/vi/${v}/maxresdefault.jpg`
).then((colors) => colors[0].hex()),
engagement: engagement, engagement: engagement,
video: json, video: json,
date: moment(k.Video.uploadDate).format("LL"), date: moment(k.Video.uploadDate).format("LL"),
@ -316,7 +328,7 @@ app.get("/watch", async function (req, res) {
t: config.t_url, t: config.t_url,
optout: t, optout: t,
badges: badges, badges: badges,
desc:desc, desc: desc,
comments: comments, comments: comments,
n: nnn, n: nnn,
lyrics: "", lyrics: "",
@ -353,8 +365,6 @@ app.get("/music", async function (req, res) {
const h = await video.text(); const h = await video.text();
const k = JSON.parse(toJson(h)); const k = JSON.parse(toJson(h));
if (!json.Channel.Name.endsWith(" - Topic")) { if (!json.Channel.Name.endsWith(" - Topic")) {
res.redirect(`/watch?v=${v}`); res.redirect(`/watch?v=${v}`);
} }
@ -362,7 +372,6 @@ app.get("/music", async function (req, res) {
//video //video
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 +
@ -372,7 +381,6 @@ app.get("/music", async function (req, res) {
"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(
@ -471,10 +479,16 @@ app.get("/search", async (req, res) => {
const { toJson } = require("xml2json"); const { toJson } = require("xml2json");
const query = req.query.query; const query = req.query.query;
if(req.query.continuation){ var continuation = req.query.continuation } if (req.query.continuation) {
if(!req.query.continuation){ var continuation = "" } var continuation = req.query.continuation;
}
if (!req.query.continuation) {
var continuation = "";
}
const search = await fetch(`https://tube.kuylar.dev/api/search?query=${query}&continuation=${continuation}`); const search = await fetch(
`https://tube.kuylar.dev/api/search?query=${query}&continuation=${continuation}`
);
const text = await search.text(); const text = await search.text();
const j = JSON.parse(toJson(text)); const j = JSON.parse(toJson(text));
@ -498,18 +512,20 @@ app.get("/channel/", async (req, res) => {
const h = await bout.text(); const h = await bout.text();
const k = JSON.parse(toJson(h)); const k = JSON.parse(toJson(h));
if (req.query.continuation) {
if(req.query.continuation){ var continuation = req.query.continuation } var continuation = req.query.continuation;
if(!req.query.continuation){ var continuation = "" } }
if (!req.query.continuation) {
var continuation = "";
}
//videos //videos
const channel = await fetch(config.tubeApi + `channel?id=${ID}&tab=videos&Continuation=${continuation}`); const channel = await fetch(
config.tubeApi + `channel?id=${ID}&tab=videos&Continuation=${continuation}`
);
const c = await channel.text(); const c = await channel.text();
const tj = JSON.parse(toJson(c)); const tj = JSON.parse(toJson(c));
const summary = await wiki.summary(k.Channel.Metadata.Name); const summary = await wiki.summary(k.Channel.Metadata.Name);
var w = ""; var w = "";
@ -528,21 +544,20 @@ app.get("/channel/", async (req, res) => {
var d = ""; var d = "";
} }
var dnoreplace = description.toString() var dnoreplace = description.toString();
if (dnoreplace === "[object Object]") { if (dnoreplace === "[object Object]") {
var dnoreplace = ""; var dnoreplace = "";
} }
renderTemplate(res, req, "channel.ejs", { renderTemplate(res, req, "channel.ejs", {
ID: ID, ID: ID,
tab: tab, tab: tab,
j: k, j: k,
tj: tj, tj: tj,
dnoreplace:dnoreplace, dnoreplace: dnoreplace,
continuation:continuation, continuation: continuation,
wiki: w, wiki: w,
getFirstLine:getFirstLine, getFirstLine: getFirstLine,
isMobile: req.useragent.isMobile, isMobile: req.useragent.isMobile,
about: k.Channel.Contents.ItemSection.About, about: k.Channel.Contents.ItemSection.About,
subs: subs:
@ -578,7 +593,6 @@ app.get("/js/:id", (req, res) => {
res.sendFile(__dirname + `/js/${req.params.id}`); res.sendFile(__dirname + `/js/${req.params.id}`);
}); });
///////////// API ///////////// ///////////// API /////////////
app.get("/embed/:v", async function (req, res) { app.get("/embed/:v", async function (req, res) {