mirror of
https://codeberg.org/ashley/poke.git
synced 2024-12-26 05:08:39 +01:00
refactor code
This commit is contained in:
parent
078266099d
commit
34d3f49bda
1 changed files with 48 additions and 29 deletions
|
@ -27,7 +27,8 @@ function linkify(text) {
|
|||
|
||||
return text.replace(urlRegex, (url) => {
|
||||
// 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(/reddit\.com/g, "teddit.net")
|
||||
.replace("https://youtube.com", "")
|
||||
|
@ -37,13 +38,12 @@ function linkify(text) {
|
|||
}
|
||||
|
||||
function channelurlfixer(text) {
|
||||
// Create a regular expression to match <a> tags with href containing "/channel/"
|
||||
const regex = /<a\s+href="\/channel\/([^"]+)"/g;
|
||||
// Replace matching <a> tags with the modified href attribute
|
||||
const updatedDescription = text.replace(regex, '<a href="/channel?id=$1"');
|
||||
return updatedDescription;
|
||||
}
|
||||
|
||||
// Create a regular expression to match <a> tags with href containing "/channel/"
|
||||
const regex = /<a\s+href="\/channel\/([^"]+)"/g;
|
||||
// Replace matching <a> tags with the modified href attribute
|
||||
const updatedDescription = text.replace(regex, '<a href="/channel?id=$1"');
|
||||
return updatedDescription;
|
||||
}
|
||||
|
||||
function endsWithYouTubeAutoGenerated(text) {
|
||||
const target = " Auto-generated by YouTube. ";
|
||||
|
@ -178,14 +178,26 @@ module.exports = function (app, config, renderTemplate) {
|
|||
});
|
||||
|
||||
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) {
|
||||
return res.redirect("/");
|
||||
}
|
||||
|
||||
var contentlang = hl || "en-US";
|
||||
var contentregion = region || "US";
|
||||
|
||||
var contentlang = hl || "en-US";
|
||||
var contentregion = region || "US";
|
||||
|
||||
const isVideoValid = await core.isvalidvideo(v);
|
||||
if (!isVideoValid) {
|
||||
|
@ -193,7 +205,7 @@ module.exports = function (app, config, renderTemplate) {
|
|||
}
|
||||
|
||||
const u = await media_proxy(v);
|
||||
|
||||
|
||||
const secure = ["poketube.fun"].includes(req.hostname);
|
||||
const verify = req.hostname === "poketube.sudovanilla.com";
|
||||
|
||||
|
@ -205,14 +217,14 @@ module.exports = function (app, config, renderTemplate) {
|
|||
const inv_comments = data?.comments || "Disabled";
|
||||
const inv_vid = data?.vid;
|
||||
const desc = data?.desc || "";
|
||||
|
||||
|
||||
let d = false;
|
||||
if (desc !== "[object Object]") {
|
||||
d = desc.toString().replace(/\n/g, " <br> ");
|
||||
}
|
||||
|
||||
const descriptionString = String(inv_vid?.description);
|
||||
|
||||
|
||||
function extractInfo(regex) {
|
||||
return descriptionString !== "[object Object]"
|
||||
? (regex.exec(descriptionString) ?? {}).groups
|
||||
|
@ -226,14 +238,21 @@ module.exports = function (app, config, renderTemplate) {
|
|||
const reddit = extractInfo(REDDIT_REGEX);
|
||||
const instagram = extractInfo(INSTAGRAM_REGEX);
|
||||
|
||||
var vidurl = u.url
|
||||
|
||||
if(inv_vid?.genre === "Music") {
|
||||
var vidurl = u.losslessurl
|
||||
}
|
||||
|
||||
if(req.useragent.source.includes("Pardus")){
|
||||
var vidurl = "https://yt.sudovanilla.com"
|
||||
var vidurl = u.url;
|
||||
var isvidious = u.isInvidiousURL;
|
||||
|
||||
if (inv_vid?.genre === "Music") {
|
||||
var vidurl = u.losslessurl;
|
||||
}
|
||||
|
||||
if (inv_vid.author.endsWith(" - Topic")) {
|
||||
var vidurl = u.losslessurl;
|
||||
var isvidious = true;
|
||||
}
|
||||
|
||||
if (req.useragent.source.includes("Pardus")) {
|
||||
var vidurl = "https://yt.sudovanilla.com";
|
||||
var isvidious = true;
|
||||
}
|
||||
|
||||
let badges = "";
|
||||
|
@ -259,8 +278,8 @@ module.exports = function (app, config, renderTemplate) {
|
|||
if (uaos === "Windows XP" || uaos === "Windows Vista")
|
||||
res.redirect("/lite?v=" + req.query.v);
|
||||
|
||||
if (req.query.from === "short") var shortsui = true
|
||||
|
||||
if (req.query.from === "short") var shortsui = true;
|
||||
|
||||
try {
|
||||
renderTemplate(res, req, "poketube.ejs", {
|
||||
color: data.color,
|
||||
|
@ -272,7 +291,7 @@ module.exports = function (app, config, renderTemplate) {
|
|||
support,
|
||||
shortsui,
|
||||
u: vidurl,
|
||||
isvidious: u.isInvidiousURL,
|
||||
isvidious: isvidious,
|
||||
video: json,
|
||||
date: k.Video.uploadDate,
|
||||
e,
|
||||
|
@ -280,7 +299,7 @@ module.exports = function (app, config, renderTemplate) {
|
|||
twitter,
|
||||
k,
|
||||
dm,
|
||||
media_proxy_url : config.media_proxy,
|
||||
media_proxy_url: config.media_proxy,
|
||||
instagram,
|
||||
useragent: req.useragent,
|
||||
verify,
|
||||
|
@ -314,7 +333,7 @@ module.exports = function (app, config, renderTemplate) {
|
|||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.redirect(`/watch?v=${req.query.v}&fx=1&err=${error}`);
|
||||
return res.redirect(`/watch?v=${req.query.v}&fx=1&err=${error}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -533,4 +552,4 @@ module.exports = function (app, config, renderTemplate) {
|
|||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue