refactor code

This commit is contained in:
Ashley 2023-12-11 22:13:28 +00:00
parent 078266099d
commit 34d3f49bda

View file

@ -27,7 +27,8 @@ function linkify(text) {
return text.replace(urlRegex, (url) => { return text.replace(urlRegex, (url) => {
// wrap the URL in an <a> tag with the URL as the href attribute // wrap the URL in an <a> tag with the URL as the href attribute
return `<a href="/api/redirect?u=${btoa(url return `<a href="/api/redirect?u=${btoa(
url
.replace(/twitter\.com/g, "nitter.net") .replace(/twitter\.com/g, "nitter.net")
.replace(/reddit\.com/g, "teddit.net") .replace(/reddit\.com/g, "teddit.net")
.replace("https://youtube.com", "") .replace("https://youtube.com", "")
@ -37,14 +38,13 @@ function linkify(text) {
} }
function channelurlfixer(text) { function channelurlfixer(text) {
// Create a regular expression to match <a> tags with href containing "/channel/" // Create a regular expression to match <a> tags with href containing "/channel/"
const regex = /<a\s+href="\/channel\/([^"]+)"/g; const regex = /<a\s+href="\/channel\/([^"]+)"/g;
// Replace matching <a> tags with the modified href attribute // Replace matching <a> tags with the modified href attribute
const updatedDescription = text.replace(regex, '<a href="/channel?id=$1"'); const updatedDescription = text.replace(regex, '<a href="/channel?id=$1"');
return updatedDescription; return updatedDescription;
} }
function endsWithYouTubeAutoGenerated(text) { function endsWithYouTubeAutoGenerated(text) {
const target = " Auto-generated by YouTube. "; const target = " Auto-generated by YouTube. ";
return text.endsWith(target); return text.endsWith(target);
@ -178,7 +178,19 @@ module.exports = function (app, config, renderTemplate) {
}); });
app.get("/watch", async (req, res) => { app.get("/watch", async (req, res) => {
const { dm, region, hl, v, e, r, f, m, quality: q, a, universe } = req.query; const {
dm,
region,
hl,
v,
e,
r,
f,
m,
quality: q,
a,
universe,
} = req.query;
if (!v) { if (!v) {
return res.redirect("/"); return res.redirect("/");
@ -226,14 +238,21 @@ module.exports = function (app, config, renderTemplate) {
const reddit = extractInfo(REDDIT_REGEX); const reddit = extractInfo(REDDIT_REGEX);
const instagram = extractInfo(INSTAGRAM_REGEX); const instagram = extractInfo(INSTAGRAM_REGEX);
var vidurl = u.url var vidurl = u.url;
var isvidious = u.isInvidiousURL;
if(inv_vid?.genre === "Music") { if (inv_vid?.genre === "Music") {
var vidurl = u.losslessurl var vidurl = u.losslessurl;
} }
if(req.useragent.source.includes("Pardus")){ if (inv_vid.author.endsWith(" - Topic")) {
var vidurl = "https://yt.sudovanilla.com" var vidurl = u.losslessurl;
var isvidious = true;
}
if (req.useragent.source.includes("Pardus")) {
var vidurl = "https://yt.sudovanilla.com";
var isvidious = true;
} }
let badges = ""; let badges = "";
@ -259,7 +278,7 @@ module.exports = function (app, config, renderTemplate) {
if (uaos === "Windows XP" || uaos === "Windows Vista") if (uaos === "Windows XP" || uaos === "Windows Vista")
res.redirect("/lite?v=" + req.query.v); res.redirect("/lite?v=" + req.query.v);
if (req.query.from === "short") var shortsui = true if (req.query.from === "short") var shortsui = true;
try { try {
renderTemplate(res, req, "poketube.ejs", { renderTemplate(res, req, "poketube.ejs", {
@ -272,7 +291,7 @@ module.exports = function (app, config, renderTemplate) {
support, support,
shortsui, shortsui,
u: vidurl, u: vidurl,
isvidious: u.isInvidiousURL, isvidious: isvidious,
video: json, video: json,
date: k.Video.uploadDate, date: k.Video.uploadDate,
e, e,
@ -280,7 +299,7 @@ module.exports = function (app, config, renderTemplate) {
twitter, twitter,
k, k,
dm, dm,
media_proxy_url : config.media_proxy, media_proxy_url: config.media_proxy,
instagram, instagram,
useragent: req.useragent, useragent: req.useragent,
verify, verify,