1
0
Fork 0
mirror of https://codeberg.org/ashley/poke.git synced 2024-11-17 16:34:38 -05:00

Refactor code :3

This commit is contained in:
Ashley 2023-02-25 17:20:38 +00:00
parent b149d3e365
commit 96c46abe1f

View file

@ -124,7 +124,7 @@ function getJson(str) {
} }
} }
const PATREON_REGEX = /https:\/\/www.patreon.com\/(?<name>[\w\d_-]+)/ const PATREON_REGEX = /https:\/\/www.patreon.com\/(?<name>[\w\d_-]+)/;
module.exports = function (app, config, renderTemplate) { module.exports = function (app, config, renderTemplate) {
app.get("/encryption", async function (req, res) { app.get("/encryption", async function (req, res) {
@ -173,102 +173,68 @@ module.exports = function (app, config, renderTemplate) {
} }
}); });
app.get("/watch", async function (req, res) { app.get("/watch", async (req, res) => {
/* const { v, e, r, f, t, quality: q, a } = req.query;
* QUERYS
* v = Video ID
* e = Embed
* r = Recommended videos
* f = Recent videos from channel
* t = Piwik OptOut
* q = quality obv
* a = ambient mode
*/
var v = req.query.v;
var e = req.query.e;
var r = req.query.r;
var f = req.query.f;
var t = req.query.t;
var q = req.query.quality;
var a = req.query.a;
const isvld = await core.isvalidvideo(v); if (!v) {
if (!v) res.redirect("/"); return res.redirect("/");
}
const isVideoValid = await core.isvalidvideo(v);
if (!isVideoValid) {
return res.redirect("/?fromerror=21");
}
const u = await media_proxy(v); const u = await media_proxy(v);
var secure; const secure = [
var verify; "poketube.fun",
"poketube.site",
"poketube.online",
"poketube.xyz",
].includes(req.hostname);
const verify = req.hostname === "pt.zzls.xyz";
if ( const response = await modules.fetch("http://ip-api.com/json/");
req.hostname == "poketube.fun" || const ip = await response.json();
req.hostname == "poketube.site" ||
req.hostname == "poketube.online" ||
req.hostname == "poketube.xyz"
) {
secure = true;
} else {
secure = false;
}
if (req.hostname == "pt.zzls.xyz") {
verify = true;
} else {
verify = false;
}
try {
const info = await modules.fetch("http://ip-api.com/json/");
const jj = await info.text();
const ip = JSON.parse(jj);
if (isvld) {
core.video(v).then((data) => { core.video(v).then((data) => {
if (data) { try {
if ("video" in data) {
const k = data.video; const k = data.video;
const json = data.json; const json = data.json;
const engagement = data.engagement; const engagement = data.engagement;
var inv_comments = data.comments; const inv_comments = data.comments || "Disabled";
const inv_vid = data.vid; const inv_vid = data.vid;
//checks if json exists const desc = data.desc || "";
if (json) { let d = false;
//checks if title exists in the json object if (desc !== "[object Object]") {
d = desc.toString().replace(/\n/g, " <br> ");
if ("Title" in json) {
if (!data.comments) inv_comments = "Disabled";
if (!core.video(v).b) {
var nnn = "";
var badges = "";
var comments = "";
} }
if (!v) res.redirect("/"); let support;
if (String(json.Description) !== "[object Object]") {
support = (PATREON_REGEX.exec(json.Description) ?? {}).groups;
}
let badges = "";
let comments = "";
let nnn = "";
if (!core.video(v).b && !v) {
badges = "";
comments = "";
nnn = "";
}
let url;
if (q === "medium") { if (q === "medium") {
var url = `https://inv.vern.cc/latest_version?id=${v}&itag=18&local=true`; url = `https://inv.vern.cc/latest_version?id=${v}&itag=18&local=true`;
}
const desc = data.desc;
if (d) {
var d = desc.toString().replace(/\n/g, " <br> ");
}
if (d === "[object Object]") {
var d = false;
}
if (String(json.Description) != "[object Object]"){
var support = (PATREON_REGEX.exec(json.Description) ?? {}).groups
} }
renderTemplate(res, req, "poketube.ejs", { renderTemplate(res, req, "poketube.ejs", {
color: data.color, color: data.color,
color2: data.color2, color2: data.color2,
engagement: engagement, engagement,
support, support,
u, u,
video: json, video: json,
@ -283,130 +249,97 @@ module.exports = function (app, config, renderTemplate) {
lightOrDark, lightOrDark,
isMobile: req.useragent.isMobile, isMobile: req.useragent.isMobile,
tj: data.channel, tj: data.channel,
r: r, r,
qua: q, qua: q,
inv: inv_comments, inv: inv_comments,
ip: ip, ip,
convert: convert, convert,
wiki: data.wiki, wiki: data.wiki,
f: f, f,
t: config.t_url, t: config.t_url,
optout: t, optout: t,
badges: badges, badges,
desc: desc, desc,
comments: comments, comments,
n: nnn, n: nnn,
inv_vid, inv_vid,
lyrics: "", lyrics: "",
}); });
}
}
}
} else {
res.redirect("/?fromerror=24");
}
});
} else {
res.redirect("/?fromerror=21");
}
} catch { } catch {
return res.redirect("/?fromerror=43"); return res.redirect("/?fromerror=43");
} }
}); });
});
app.get("/lite", async function (req, res) { app.get("/lite", async function (req, res) {
/* const { v, e, r, f, t, quality: q } = req.query;
* QUERYS
* v = Video ID
* e = Embed
* r = Recommended videos
* f = Recent videos from channel
* t = Piwik OptOut
* q = quality obv
*/
var v = req.query.v;
var e = req.query.e;
var r = req.query.r;
var f = req.query.f;
var t = req.query.t;
var q = req.query.quality;
try {
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 ip = await info.json();
const ip = JSON.parse(jj);
const isvld = await core.isvalidvideo(v);
if (isvld) { const {
core.video(v).then((data) => { video: k,
if (data) { json,
if (data.video) { engagement,
const k = data.video; comments: inv_comments,
const json = data.json; vid: inv_vid,
const engagement = data.engagement; } = await core.video(v);
var inv_comments = data.comments;
const inv_vid = data.vid;
if (json) {
if (json.Title) {
if (!data.comments) inv_comments = "Disabled";
if (!core.video(v).b) { if (!k || !json || !json.Title) {
var nnn = ""; res.redirect("/");
var badges = ""; return;
var comments = "";
}
if (!v) res.redirect("/");
if (q === "medium") {
var url = `https://inv.vern.cc/latest_version?id=${v}&itag=18&local=true`;
} }
const data = await core.video(v);
const color = data.color;
const color2 = data.color2;
const desc = data.desc; const desc = data.desc;
if (d) { const isMobile = req.useragent.isMobile;
var d = desc.toString().replace(/\n/g, " <br> "); const wiki = data.wiki;
} const { channel: tj } = data;
if (d === "[object Object]") { const d = desc.toString().replace(/\n/g, " <br> ");
var d = false; const comments = inv_comments || "Disabled";
}
renderTemplate(res, req, "lite.ejs", { const url =
color: data.color, q === "medium"
color2: data.color2, ? `https://inv.vern.cc/latest_version?id=${v}&itag=18&local=true`
engagement: engagement, : null;
const templateData = {
color,
color2,
engagement,
video: json, video: json,
date: k.Video.uploadDate, date: k.Video.uploadDate,
e: e, e,
k: k, k,
process: process, process,
sha384: sha384, sha384,
lightOrDark, lightOrDark,
isMobile: req.useragent.isMobile, isMobile,
tj: data.channel, tj,
r: r, r,
qua: q, qua: q,
inv: inv_comments, inv: comments,
ip: ip, ip,
convert: convert, convert,
wiki: data.wiki, wiki,
f: f, f,
t: config.t_url, t: config.t_url,
optout: t, optout: t,
badges: badges, badges: "",
desc: desc, desc,
comments: comments, comments,
n: nnn, n: "",
inv_vid, inv_vid,
lyrics: "", lyrics: "",
}); };
}
} renderTemplate(res, req, "lite.ejs", templateData);
} } catch (error) {
} else { console.error(error);
res.redirect("/");
}
});
} else {
res.redirect("/"); res.redirect("/");
} }
}); });
@ -465,8 +398,8 @@ module.exports = function (app, config, renderTemplate) {
const stringed = toObject(atmos); const stringed = toObject(atmos);
const search = what => atmos.find(element => element.id === what); const search = (what) => atmos.find((element) => element.id === what);
const mos = search(v) const mos = search(v);
/* /*
this is only for the alac codec being used this is only for the alac codec being used
@ -499,7 +432,6 @@ module.exports = function (app, config, renderTemplate) {
"Piwik" + "Piwik" +
sha384(config.t_url); sha384(config.t_url);
} else { } else {
} }
// channel info // channel info