mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 16:37:52 +01:00
fix my skill issue
This commit is contained in:
parent
c2a8fffddd
commit
a6116e6f9d
1 changed files with 107 additions and 481 deletions
|
@ -8,6 +8,7 @@ const {
|
|||
initlog,
|
||||
init,
|
||||
} = require("../libpoketube-initsys.js");
|
||||
|
||||
const {
|
||||
IsJsonString,
|
||||
convert,
|
||||
|
@ -17,500 +18,125 @@ const {
|
|||
getRandomInt,
|
||||
getRandomArbitrary,
|
||||
} = require("../ptutils/libpt-coreutils.js");
|
||||
const media_proxy = require("../libpoketube-video.js");
|
||||
const atmos = require("../../../pokeatmosurls.json");
|
||||
|
||||
function linkify(text) {
|
||||
// regular expression to match URLs
|
||||
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
||||
|
||||
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
|
||||
.replace(/twitter\.com/g, "nitter.net")
|
||||
.replace(/reddit\.com/g, "teddit.net")
|
||||
.replace("https://youtube.com", "")
|
||||
.replace("https://youtu.be", "")
|
||||
)}" target="_blank">${url}</a>`;
|
||||
});
|
||||
}
|
||||
const path = require("path");
|
||||
const fs = require("node:fs");
|
||||
const CleanCSS = require("clean-css");
|
||||
|
||||
const sha384 = modules.hash;
|
||||
const fetch = modules.fetch;
|
||||
const htmlToText = require("html-to-text");
|
||||
const encoding = require("encoding");
|
||||
const delim1 =
|
||||
'</div></div></div></div><div class="hwc"><div class="BNeawe tAd8D AP7Wnd"><div><div class="BNeawe tAd8D AP7Wnd">';
|
||||
const delim2 =
|
||||
'</div></div></div></div></div><div><span class="hwc"><div class="BNeawe uEec3 AP7Wnd">';
|
||||
const url = "https://www.google.com/search?q=";
|
||||
|
||||
async function lyricsFinder(e = "", d = "") {
|
||||
let i;
|
||||
try {
|
||||
i = await fetch(`${url}${encodeURIComponent(d + " " + e)}+lyrics`);
|
||||
i = await i.textConverted();
|
||||
[, i] = i.split(delim1);
|
||||
[i] = i.split(delim2);
|
||||
} catch (m) {
|
||||
try {
|
||||
i = await fetch(`${url}${encodeURIComponent(d + " " + e)}+song+lyrics`);
|
||||
i = await i.textConverted();
|
||||
[, i] = i.split(delim1);
|
||||
[i] = i.split(delim2);
|
||||
} catch (n) {
|
||||
try {
|
||||
i = await fetch(`${url}${encodeURIComponent(d + " " + e)}+song`);
|
||||
i = await i.textConverted();
|
||||
[, i] = i.split(delim1);
|
||||
[i] = i.split(delim2);
|
||||
} catch (o) {
|
||||
try {
|
||||
i = await fetch(`${url}${encodeURIComponent(d + " " + e)}`);
|
||||
i = await i.textConverted();
|
||||
[, i] = i.split(delim1);
|
||||
[i] = i.split(delim2);
|
||||
} catch (p) {
|
||||
i = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const ret = i.split("\n");
|
||||
let final = "";
|
||||
for (let j = 0; j < ret.length; j += 1) {
|
||||
final = `${final}${htmlToText.fromString(ret[j])}\n`;
|
||||
}
|
||||
return String(encoding.convert(final)).trim();
|
||||
}
|
||||
|
||||
function toObject(arr) {
|
||||
var rv = {};
|
||||
for (var i = 0; i < arr.length; ++i) if (arr[i] !== undefined) rv[i] = arr[i];
|
||||
return rv;
|
||||
}
|
||||
|
||||
function lightOrDark(color) {
|
||||
// Variables for red, green, blue values
|
||||
var r, g, b, hsp;
|
||||
|
||||
// Check the format of the color, HEX or RGB?
|
||||
if (color.match(/^rgb/)) {
|
||||
// If RGB --> store the red, green, blue values in separate variables
|
||||
color = color.match(
|
||||
/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/
|
||||
);
|
||||
|
||||
r = color[1];
|
||||
g = color[2];
|
||||
b = color[3];
|
||||
} else {
|
||||
// If hex --> Convert it to RGB: http://gist.github.com/983661
|
||||
color = +("0x" + color.slice(1).replace(color.length < 5 && /./g, "$&$&"));
|
||||
|
||||
r = color >> 16;
|
||||
g = (color >> 8) & 255;
|
||||
b = color & 255;
|
||||
}
|
||||
|
||||
// HSP (Highly Sensitive Poo) equation from http://alienryderflex.com/hsp.html
|
||||
hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b));
|
||||
|
||||
// Using the HSP value, determine whether the color is light or dark
|
||||
if (hsp > 127.5) {
|
||||
return "light";
|
||||
} else {
|
||||
return "dark";
|
||||
}
|
||||
}
|
||||
|
||||
function IsInArray(array, id) {
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
if (array[i].id === id) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getJson(str) {
|
||||
try {
|
||||
return JSON.parse(str);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* support button */
|
||||
const PATREON_REGEX = /https:\/\/www.patreon.com\/(?<name>[\w\d_-]+)/;
|
||||
|
||||
/* connections */
|
||||
const X_REGEX = /https:\/\/twitter.com\/(?<name>[\w\d_-]+)/;
|
||||
const CORD_REGEX = /https:\/\/discord.gg\/(?<name>[\w\d_-]+)/;
|
||||
const TWITCH_REGEX = /https:\/\/twitch.tv\/(?<name>[\w\d_-]+)/;
|
||||
const REDDIT_REGEX = /https:\/\/reddit\.com\/r\/(?<name>[\w\d_-]+)/;
|
||||
const INSTAGRAM_REGEX = /https:\/\/www.instagram.com\/(?<name>[\w\d_-]+)/;
|
||||
const notice =
|
||||
"/* the code is Licensed in gpl-3.0-or-later. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public License for more detailsYou should have received a copy of the GNU General Public Licensealong with this program. If not, see <https://www.gnu.org/licenses/>. - add the param nomin to view source code. (eg poketube.fun/css/poketube.css?nomin=true) */";
|
||||
|
||||
module.exports = function (app, config, renderTemplate) {
|
||||
app.get("/encryption", async function (req, res) {
|
||||
res.json("error in parsing");
|
||||
});
|
||||
var html_location = "./css/";
|
||||
|
||||
app.get("/old", function (req, res) {
|
||||
const v = req.query.v;
|
||||
|
||||
renderTemplate(res, req, "poketube-old.ejs", {
|
||||
v,
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/watch", async (req, res) => {
|
||||
const { dm, v, e, r, f, m, quality: q, a, universe } = req.query;
|
||||
|
||||
if (!v) {
|
||||
return res.redirect("/");
|
||||
}
|
||||
|
||||
const isVideoValid = await core.isvalidvideo(v);
|
||||
if (!isVideoValid) {
|
||||
return res.redirect("/?fromerror=21_video_not_valid");
|
||||
}
|
||||
|
||||
const u = await media_proxy(v);
|
||||
|
||||
const secure = ["poketube.fun"].includes(req.hostname);
|
||||
const verify = req.hostname === "pt.zzls.xyz";
|
||||
|
||||
core.video(v).then((data) => {
|
||||
try {
|
||||
const k = data?.video;
|
||||
const json = data?.json;
|
||||
const engagement = data?.engagement;
|
||||
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);
|
||||
|
||||
const support =
|
||||
descriptionString !== "[object Object]"
|
||||
? (PATREON_REGEX.exec(descriptionString) ?? {}).groups
|
||||
: undefined;
|
||||
const twitter =
|
||||
descriptionString !== "[object Object]"
|
||||
? (X_REGEX.exec(descriptionString) ?? {}).groups
|
||||
: undefined;
|
||||
const discord =
|
||||
descriptionString !== "[object Object]"
|
||||
? (CORD_REGEX.exec(descriptionString) ?? {}).groups
|
||||
: undefined;
|
||||
const twitch =
|
||||
descriptionString !== "[object Object]"
|
||||
? (TWITCH_REGEX.exec(descriptionString) ?? {}).groups
|
||||
: undefined;
|
||||
const reddit =
|
||||
descriptionString !== "[object Object]"
|
||||
? (REDDIT_REGEX.exec(descriptionString) ?? {}).groups
|
||||
: undefined;
|
||||
const instagram =
|
||||
descriptionString !== "[object Object]"
|
||||
? (INSTAGRAM_REGEX.exec(descriptionString) ?? {}).groups
|
||||
: undefined;
|
||||
|
||||
let badges = "";
|
||||
let comments = "";
|
||||
let nnn = "";
|
||||
|
||||
if (
|
||||
inv_vid?.error ===
|
||||
"The uploader has not made this video available in your country" ||
|
||||
inv_vid?.error === "This video is not available"
|
||||
) {
|
||||
res.send(
|
||||
"error: " + inv_vid.error + " please refresh the page please qt"
|
||||
);
|
||||
}
|
||||
|
||||
var uaos = req.useragent.os;
|
||||
const browser = req.useragent.browser;
|
||||
const IsOldWindows =
|
||||
(uaos === "Windows 7" || uaos === "Windows 8") &&
|
||||
browser === "Firefox";
|
||||
|
||||
if (uaos === "Windows XP" || uaos === "Windows Vista")
|
||||
res.redirect("/lite?v=" + req.query.v);
|
||||
|
||||
try {
|
||||
renderTemplate(res, req, "poketube.ejs", {
|
||||
color: data.color,
|
||||
color2: data.color2,
|
||||
linkify,
|
||||
engagement,
|
||||
IsOldWindows,
|
||||
support,
|
||||
u: u.url,
|
||||
isvidious: u.isInvidiousURL,
|
||||
video: json,
|
||||
date: k.Video.uploadDate,
|
||||
e,
|
||||
a,
|
||||
twitter,
|
||||
k,
|
||||
dm,
|
||||
instagram,
|
||||
useragent: req.useragent,
|
||||
verify,
|
||||
discord,
|
||||
twitch,
|
||||
reddit,
|
||||
secure,
|
||||
process,
|
||||
sha384,
|
||||
lightOrDark,
|
||||
isMobile: req.useragent.isMobile,
|
||||
tj: data.channel,
|
||||
r,
|
||||
qua: q,
|
||||
inv: inv_comments,
|
||||
convert,
|
||||
universe,
|
||||
wiki: data.wiki,
|
||||
f,
|
||||
t: config.t_url,
|
||||
optout: m,
|
||||
badges,
|
||||
desc,
|
||||
comments,
|
||||
n: nnn,
|
||||
inv_vid,
|
||||
lyrics: "",
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.redirect("/?fromerror=41_generic_error");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/lite", async function (req, res) {
|
||||
const { v, e, r, f, t, quality: q } = req.query;
|
||||
|
||||
try {
|
||||
const info = await modules.fetch("http://ip-api.com/json/");
|
||||
const ip = await info.json();
|
||||
|
||||
const {
|
||||
video: k,
|
||||
json,
|
||||
engagement,
|
||||
comments: inv_comments,
|
||||
vid: inv_vid,
|
||||
} = await core.video(v);
|
||||
|
||||
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;
|
||||
const u = await media_proxy(v);
|
||||
const d = desc.toString().replace(/\n/g, " <br> ");
|
||||
const comments = inv_comments || "Disabled";
|
||||
|
||||
const templateData = {
|
||||
color,
|
||||
color2,
|
||||
engagement,
|
||||
u: u.url,
|
||||
video: json,
|
||||
date: k.Video.uploadDate,
|
||||
e,
|
||||
k,
|
||||
process,
|
||||
sha384,
|
||||
lightOrDark,
|
||||
isMobile,
|
||||
tj,
|
||||
r,
|
||||
qua: q,
|
||||
isvidious: u.isInvidiousURL,
|
||||
inv: comments,
|
||||
ip,
|
||||
convert,
|
||||
linkify,
|
||||
wiki,
|
||||
f,
|
||||
t: config.t_url,
|
||||
optout: t,
|
||||
badges: "",
|
||||
desc,
|
||||
comments,
|
||||
n: "",
|
||||
inv_vid,
|
||||
lyrics: "",
|
||||
};
|
||||
|
||||
renderTemplate(res, req, "lite.ejs", templateData);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.redirect("/?err=" + error);
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/music", async function (req, res) {
|
||||
/*
|
||||
* 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;
|
||||
|
||||
const info = await modules.fetch("http://ip-api.com/json/");
|
||||
const n = await info.text();
|
||||
const ip = JSON.parse(n);
|
||||
|
||||
if (!v) {
|
||||
res.redirect("/discover?tab=music");
|
||||
app.get("/privacy", function (req, res) {
|
||||
if (req.hostname == "poketube.fun") {
|
||||
renderTemplate(res, req, "priv.ejs", {
|
||||
isMobile: req.useragent.isMobile,
|
||||
});
|
||||
} else {
|
||||
var fetching = await fetcher(v);
|
||||
renderTemplate(res, req, "priv-custom.ejs");
|
||||
}
|
||||
});
|
||||
|
||||
const json = fetching.video.Player;
|
||||
app.get("/143", function (req, res) {
|
||||
var number_easteregg = getRandomArbitrary(0, 143);
|
||||
|
||||
const video = await modules.fetch(config.tubeApi + `video?v=${v}`);
|
||||
if (number_easteregg == "143") {
|
||||
renderTemplate(res, req, "143.ejs", {
|
||||
something: req.query.something,
|
||||
});
|
||||
}
|
||||
|
||||
const h = await video.text();
|
||||
const k = JSON.parse(modules.toJson(h));
|
||||
if (req.query.number == "143") {
|
||||
renderTemplate(res, req, "143.ejs", {
|
||||
something: req.query.something,
|
||||
});
|
||||
}
|
||||
|
||||
if (!json.Channel.Name.endsWith(" - Topic")) {
|
||||
res.redirect(`/watch?v=${v}`);
|
||||
if (req.query.something == "143") {
|
||||
renderTemplate(res, req, "143.ejs", {
|
||||
something: req.query.something,
|
||||
});
|
||||
}
|
||||
|
||||
if (number_easteregg != "143") {
|
||||
return res.redirect("/" + "?number=" + number_easteregg);
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/domains", function (req, res) {
|
||||
renderTemplate(res, req, "domains.ejs");
|
||||
});
|
||||
|
||||
app.get("/license", function (req, res) {
|
||||
renderTemplate(res, req, "license.ejs");
|
||||
});
|
||||
|
||||
app.get("/credits", function (req, res) {
|
||||
renderTemplate(res, req, "want-you-gone.ejs");
|
||||
});
|
||||
|
||||
app.get("/customize", function (req, res) {
|
||||
const tab = req.query.tab;
|
||||
|
||||
renderTemplate(res, req, "custom-css.ejs", {
|
||||
tab,
|
||||
});
|
||||
});
|
||||
|
||||
const cssDir = "./css/";
|
||||
|
||||
app.get("/css/:id", (req, res) => {
|
||||
const filePath = path.join(cssDir, req.params.id);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
res.status(404).send("File not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.params.id.endsWith(".css") && !req.query.nomin) {
|
||||
// Minimize the CSS file
|
||||
const css = fs.readFileSync(filePath, "utf8");
|
||||
const minimizedCss = new CleanCSS().minify(css).styles;
|
||||
// Serve the minimized CSS file
|
||||
res.header("Content-Type", "text/css");
|
||||
res.send(notice + " " + minimizedCss);
|
||||
} else {
|
||||
// Serve the original file
|
||||
res.sendFile(req.params.id, { root: html_location });
|
||||
}
|
||||
|
||||
if (req.params.id.endsWith(".js")) {
|
||||
res.redirect("/static/" + req.params.id);
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/static/:id", (req, res) => {
|
||||
if (req.params.id.endsWith(".css")) {
|
||||
res.redirect("/css/" + req.params.id);
|
||||
} else if (req.params.id.endsWith(".js")) {
|
||||
const filePath = path.join(html_location, req.params.id);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
res.status(404).send("File not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.useragent.isMobile) {
|
||||
res.redirect(`/watch?v=${v}`);
|
||||
}
|
||||
|
||||
//video
|
||||
var url = `https://tube.kuylar.dev/proxy/media/${v}/22`;
|
||||
|
||||
// encryption
|
||||
var url_e =
|
||||
url +
|
||||
"?e=" +
|
||||
sha384(k.Video.Channel.id) +
|
||||
sha384(k.Video.Channel.id) +
|
||||
"Piwik" +
|
||||
sha384(config.t_url);
|
||||
|
||||
const stringed = toObject(atmos);
|
||||
|
||||
const search = (what) => atmos.find((element) => element.id === what);
|
||||
const mos = search(v);
|
||||
|
||||
/*
|
||||
this is only for the alac codec being used
|
||||
|
||||
* Copyright (c) 2023 Apple Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_APACHE_LICENSE_HEADER_START@
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_APACHE_LICENSE_HEADER_END@
|
||||
*/
|
||||
|
||||
if (mos) {
|
||||
var url_e =
|
||||
mos.url +
|
||||
"?e=" +
|
||||
sha384(k.Video.Channel.id) +
|
||||
sha384(k.Video.Channel.id) +
|
||||
"Piwik" +
|
||||
sha384(config.t_url);
|
||||
} else {
|
||||
}
|
||||
|
||||
// channel info
|
||||
const engagement = fetching.engagement;
|
||||
const channel = await modules.fetch(
|
||||
config.tubeApi + `channel?id=${k.Video.Channel.id}&tab=videos`
|
||||
// Minimize the JavaScript file
|
||||
const js = fs.readFileSync(filePath, "utf8");
|
||||
const minimizedJs = require("uglify-js").minify(js).code;
|
||||
// Serve the minimized JavaScript file
|
||||
res.header("Content-Type", "text/javascript");
|
||||
res.send(
|
||||
"// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later" +
|
||||
`\n` +
|
||||
`// Source code can be found in: https://codeberg.org/Ashley/poketube/src/branch/main/css/${req.params.id}` +
|
||||
`\n` +
|
||||
minimizedJs +
|
||||
`\n` +
|
||||
"// @license-end"
|
||||
);
|
||||
const c = await channel.text();
|
||||
const tj = JSON.parse(modules.toJson(c));
|
||||
|
||||
try {
|
||||
// info
|
||||
const song = await musicInfo.searchSong(
|
||||
{
|
||||
title: k.Video.Title,
|
||||
artist: json.Channel.Name.replace("- Topic", ""),
|
||||
},
|
||||
1000
|
||||
);
|
||||
|
||||
if (!song) {
|
||||
res.redirect(`/watch?v=${v}`);
|
||||
}
|
||||
|
||||
const lyrics = await lyricsFinder(song.artist + song.title);
|
||||
if (lyrics == undefined)
|
||||
ly = "This Is Where I'd Put The songs lyrics. IF IT HAD ONE ";
|
||||
|
||||
var ly = "";
|
||||
if (lyrics) {
|
||||
ly = lyrics.replace(/\n/g, " <br> ");
|
||||
}
|
||||
|
||||
renderTemplate(res, req, "poketube-music.ejs", {
|
||||
url: url_e,
|
||||
info: song,
|
||||
color: await modules
|
||||
.getColors(song.artwork)
|
||||
.then((colors) => colors[0].hex()),
|
||||
engagement: engagement,
|
||||
process: process,
|
||||
ip: ip,
|
||||
video: json,
|
||||
date: modules.moment(k.Video.uploadDate).format("LL"),
|
||||
e: e,
|
||||
k: k,
|
||||
sha384: sha384,
|
||||
isMobile: req.useragent.isMobile,
|
||||
tj: tj,
|
||||
r: r,
|
||||
f: f,
|
||||
t: config.t_url,
|
||||
optout: t,
|
||||
lyrics: ly,
|
||||
});
|
||||
} catch {
|
||||
return res.redirect("/?fromerror=43");
|
||||
}
|
||||
} else {
|
||||
res.sendFile(req.params.id, { root: html_location });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue