2022-11-10 14:27:26 +01:00
|
|
|
const {
|
|
|
|
fetcher,
|
|
|
|
core,
|
|
|
|
wiki,
|
|
|
|
musicInfo,
|
|
|
|
modules,
|
|
|
|
version,
|
|
|
|
initlog,
|
|
|
|
init,
|
|
|
|
} = require("../libpoketube-initsys.js");
|
2022-11-09 17:48:29 +01:00
|
|
|
const {
|
|
|
|
IsJsonString,
|
|
|
|
convert,
|
|
|
|
getFirstLine,
|
|
|
|
capitalizeFirstLetter,
|
|
|
|
turntomins,
|
|
|
|
getRandomInt,
|
|
|
|
getRandomArbitrary,
|
|
|
|
} = require("../ptutils/libpt-coreutils.js");
|
|
|
|
|
2023-06-30 13:17:52 +02:00
|
|
|
var http = require("https");
|
|
|
|
var ping = require("ping");
|
|
|
|
|
2022-11-09 17:48:29 +01:00
|
|
|
const sha384 = modules.hash;
|
|
|
|
|
2023-11-23 07:24:55 +01:00
|
|
|
|
|
|
|
const splash = [
|
|
|
|
"Woke!",
|
|
|
|
"Gay gay homosexaul gay!",
|
2023-11-23 08:54:35 +01:00
|
|
|
"free Palestine!",
|
2023-11-23 07:24:55 +01:00
|
|
|
"free software!",
|
2023-11-23 08:58:11 +01:00
|
|
|
"im... stuff!",
|
2023-11-23 07:24:55 +01:00
|
|
|
"frick capitalism!",
|
|
|
|
"still calling it twitter btw!",
|
2023-11-23 08:39:51 +01:00
|
|
|
"boop!",
|
|
|
|
"no way!",
|
2023-11-23 08:54:35 +01:00
|
|
|
"traaaa rightssss!",
|
|
|
|
"XD!",
|
2023-11-23 08:39:51 +01:00
|
|
|
"nya!",
|
|
|
|
"say gex!",
|
2023-11-23 08:54:35 +01:00
|
|
|
"also try invidious!",
|
|
|
|
"rms <3!",
|
|
|
|
"du hast",
|
|
|
|
"can u belive no one bought this?",
|
|
|
|
"reee",
|
|
|
|
"1.000.000€!",
|
|
|
|
"pika!",
|
|
|
|
"fsf.org",
|
|
|
|
"ssfffssfssfffaassssfsdf!",
|
2024-05-01 11:32:28 +02:00
|
|
|
"can you save my hds?",
|
|
|
|
"sahlo folina!",
|
|
|
|
"we come for you!",
|
|
|
|
"no chances!",
|
|
|
|
"dema dont control us!",
|
|
|
|
"im fairly local!",
|
|
|
|
"i dont wanna go like this!",
|
2024-05-01 15:45:11 +02:00
|
|
|
"east is up!",
|
|
|
|
"not done, josh dun!",
|
|
|
|
"your the judge, oh no!",
|
|
|
|
"I dont wanna backslide",
|
2024-05-03 00:17:19 +02:00
|
|
|
"welcome back to trench!",
|
2024-05-01 15:45:11 +02:00
|
|
|
"sai is propaganda!",
|
|
|
|
" •|i|• Ø i+! ].[",
|
|
|
|
"stay alive! |-/",
|
|
|
|
"the few, the proud, the Emotional!",
|
|
|
|
"ill morph into someone else",
|
|
|
|
"still alive",
|
|
|
|
"follow the torches",
|
|
|
|
"i created this world!",
|
|
|
|
"to feel some control!",
|
2024-05-01 15:46:00 +02:00
|
|
|
"destory it if i want!",
|
2024-05-01 15:45:11 +02:00
|
|
|
"o7 keons",
|
2024-05-01 11:33:43 +02:00
|
|
|
"at least let me clean my room",
|
2023-11-23 08:54:35 +01:00
|
|
|
"100+ stars on gh!",
|
|
|
|
"now even gayer!",
|
|
|
|
"poketube!!!",
|
2023-11-23 11:15:05 +01:00
|
|
|
"rvlt.gg/poke!",
|
|
|
|
"women are pretty!",
|
|
|
|
"men are handsome!",
|
|
|
|
"enbys are cute!",
|
|
|
|
"you are cute :3",
|
|
|
|
"stallmansupport.org!!!"
|
2023-11-23 07:24:55 +01:00
|
|
|
]
|
|
|
|
|
2023-11-23 08:40:51 +01:00
|
|
|
|
2023-11-23 07:24:55 +01:00
|
|
|
|
|
|
|
|
2022-12-18 15:00:51 +01:00
|
|
|
function getJson(str) {
|
|
|
|
try {
|
2022-12-18 16:02:03 +01:00
|
|
|
return JSON.parse(str);
|
2022-12-18 15:00:51 +01:00
|
|
|
} catch {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 17:48:29 +01:00
|
|
|
module.exports = function (app, config, renderTemplate) {
|
2023-06-13 20:31:10 +02:00
|
|
|
app.get("/app", async function (req, res) {
|
2023-09-30 22:20:29 +02:00
|
|
|
const { fetch } = await import("undici");
|
|
|
|
|
2023-02-25 18:46:42 +01:00
|
|
|
let tab = "";
|
|
|
|
if (req.query.tab) {
|
|
|
|
tab = `/?type=${capitalizeFirstLetter(req.query.tab)}`;
|
|
|
|
}
|
2022-11-09 17:48:29 +01:00
|
|
|
|
2023-10-05 18:05:51 +02:00
|
|
|
const invtrend = await fetch(
|
2024-03-27 17:16:53 +01:00
|
|
|
`${config.invapi}/trending${tab}`
|
2023-05-16 20:07:17 +02:00
|
|
|
);
|
2023-02-25 18:46:42 +01:00
|
|
|
const t = getJson(await invtrend.text());
|
2022-11-09 17:48:29 +01:00
|
|
|
|
2023-10-23 16:49:24 +02:00
|
|
|
const invpopular = await fetch(
|
|
|
|
`https://invid-api.poketube.fun/api/v1/popular`
|
|
|
|
);
|
|
|
|
const p = getJson(await invpopular.text());
|
|
|
|
|
2023-02-25 18:46:42 +01:00
|
|
|
let j = null;
|
2022-11-10 14:27:26 +01:00
|
|
|
if (req.query.mobilesearch) {
|
2023-02-25 18:46:42 +01:00
|
|
|
const query = req.query.mobilesearch;
|
|
|
|
const continuation = req.query.continuation || "";
|
2023-09-30 22:20:29 +02:00
|
|
|
const search = await fetch(
|
2023-05-16 20:07:17 +02:00
|
|
|
`https://inner-api.poketube.fun/api/search?query=${query}&continuation=${continuation}`
|
|
|
|
);
|
2022-11-10 14:27:26 +01:00
|
|
|
const text = await search.text();
|
2023-02-25 18:46:42 +01:00
|
|
|
j = getJson(modules.toJson(text));
|
2022-11-09 17:48:29 +01:00
|
|
|
}
|
|
|
|
|
2023-10-06 16:54:03 +02:00
|
|
|
renderTemplate(res, req, "discover.ejs", {
|
2022-11-10 14:27:26 +01:00
|
|
|
tab: req.query.tab,
|
|
|
|
isMobile: req.useragent.isMobile,
|
2023-10-23 16:49:24 +02:00
|
|
|
p,
|
2022-11-10 14:27:26 +01:00
|
|
|
mobilesearch: req.query.mobilesearch,
|
|
|
|
inv: t,
|
|
|
|
turntomins,
|
2023-02-25 18:46:42 +01:00
|
|
|
continuation: req.query.continuation,
|
2022-11-10 14:27:26 +01:00
|
|
|
j,
|
|
|
|
});
|
|
|
|
});
|
2023-05-16 20:07:17 +02:00
|
|
|
|
2023-06-30 13:17:52 +02:00
|
|
|
app.get("/:v*?", async function (req, res) {
|
|
|
|
const uaos = req.useragent.os;
|
2023-11-23 08:40:51 +01:00
|
|
|
const random = splash[Math.floor(Math.random() * splash.length)];
|
2023-06-30 13:17:52 +02:00
|
|
|
const browser = req.useragent.browser;
|
2023-10-06 16:54:03 +02:00
|
|
|
const isOldWindows = (uaos === "Windows 7" || uaos === "Windows 8") && browser === "Firefox";
|
2024-05-01 08:41:06 +02:00
|
|
|
var proxyurl = config.p_url;
|
2023-06-30 13:17:52 +02:00
|
|
|
|
2024-05-01 05:04:20 +02:00
|
|
|
const secure = [
|
|
|
|
"poketube.fun",
|
|
|
|
"localhost" // Testing purposes
|
|
|
|
].includes(req.hostname);
|
|
|
|
const verify = [
|
|
|
|
"poketube.fun",
|
|
|
|
"poke.ashley0143.xyz",
|
|
|
|
"localhost"
|
|
|
|
].includes(req.hostname);
|
|
|
|
|
2023-06-30 13:17:52 +02:00
|
|
|
const rendermainpage = () => {
|
|
|
|
if (req.useragent.isMobile) {
|
2023-10-23 16:49:24 +02:00
|
|
|
return res.redirect("/app");
|
2023-06-30 13:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return renderTemplate(res, req, "landing.ejs", {
|
2024-05-01 05:04:20 +02:00
|
|
|
secure,
|
|
|
|
verify,
|
2023-06-30 13:17:52 +02:00
|
|
|
isOldWindows,
|
2024-05-01 08:41:06 +02:00
|
|
|
proxyurl,
|
2023-11-23 08:02:06 +01:00
|
|
|
random
|
2023-06-30 13:17:52 +02:00
|
|
|
});
|
|
|
|
};
|
2023-05-16 20:07:17 +02:00
|
|
|
|
2023-06-30 13:17:52 +02:00
|
|
|
if (req.params.v && /[a-zA-Z0-9]+/.test(req.params.v)) {
|
|
|
|
const isvld = await core.isvalidvideo(req.params.v);
|
2023-12-24 14:02:30 +01:00
|
|
|
if (isvld && req.params.v.length >= 10) {
|
2023-06-30 13:17:52 +02:00
|
|
|
return res.redirect(`/watch?v=${req.params.v}`);
|
2023-12-24 14:02:30 +01:00
|
|
|
} else {
|
2023-12-26 08:47:35 +01:00
|
|
|
return renderTemplate(res, req, "404.ejs", {
|
|
|
|
isOldWindows,
|
|
|
|
random
|
|
|
|
});
|
2023-06-30 13:17:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rendermainpage();
|
|
|
|
});
|
2023-11-23 08:40:51 +01:00
|
|
|
};
|