Refactor code :3

This commit is contained in:
Ashley 2023-02-25 17:20:38 +00:00
parent 95300983c8
commit 03755a8e3b

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,240 +173,173 @@ 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") { core.video(v).then((data) => {
verify = true; try {
} else { const k = data.video;
verify = false; const json = data.json;
} const engagement = data.engagement;
const inv_comments = data.comments || "Disabled";
const inv_vid = data.vid;
const desc = data.desc || "";
try { let d = false;
const info = await modules.fetch("http://ip-api.com/json/"); if (desc !== "[object Object]") {
const jj = await info.text(); d = desc.toString().replace(/\n/g, " <br> ");
const ip = JSON.parse(jj); }
if (isvld) { let support;
core.video(v).then((data) => { if (String(json.Description) !== "[object Object]") {
if (data) { support = (PATREON_REGEX.exec(json.Description) ?? {}).groups;
if ("video" in data) { }
const k = data.video;
const json = data.json;
const engagement = data.engagement;
var inv_comments = data.comments;
const inv_vid = data.vid;
//checks if json exists
if (json) { let badges = "";
//checks if title exists in the json object let comments = "";
let nnn = "";
if (!core.video(v).b && !v) {
badges = "";
comments = "";
nnn = "";
}
if ("Title" in json) { let url;
if (!data.comments) inv_comments = "Disabled"; if (q === "medium") {
url = `https://inv.vern.cc/latest_version?id=${v}&itag=18&local=true`;
}
if (!core.video(v).b) { renderTemplate(res, req, "poketube.ejs", {
var nnn = ""; color: data.color,
var badges = ""; color2: data.color2,
var comments = ""; engagement,
} support,
u,
if (!v) res.redirect("/"); video: json,
date: k.Video.uploadDate,
if (q === "medium") { e,
var url = `https://inv.vern.cc/latest_version?id=${v}&itag=18&local=true`; a,
} k,
verify,
const desc = data.desc; secure,
process,
if (d) { sha384,
var d = desc.toString().replace(/\n/g, " <br> "); lightOrDark,
} isMobile: req.useragent.isMobile,
tj: data.channel,
if (d === "[object Object]") { r,
var d = false; qua: q,
} inv: inv_comments,
ip,
if (String(json.Description) != "[object Object]"){ convert,
var support = (PATREON_REGEX.exec(json.Description) ?? {}).groups wiki: data.wiki,
} f,
t: config.t_url,
renderTemplate(res, req, "poketube.ejs", { optout: t,
color: data.color, badges,
color2: data.color2, desc,
engagement: engagement, comments,
support, n: nnn,
u, inv_vid,
video: json, lyrics: "",
date: k.Video.uploadDate,
e,
a,
k,
verify,
secure,
process,
sha384,
lightOrDark,
isMobile: req.useragent.isMobile,
tj: data.channel,
r: r,
qua: q,
inv: inv_comments,
ip: ip,
convert: convert,
wiki: data.wiki,
f: f,
t: config.t_url,
optout: t,
badges: badges,
desc: desc,
comments: comments,
n: nnn,
inv_vid,
lyrics: "",
});
}
}
}
} else {
res.redirect("/?fromerror=24");
}
}); });
} else { } catch {
res.redirect("/?fromerror=21"); return res.redirect("/?fromerror=43");
} }
} catch { });
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;
const info = await modules.fetch("http://ip-api.com/json/"); try {
const jj = await info.text(); const info = await modules.fetch("http://ip-api.com/json/");
const ip = JSON.parse(jj); const ip = await info.json();
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("/"); const data = await core.video(v);
const color = data.color;
const color2 = data.color2;
const desc = data.desc;
const isMobile = req.useragent.isMobile;
const wiki = data.wiki;
const { channel: tj } = data;
if (q === "medium") { const d = desc.toString().replace(/\n/g, " <br> ");
var url = `https://inv.vern.cc/latest_version?id=${v}&itag=18&local=true`; const comments = inv_comments || "Disabled";
}
const desc = data.desc; const url =
if (d) { q === "medium"
var d = desc.toString().replace(/\n/g, " <br> "); ? `https://inv.vern.cc/latest_version?id=${v}&itag=18&local=true`
} : null;
if (d === "[object Object]") { const templateData = {
var d = false; color,
} color2,
engagement,
video: json,
date: k.Video.uploadDate,
e,
k,
process,
sha384,
lightOrDark,
isMobile,
tj,
r,
qua: q,
inv: comments,
ip,
convert,
wiki,
f,
t: config.t_url,
optout: t,
badges: "",
desc,
comments,
n: "",
inv_vid,
lyrics: "",
};
renderTemplate(res, req, "lite.ejs", { renderTemplate(res, req, "lite.ejs", templateData);
color: data.color, } catch (error) {
color2: data.color2, console.error(error);
engagement: engagement,
video: json,
date: k.Video.uploadDate,
e: e,
k: k,
process: process,
sha384: sha384,
lightOrDark,
isMobile: req.useragent.isMobile,
tj: data.channel,
r: r,
qua: q,
inv: inv_comments,
ip: ip,
convert: convert,
wiki: data.wiki,
f: f,
t: config.t_url,
optout: t,
badges: badges,
desc: desc,
comments: comments,
n: nnn,
inv_vid,
lyrics: "",
});
}
}
}
} else {
res.redirect("/");
}
});
} else {
res.redirect("/"); res.redirect("/");
} }
}); });
@ -464,11 +397,11 @@ module.exports = function (app, config, renderTemplate) {
sha384(config.t_url); sha384(config.t_url);
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
* Copyright (c) 2023 Apple Inc. All rights reserved. * Copyright (c) 2023 Apple Inc. All rights reserved.
@ -489,7 +422,7 @@ module.exports = function (app, config, renderTemplate) {
* *
* @APPLE_APACHE_LICENSE_HEADER_END@ * @APPLE_APACHE_LICENSE_HEADER_END@
*/ */
if (mos) { if (mos) {
var url_e = var url_e =
mos.url + mos.url +
@ -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