2022-11-18 10:42:25 +01:00
|
|
|
const {
|
|
|
|
fetcher,
|
|
|
|
core,
|
|
|
|
wiki,
|
|
|
|
musicInfo,
|
|
|
|
modules,
|
|
|
|
version,
|
|
|
|
initlog,
|
|
|
|
init,
|
|
|
|
} = require("../libpoketube-initsys.js");
|
2022-11-09 17:52:57 +01:00
|
|
|
const {
|
|
|
|
IsJsonString,
|
|
|
|
convert,
|
|
|
|
getFirstLine,
|
|
|
|
capitalizeFirstLetter,
|
|
|
|
turntomins,
|
|
|
|
getRandomInt,
|
|
|
|
getRandomArbitrary,
|
|
|
|
} = require("../ptutils/libpt-coreutils.js");
|
|
|
|
|
2022-12-18 16:30:24 +01:00
|
|
|
const sha384 = modules.hash;
|
2022-12-09 18:13:14 +01:00
|
|
|
|
|
|
|
function getJson(str) {
|
|
|
|
try {
|
|
|
|
return JSON.parse(str);
|
|
|
|
} catch {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 17:52:57 +01:00
|
|
|
module.exports = function (app, config, renderTemplate) {
|
2022-11-18 10:42:25 +01:00
|
|
|
app.get("/download", async function (req, res) {
|
|
|
|
var v = req.query.v;
|
|
|
|
|
|
|
|
// video
|
|
|
|
const video = await modules.fetch(config.tubeApi + `video?v=${v}`);
|
|
|
|
const h = await video.text();
|
|
|
|
const k = JSON.parse(modules.toJson(h));
|
|
|
|
|
|
|
|
if (!v) res.redirect("/");
|
|
|
|
|
|
|
|
var fetching = await fetcher(v);
|
|
|
|
|
|
|
|
const json = fetching.video.Player;
|
|
|
|
const engagement = fetching.engagement;
|
|
|
|
|
|
|
|
renderTemplate(res, req, "download.ejs", {
|
|
|
|
engagement: engagement,
|
|
|
|
k: k,
|
|
|
|
video: json,
|
|
|
|
date: k.Video.uploadDate,
|
|
|
|
color: await modules
|
|
|
|
.getColors(`https://i.ytimg.com/vi/${v}/maxresdefault.jpg`)
|
|
|
|
.then((colors) => colors[0].hex()),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get("/old/watch", async function (req, res) {
|
|
|
|
var v = req.query.v;
|
|
|
|
var e = req.query.e;
|
|
|
|
if (!v) res.redirect("/");
|
|
|
|
|
|
|
|
res.redirect(`/watch?v=${v}`);
|
2022-11-09 17:52:57 +01:00
|
|
|
});
|
2022-11-18 10:42:25 +01:00
|
|
|
|
|
|
|
app.get("/search", async (req, res) => {
|
|
|
|
const query = req.query.query;
|
|
|
|
|
|
|
|
if (req.query.continuation) {
|
|
|
|
var continuation = req.query.continuation;
|
|
|
|
}
|
2022-12-24 11:51:44 +01:00
|
|
|
|
2022-11-18 10:42:25 +01:00
|
|
|
if (!req.query.continuation) {
|
|
|
|
var continuation = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!query) {
|
|
|
|
return res.redirect("/");
|
|
|
|
}
|
|
|
|
|
2022-12-30 17:22:29 +01:00
|
|
|
if (query) {
|
2022-12-31 13:39:51 +01:00
|
|
|
try {
|
|
|
|
const search = await modules.fetch(
|
|
|
|
`https://tube-srv.ashley143.gay/api/search?query=${query.replace(
|
|
|
|
"&",
|
|
|
|
"and"
|
|
|
|
)}&continuation=${continuation}`
|
|
|
|
);
|
|
|
|
|
|
|
|
const text = await search.text();
|
|
|
|
const j = JSON.parse(modules.toJson(text));
|
|
|
|
|
|
|
|
h = " ";
|
2023-02-17 22:17:56 +01:00
|
|
|
|
|
|
|
// YOUTUBE WHY do you WANT me to do this oh ma gosh
|
2022-12-31 13:39:51 +01:00
|
|
|
if (j.Search) {
|
|
|
|
if ("Results.DynamicItem" in j.Search) {
|
|
|
|
if (j.Search.Results.DynamicItem.id == "didYouMeanRenderer") {
|
|
|
|
var h = JSON.parse(j.Search.Results.DynamicItem.Title);
|
|
|
|
}
|
2022-12-31 12:05:26 +01:00
|
|
|
}
|
2022-12-30 17:22:29 +01:00
|
|
|
}
|
|
|
|
|
2022-12-31 13:39:51 +01:00
|
|
|
const summary = await wiki
|
|
|
|
.summary(query + " ")
|
|
|
|
.then((summary_) =>
|
|
|
|
summary_.title !== "Not found." ? summary_ : "none"
|
|
|
|
);
|
|
|
|
|
|
|
|
renderTemplate(res, req, "search.ejs", {
|
|
|
|
j,
|
|
|
|
h,
|
|
|
|
continuation,
|
|
|
|
q: query,
|
|
|
|
summary,
|
|
|
|
});
|
|
|
|
} catch {
|
|
|
|
res.redirect("/");
|
|
|
|
}
|
2022-12-30 17:22:29 +01:00
|
|
|
}
|
2022-11-09 17:52:57 +01:00
|
|
|
});
|
2022-11-18 10:42:25 +01:00
|
|
|
|
|
|
|
app.get("/channel/", async (req, res) => {
|
|
|
|
const ID = req.query.id;
|
|
|
|
const tab = req.query.tab;
|
|
|
|
|
2022-12-21 09:25:16 +01:00
|
|
|
try {
|
|
|
|
// about
|
|
|
|
const bout = await modules.fetch(
|
|
|
|
config.tubeApi + `channel?id=${ID}&tab=about`
|
|
|
|
);
|
|
|
|
const h = await bout.text();
|
|
|
|
var k = JSON.parse(modules.toJson(h));
|
|
|
|
} catch {
|
|
|
|
k = " ";
|
|
|
|
}
|
2023-02-17 22:17:56 +01:00
|
|
|
|
2023-02-22 17:10:47 +01:00
|
|
|
try {
|
|
|
|
|
2023-02-17 22:17:56 +01:00
|
|
|
// continuation stuff - whoa cool
|
|
|
|
let continuation = req.query.continuation ? `&continuation=${req.query.continuation}` : "";
|
|
|
|
let continuationl = req.query.continuationl ? `&continuation=${req.query.continuationl}` : "";
|
|
|
|
let continuations = req.query.continuations ? `&continuation=${req.query.continuations}` : "";
|
2023-02-04 22:59:45 +01:00
|
|
|
|
2023-02-17 22:17:56 +01:00
|
|
|
// videos - i dont think this is readable at all but o welp if it works it works:tm:
|
|
|
|
// https://github.com/iv-org/invidious/blob/05258d56bdc3f4de1f0da0c0dbd2d540f68cbdd5/src/invidious/channels/videos.cr
|
|
|
|
|
|
|
|
const tj = await modules.fetch(`https://inv.zzls.xyz/api/v1/channels/videos/${ID}/?sort_by=${req.query.sort_by || "newest"}` + continuation).then((res) => res.text()).then((txt) => getJson(txt)).catch(" ")
|
|
|
|
const shorts = await modules.fetch(`https://inv.zzls.xyz/api/v1/channels/${ID}/shorts?sort_by=${req.query.sort_by || "newest"}` + continuations).then((res) => res.text()).then((txt) => getJson(txt)).catch(" ")
|
|
|
|
const stream = await modules.fetch(`https://inv.zzls.xyz/api/v1/channels/${ID}/streams?sort_by=${req.query.sort_by || "newest"}` + continuationl).then((res) => res.text()).then((txt) => getJson(txt)).catch(" ")
|
|
|
|
|
|
|
|
// community tab - protobuf Egljb21tdW5pdHk%3D
|
|
|
|
const c = await modules.fetch(`https://inv.zzls.xyz/api/v1/channels/community/${ID}/`).then((res) => res.text()) .then((txt) => getJson(txt));
|
|
|
|
|
2022-12-18 16:30:24 +01:00
|
|
|
const summary = await wiki.summary(k.Channel.Metadata.Name);
|
2022-12-10 08:46:23 +01:00
|
|
|
|
2022-12-18 16:30:24 +01:00
|
|
|
var w = "";
|
2023-02-17 22:17:56 +01:00
|
|
|
|
2022-12-18 16:30:24 +01:00
|
|
|
if (summary.title === "Not found.") {
|
|
|
|
w = "none";
|
|
|
|
}
|
|
|
|
if (summary.title !== "Not found.") {
|
|
|
|
w = summary;
|
|
|
|
}
|
2022-11-18 10:42:25 +01:00
|
|
|
|
2022-12-18 16:30:24 +01:00
|
|
|
const { Subscribers: subscribers } = k.Channel.Metadata;
|
|
|
|
const description = k.Channel.Contents.ItemSection.About.Description;
|
2022-11-18 10:42:25 +01:00
|
|
|
|
2022-12-18 16:30:24 +01:00
|
|
|
var d = description.toString().replace(/\n/g, " <br> ");
|
2022-12-24 11:51:44 +01:00
|
|
|
|
2022-12-18 16:30:24 +01:00
|
|
|
if (d === "[object Object]") {
|
|
|
|
var d = "";
|
|
|
|
}
|
2022-11-18 10:42:25 +01:00
|
|
|
|
2022-12-18 16:30:24 +01:00
|
|
|
var dnoreplace = description.toString();
|
2022-12-24 11:51:44 +01:00
|
|
|
|
2022-12-18 16:30:24 +01:00
|
|
|
if (dnoreplace === "[object Object]") {
|
|
|
|
var dnoreplace = "";
|
|
|
|
}
|
2022-11-18 10:42:25 +01:00
|
|
|
|
2022-12-18 16:30:24 +01:00
|
|
|
renderTemplate(res, req, "channel.ejs", {
|
|
|
|
ID,
|
|
|
|
tab,
|
2023-02-04 22:59:45 +01:00
|
|
|
shorts,
|
2022-12-18 16:30:24 +01:00
|
|
|
j: k,
|
2023-02-02 20:17:50 +01:00
|
|
|
sort:req.query.sort_by,
|
2023-02-04 22:59:45 +01:00
|
|
|
stream,
|
2022-12-18 16:30:24 +01:00
|
|
|
tj,
|
|
|
|
c,
|
|
|
|
convert,
|
|
|
|
turntomins,
|
|
|
|
dnoreplace: dnoreplace,
|
|
|
|
continuation: continuation,
|
|
|
|
wiki: w,
|
|
|
|
getFirstLine: getFirstLine,
|
|
|
|
isMobile: req.useragent.isMobile,
|
|
|
|
about: k.Channel.Contents.ItemSection.About,
|
|
|
|
subs:
|
|
|
|
typeof subscribers === "string"
|
|
|
|
? subscribers.replace("subscribers", "")
|
2023-02-17 22:17:56 +01:00
|
|
|
: "None",
|
2022-12-18 16:30:24 +01:00
|
|
|
desc: d,
|
|
|
|
});
|
|
|
|
} catch {
|
|
|
|
res.redirect("/");
|
2023-02-22 17:10:47 +01:00
|
|
|
}
|
2022-11-09 17:52:57 +01:00
|
|
|
});
|
2022-11-18 10:42:25 +01:00
|
|
|
};
|