Refactor code, add more gooda error thingy :3

This commit is contained in:
Ashley 2022-11-14 18:36:00 +01:00
parent cfb03a6003
commit 5b747a82dd

View file

@ -1,4 +1,13 @@
const { fetcher,core, wiki,musicInfo, modules, version, initlog, init,} = require("../libpoketube-initsys.js"); const {
fetcher,
core,
wiki,
musicInfo,
modules,
version,
initlog,
init,
} = require("../libpoketube-initsys.js");
const { const {
IsJsonString, IsJsonString,
convert, convert,
@ -47,9 +56,9 @@ module.exports = function (app, config, renderTemplate) {
}; };
res.json(re); res.json(re);
}); });
app.get("/watch", async function (req, res) { app.get("/watch", async function (req, res) {
/* /*
* QUERYS * QUERYS
* v = Video ID * v = Video ID
@ -69,7 +78,9 @@ app.get("/watch", async function (req, res) {
const info = await modules.fetch("http://ip-api.com/json/"); const info = await modules.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);
const isvld = await core.isvalidvideo(v);
if (isvld) {
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
try { try {
core.video(v).then((data) => { core.video(v).then((data) => {
@ -93,25 +104,16 @@ app.get("/watch", async function (req, res) {
var url = `https://inv.vern.cc/latest_version?id=${v}&itag=18&local=true`; var url = `https://inv.vern.cc/latest_version?id=${v}&itag=18&local=true`;
} }
// encryption
const url_e =
url +
"?e=" +
sha384(k.Video.Channel.id) +
sha384(k.Video.Channel.id) +
"Piwik" +
sha384(config.t_url);
const desc = data.desc; const desc = data.desc;
if (d) {
var d = desc.toString().replace(/\n/g, " <br> "); var d = desc.toString().replace(/\n/g, " <br> ");
}
if (d === "[object Object]") { if (d === "[object Object]") {
var d = false; var d = false;
} }
renderTemplate(res, req, "poketube.ejs", { renderTemplate(res, req, "poketube.ejs", {
url: url_e,
color: data.color, color: data.color,
engagement: engagement, engagement: engagement,
video: json, video: json,
@ -149,9 +151,12 @@ app.get("/watch", async function (req, res) {
} }
} }
} }
}); } else {
res.redirect("/");
}
});
app.get("/music", async function (req, res) { app.get("/music", async function (req, res) {
/* /*
* QUERYS * QUERYS
* v = Video ID * v = Video ID
@ -208,7 +213,10 @@ app.get("/music", async function (req, res) {
// info // info
const song = await musicInfo.searchSong( const song = await musicInfo.searchSong(
{ title: k.Video.Title, artist: json.Channel.Name.replace("- Topic", "") }, {
title: k.Video.Title,
artist: json.Channel.Name.replace("- Topic", ""),
},
1000 1000
); );
@ -251,5 +259,5 @@ app.get("/music", async function (req, res) {
optout: t, optout: t,
lyrics: ly, lyrics: ly,
}); });
}); });
} };