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");
|
|
|
|
|
|
|
|
const sha384 = modules.hash;
|
|
|
|
|
|
|
|
module.exports = function (app, config, renderTemplate) {
|
2022-11-10 14:27:26 +01:00
|
|
|
app.get("/discover", async function (req, res) {
|
|
|
|
const trends = await modules.fetch(config.tubeApi + `trending`);
|
|
|
|
const h = await trends.text();
|
|
|
|
const k = JSON.parse(modules.toJson(h));
|
2022-11-09 17:48:29 +01:00
|
|
|
|
2022-11-10 14:27:26 +01:00
|
|
|
if (req.query.tab)
|
|
|
|
var tab = `/?type=${capitalizeFirstLetter(req.query.tab)}`;
|
2022-11-09 17:48:29 +01:00
|
|
|
|
2022-11-10 14:27:26 +01:00
|
|
|
if (!req.query.tab) var tab = "";
|
2022-11-09 17:48:29 +01:00
|
|
|
|
2022-11-10 14:27:26 +01:00
|
|
|
const invtrend = await modules
|
|
|
|
.fetch(`https://vid.puffyan.us/api/v1/trending${tab}`)
|
|
|
|
.then((res) => res.text());
|
2022-11-09 17:48:29 +01:00
|
|
|
|
2022-11-10 14:27:26 +01:00
|
|
|
const t = JSON.parse(invtrend);
|
2022-11-09 17:48:29 +01:00
|
|
|
|
2022-11-10 14:27:26 +01:00
|
|
|
if (req.query.mobilesearch) {
|
|
|
|
var query = req.query.mobilesearch;
|
|
|
|
tab = "search";
|
|
|
|
if (req.query.continuation) {
|
|
|
|
var continuation = req.query.continuation;
|
|
|
|
}
|
|
|
|
if (!req.query.continuation) {
|
|
|
|
var continuation = "";
|
|
|
|
}
|
2022-11-09 17:48:29 +01:00
|
|
|
|
2022-11-10 14:27:26 +01:00
|
|
|
const search = await modules.fetch(
|
2022-12-15 17:22:03 +01:00
|
|
|
`https://tube-srv.ashley143.gay/api/search?query=${query}&continuation=${continuation}`
|
2022-11-10 14:27:26 +01:00
|
|
|
);
|
2022-11-09 17:48:29 +01:00
|
|
|
|
2022-11-10 14:27:26 +01:00
|
|
|
const text = await search.text();
|
|
|
|
var j = JSON.parse(modules.toJson(text));
|
2022-11-09 17:48:29 +01:00
|
|
|
}
|
|
|
|
|
2022-11-10 14:27:26 +01:00
|
|
|
renderTemplate(res, req, "main.ejs", {
|
|
|
|
k: k,
|
|
|
|
tab: req.query.tab,
|
|
|
|
isMobile: req.useragent.isMobile,
|
|
|
|
mobilesearch: req.query.mobilesearch,
|
|
|
|
inv: t,
|
|
|
|
turntomins,
|
|
|
|
continuation,
|
|
|
|
j,
|
|
|
|
});
|
|
|
|
});
|
2022-11-09 17:48:29 +01:00
|
|
|
|
2022-11-10 14:27:26 +01:00
|
|
|
app.get("/:v*?", async function (req, res) {
|
|
|
|
let rendermainpage = () => {
|
|
|
|
if (req.useragent.isMobile) {
|
|
|
|
return res.redirect(`/discover`);
|
|
|
|
} else {
|
|
|
|
return renderTemplate(res, req, "landing.ejs");
|
|
|
|
}
|
|
|
|
};
|
2022-11-09 17:48:29 +01:00
|
|
|
|
2022-11-10 14:27:26 +01:00
|
|
|
if (req.params.v) {
|
2022-12-18 12:56:33 +01:00
|
|
|
if (/[a-zA-Z0-9]+/.test(req.param.v)) {
|
|
|
|
const isvld = await core.isvalidvideo(req.params.v);
|
2022-11-09 17:48:29 +01:00
|
|
|
|
2022-12-18 12:56:33 +01:00
|
|
|
if (isvld) {
|
|
|
|
return res.redirect(`/watch?v=${req.params.v}`);
|
|
|
|
} else {
|
|
|
|
return rendermainpage();
|
|
|
|
}
|
2022-11-10 14:27:26 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return rendermainpage();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|