mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-10 13:48:24 +01:00
add did you mean? prompt
This commit is contained in:
parent
956df8e5cf
commit
e3cb7256ee
1 changed files with 142 additions and 121 deletions
|
@ -1,4 +1,13 @@
|
||||||
const { fetcher,core, wiki,musicInfo, modules, version, initlog, init,} = require("../libpoketube-initsys.js");
|
const {
|
||||||
|
fetcher,
|
||||||
|
core,
|
||||||
|
wiki,
|
||||||
|
musicInfo,
|
||||||
|
modules,
|
||||||
|
version,
|
||||||
|
initlog,
|
||||||
|
init,
|
||||||
|
} = require("../libpoketube-initsys.js");
|
||||||
const {
|
const {
|
||||||
IsJsonString,
|
IsJsonString,
|
||||||
convert,
|
convert,
|
||||||
|
@ -12,142 +21,154 @@ const {
|
||||||
const sha384 = modules.hash;
|
const sha384 = modules.hash;
|
||||||
|
|
||||||
module.exports = function (app, config, renderTemplate) {
|
module.exports = function (app, config, renderTemplate) {
|
||||||
app.get("/download", async function (req, res) {
|
app.get("/download", async function (req, res) {
|
||||||
var v = req.query.v;
|
var v = req.query.v;
|
||||||
|
|
||||||
// video
|
// video
|
||||||
const video = await modules.fetch(config.tubeApi + `video?v=${v}`);
|
const video = await modules.fetch(config.tubeApi + `video?v=${v}`);
|
||||||
const h = await video.text();
|
const h = await video.text();
|
||||||
const k = JSON.parse(modules.toJson(h));
|
const k = JSON.parse(modules.toJson(h));
|
||||||
|
|
||||||
if (!v) res.redirect("/");
|
if (!v) res.redirect("/");
|
||||||
|
|
||||||
var fetching = await fetcher(v);
|
var fetching = await fetcher(v);
|
||||||
const j = fetching.video.Player.Formats.Format,
|
const j = fetching.video.Player.Formats.Format,
|
||||||
j_ = Array.isArray(j) ? j[j.length - 1] : j;
|
j_ = Array.isArray(j) ? j[j.length - 1] : j;
|
||||||
let url;
|
let url;
|
||||||
if (j_.URL != undefined) url = j_.URL;
|
if (j_.URL != undefined) url = j_.URL;
|
||||||
|
|
||||||
const json = fetching.video.Player;
|
const json = fetching.video.Player;
|
||||||
const engagement = fetching.engagement;
|
const engagement = fetching.engagement;
|
||||||
|
|
||||||
renderTemplate(res, req, "download.ejs", {
|
renderTemplate(res, req, "download.ejs", {
|
||||||
url: url,
|
url: url,
|
||||||
engagement: engagement,
|
engagement: engagement,
|
||||||
k: k,
|
k: k,
|
||||||
video: json,
|
video: json,
|
||||||
date: k.Video.uploadDate,
|
date: k.Video.uploadDate,
|
||||||
color: await modules
|
color: await modules
|
||||||
.getColors(`https://i.ytimg.com/vi/${v}/maxresdefault.jpg`)
|
.getColors(`https://i.ytimg.com/vi/${v}/maxresdefault.jpg`)
|
||||||
.then((colors) => colors[0].hex()),
|
.then((colors) => colors[0].hex()),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
app.get("/old/watch", async function (req, res) {
|
app.get("/old/watch", async function (req, res) {
|
||||||
var v = req.query.v;
|
var v = req.query.v;
|
||||||
var e = req.query.e;
|
var e = req.query.e;
|
||||||
if (!v) res.redirect("/");
|
if (!v) res.redirect("/");
|
||||||
|
|
||||||
res.redirect(`/watch?v=${v}`);
|
res.redirect(`/watch?v=${v}`);
|
||||||
});
|
|
||||||
|
|
||||||
app.get("/search", async (req, res) => {
|
|
||||||
const query = req.query.query;
|
|
||||||
|
|
||||||
if (req.query.continuation) {
|
|
||||||
var continuation = req.query.continuation;
|
|
||||||
}
|
|
||||||
if (!req.query.continuation) {
|
|
||||||
var continuation = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
const search = await modules.fetch(
|
|
||||||
`https://tube.kuylar.dev/api/search?query=${query}&continuation=${continuation}`
|
|
||||||
);
|
|
||||||
|
|
||||||
const text = await search.text();
|
|
||||||
const j = JSON.parse(modules.toJson(text));
|
|
||||||
|
|
||||||
if (!query) {
|
|
||||||
return res.redirect("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
const summary = await wiki
|
|
||||||
.summary(query + " ")
|
|
||||||
.then((summary_) => (summary_.title !== "Not found." ? summary_ : "none"));
|
|
||||||
|
|
||||||
renderTemplate(res, req, "search.ejs", {
|
|
||||||
j,
|
|
||||||
continuation,
|
|
||||||
q: query,
|
|
||||||
summary,
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
app.get("/channel/", async (req, res) => {
|
app.get("/search", async (req, res) => {
|
||||||
const ID = req.query.id;
|
const query = req.query.query;
|
||||||
const tab = req.query.tab;
|
|
||||||
|
|
||||||
// about
|
if (req.query.continuation) {
|
||||||
const bout = await modules.fetch(
|
var continuation = req.query.continuation;
|
||||||
config.tubeApi + `channel?id=${ID}&tab=about`
|
}
|
||||||
);
|
if (!req.query.continuation) {
|
||||||
const h = await bout.text();
|
var continuation = "";
|
||||||
const k = JSON.parse(modules.toJson(h));
|
}
|
||||||
|
|
||||||
if (req.query.continuation) {
|
const search = await modules.fetch(
|
||||||
var continuation = req.query.continuation;
|
`https://tube.kuylar.dev/api/search?query=${query}&continuation=${continuation}`
|
||||||
}
|
);
|
||||||
if (!req.query.continuation) {
|
|
||||||
var continuation = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
//videos
|
const text = await search.text();
|
||||||
const channel = await modules.fetch(
|
const j = JSON.parse(modules.toJson(text));
|
||||||
config.tubeApi + `channel?id=${ID}&tab=shorts&Continuation=${continuation}`
|
|
||||||
);
|
|
||||||
const c = await channel.text();
|
|
||||||
const tj = JSON.parse(modules.toJson(c));
|
|
||||||
|
|
||||||
const summary = await wiki.summary(k.Channel.Metadata.Name);
|
if (!query) {
|
||||||
|
return res.redirect("/");
|
||||||
|
}
|
||||||
|
|
||||||
var w = "";
|
h = " ";
|
||||||
if (summary.title === "Not found.") {
|
|
||||||
w = "none";
|
|
||||||
}
|
|
||||||
if (summary.title !== "Not found.") {
|
|
||||||
w = summary;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { Subscribers: subscribers } = k.Channel.Metadata;
|
if (j.Search.Results.DynamicItem) {
|
||||||
const description = k.Channel.Contents.ItemSection.About.Description;
|
if (j.Search.Results.DynamicItem.id == "didYouMeanRenderer") {
|
||||||
|
var h = JSON.parse(j.Search.Results.DynamicItem.Title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var d = description.toString().replace(/\n/g, " <br> ");
|
const summary = await wiki
|
||||||
if (d === "[object Object]") {
|
.summary(query + " ")
|
||||||
var d = "";
|
.then((summary_) =>
|
||||||
}
|
summary_.title !== "Not found." ? summary_ : "none"
|
||||||
|
);
|
||||||
|
|
||||||
var dnoreplace = description.toString();
|
renderTemplate(res, req, "search.ejs", {
|
||||||
if (dnoreplace === "[object Object]") {
|
j,
|
||||||
var dnoreplace = "";
|
h,
|
||||||
}
|
continuation,
|
||||||
|
q: query,
|
||||||
renderTemplate(res, req, "channel.ejs", {
|
summary,
|
||||||
ID: ID,
|
});
|
||||||
tab: tab,
|
|
||||||
j: k,
|
|
||||||
tj: tj,
|
|
||||||
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", "")
|
|
||||||
: "Private",
|
|
||||||
desc: d,
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
app.get("/channel/", async (req, res) => {
|
||||||
|
const ID = req.query.id;
|
||||||
|
const tab = req.query.tab;
|
||||||
|
|
||||||
|
// about
|
||||||
|
const bout = await modules.fetch(
|
||||||
|
config.tubeApi + `channel?id=${ID}&tab=about`
|
||||||
|
);
|
||||||
|
const h = await bout.text();
|
||||||
|
const k = JSON.parse(modules.toJson(h));
|
||||||
|
|
||||||
|
if (req.query.continuation) {
|
||||||
|
var continuation = req.query.continuation;
|
||||||
|
}
|
||||||
|
if (!req.query.continuation) {
|
||||||
|
var continuation = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
//videos
|
||||||
|
const channel = await modules.fetch(
|
||||||
|
config.tubeApi +
|
||||||
|
`channel?id=${ID}&tab=shorts&Continuation=${continuation}`
|
||||||
|
);
|
||||||
|
const c = await channel.text();
|
||||||
|
const tj = JSON.parse(modules.toJson(c));
|
||||||
|
|
||||||
|
const summary = await wiki.summary(k.Channel.Metadata.Name);
|
||||||
|
|
||||||
|
var w = "";
|
||||||
|
if (summary.title === "Not found.") {
|
||||||
|
w = "none";
|
||||||
|
}
|
||||||
|
if (summary.title !== "Not found.") {
|
||||||
|
w = summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { Subscribers: subscribers } = k.Channel.Metadata;
|
||||||
|
const description = k.Channel.Contents.ItemSection.About.Description;
|
||||||
|
|
||||||
|
var d = description.toString().replace(/\n/g, " <br> ");
|
||||||
|
if (d === "[object Object]") {
|
||||||
|
var d = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
var dnoreplace = description.toString();
|
||||||
|
if (dnoreplace === "[object Object]") {
|
||||||
|
var dnoreplace = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
renderTemplate(res, req, "channel.ejs", {
|
||||||
|
ID: ID,
|
||||||
|
tab: tab,
|
||||||
|
j: k,
|
||||||
|
tj: tj,
|
||||||
|
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", "")
|
||||||
|
: "Private",
|
||||||
|
desc: d,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue