2022-11-15 17:40:40 +01:00
|
|
|
const {
|
|
|
|
fetcher,
|
|
|
|
core,
|
|
|
|
wiki,
|
|
|
|
musicInfo,
|
|
|
|
modules,
|
|
|
|
version,
|
|
|
|
initlog,
|
|
|
|
init,
|
|
|
|
} = require("../libpoketube-initsys.js");
|
2022-11-09 17:51:10 +01:00
|
|
|
const {
|
|
|
|
IsJsonString,
|
|
|
|
convert,
|
|
|
|
getFirstLine,
|
|
|
|
capitalizeFirstLetter,
|
|
|
|
turntomins,
|
|
|
|
getRandomInt,
|
|
|
|
getRandomArbitrary,
|
|
|
|
} = require("../ptutils/libpt-coreutils.js");
|
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
const pkg = require("../../../package.json");
|
|
|
|
|
2022-12-15 17:08:10 +01:00
|
|
|
const ver = "v22.1215-c98Lu-stable"
|
|
|
|
const versionnumber = "102"
|
2022-11-16 11:27:48 +01:00
|
|
|
|
|
|
|
const response = {
|
|
|
|
pt_version: ver,
|
2022-11-16 15:00:15 +01:00
|
|
|
vernum:versionnumber,
|
2022-11-16 11:27:48 +01:00
|
|
|
packages: {
|
|
|
|
libpt: version,
|
|
|
|
node: process.version,
|
|
|
|
v8: process.versions.v8,
|
|
|
|
},
|
|
|
|
process: process.versions,
|
|
|
|
dependencies: pkg.dependencies,
|
|
|
|
};
|
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
module.exports = function (app, config, renderTemplate) {
|
|
|
|
app.get("/embed/:v", async function (req, res) {
|
|
|
|
var e = req.query.e;
|
|
|
|
var f = req.query.f;
|
|
|
|
var t = req.query.t;
|
|
|
|
var q = req.query.quality;
|
|
|
|
var v = req.params.v;
|
|
|
|
|
|
|
|
var fetching = await fetcher(v);
|
|
|
|
const video = await modules.fetch(config.tubeApi + `video?v=${v}`);
|
|
|
|
|
|
|
|
const json = fetching.video.Player;
|
|
|
|
const h = await video.text();
|
|
|
|
const k = JSON.parse(modules.toJson(h));
|
|
|
|
const engagement = fetching.engagement;
|
|
|
|
|
|
|
|
if (!v) res.redirect("/");
|
|
|
|
|
|
|
|
//video
|
|
|
|
if (!q) url = `https://tube.kuylar.dev/proxy/media/${v}/22`;
|
|
|
|
if (q === "medium") {
|
|
|
|
var url = `https://tube.kuylar.dev/proxy/media/${v}/18`;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderTemplate(res, req, "poketube-iframe.ejs", {
|
|
|
|
video: json,
|
|
|
|
url: url,
|
|
|
|
sha384: modules.hash,
|
|
|
|
qua: q,
|
|
|
|
engagement: engagement,
|
|
|
|
k: k,
|
|
|
|
optout: t,
|
|
|
|
t: config.t_url,
|
|
|
|
});
|
2022-11-13 12:49:48 +01:00
|
|
|
});
|
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
app.get("/api/search", async (req, res) => {
|
|
|
|
const query = req.query.query;
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
if (!query) {
|
|
|
|
return res.redirect("/");
|
|
|
|
}
|
|
|
|
return res.redirect(`/search?query=${query}`);
|
|
|
|
});
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
app.get("/api/video/download", async function (req, res) {
|
|
|
|
var v = req.query.v;
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
var format = "mp4";
|
|
|
|
var q = "22";
|
|
|
|
if (req.query.q) q = req.query.q;
|
|
|
|
if (req.query.f) {
|
|
|
|
var format = "mp3";
|
|
|
|
}
|
|
|
|
var fetching = await fetcher(v);
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
const json = fetching.video.Player;
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-12-15 17:20:03 +01:00
|
|
|
const url = `https://tube.kuylar.dev/proxy/media/${v}/${q}`;
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
res.redirect(url);
|
|
|
|
});
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
app.get("/api/video/downloadjson", async function (req, res) {
|
|
|
|
var v = req.query.v;
|
|
|
|
var fetching = await fetcher(v);
|
|
|
|
const url = fetching.video.Player.Formats.Format[1].URL;
|
|
|
|
res.json(url);
|
|
|
|
});
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
app.get("/api/subtitles", async (req, res) => {
|
|
|
|
const id = req.query.v;
|
|
|
|
const l = req.query.h;
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-12-13 19:24:28 +01:00
|
|
|
const url = `https://tube-srv.ashley143.gay/proxy/caption/${id}/${l}/`;
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
let f = await modules.fetch(url);
|
|
|
|
const body = await f.text();
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
res.send(body);
|
|
|
|
});
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
app.get("/api/redirect", async (req, res) => {
|
|
|
|
const red_url = req.query.u;
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
if (!red_url) {
|
|
|
|
res.redirect("/");
|
|
|
|
}
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
res.redirect(red_url);
|
|
|
|
});
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
app.get("/api/version.json", async (req, res) => {
|
|
|
|
res.json(response);
|
|
|
|
});
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
app.get("/api/instances.json", async (req, res) => {
|
|
|
|
const url = `https://codeberg.org/Ashley/poketube/raw/branch/main/instances.json`;
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
let f = await modules
|
|
|
|
.fetch(url)
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then((json) => JSON.parse(json));
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
res.json(f);
|
|
|
|
});
|
|
|
|
};
|
2022-11-16 11:27:48 +01:00
|
|
|
|
2022-11-16 15:00:15 +01:00
|
|
|
module.exports.api = versionnumber;
|