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");
|
|
|
|
|
2023-03-07 18:21:34 +01:00
|
|
|
function getJson(str) {
|
|
|
|
try {
|
|
|
|
return JSON.parse(str);
|
|
|
|
} catch {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2022-11-15 17:40:40 +01:00
|
|
|
|
2023-03-07 18:21:34 +01:00
|
|
|
const pkg = require("../../../package.json");
|
2023-09-09 18:58:37 +02:00
|
|
|
const ver = "v23.0909-aStfl-MAJOR-stable-nonLTS-git-MTY4MzU2MzMxNQ==";
|
2023-03-07 18:21:34 +01:00
|
|
|
const branch = "master";
|
2023-09-09 18:58:37 +02:00
|
|
|
const codename = "astolfo-3";
|
|
|
|
const versionnumber = "245";
|
2023-06-02 18:04:31 +02:00
|
|
|
const relaseunixdate = "MTY4NTcxNzAzOQ==";
|
2022-11-16 11:27:48 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
module.exports = function (app, config, renderTemplate) {
|
2023-09-09 18:58:37 +02:00
|
|
|
app.get("/embed/:v", async function (req, res) {
|
|
|
|
res.send("Disabled until further notice");
|
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;
|
2023-01-01 11:00:04 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
if (req.query.f) {
|
|
|
|
var format = "mp3";
|
|
|
|
}
|
2023-09-09 18:58:37 +02: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/subtitles", async (req, res) => {
|
|
|
|
const id = req.query.v;
|
|
|
|
const l = req.query.h;
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2023-09-09 18:58:37 +02:00
|
|
|
try {
|
|
|
|
let url = `https://invid-api.poketube.fun/api/v1/captions/${id}?label=${l}`;
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2023-09-09 18:58:37 +02:00
|
|
|
let f = await modules.fetch(url);
|
|
|
|
const body = await f.text();
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2023-09-09 18:58:37 +02:00
|
|
|
res.send(body);
|
|
|
|
} catch {}
|
2022-11-15 17:40:40 +01:00
|
|
|
});
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2023-01-01 11:00:04 +01:00
|
|
|
app.get("/feeds/videos.xml", async (req, res) => {
|
|
|
|
const id = req.query.channel_id;
|
|
|
|
|
|
|
|
let url = `https://youtube.com/feeds/videos.xml?channel_id=${id}`;
|
|
|
|
|
|
|
|
let f = await modules.fetch(url, {
|
|
|
|
method: req.method,
|
|
|
|
});
|
|
|
|
|
|
|
|
f.body.pipe(res);
|
|
|
|
});
|
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
app.get("/api/redirect", async (req, res) => {
|
2023-03-04 17:31:49 +01:00
|
|
|
const red_url = atob(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
|
|
|
|
2023-05-04 18:34:43 +02:00
|
|
|
res.redirect(red_url + "?f=" + req.query.u);
|
2022-11-15 17:40:40 +01:00
|
|
|
});
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2023-09-09 18:58:37 +02:00
|
|
|
app.get("/api", async (req, res) => {
|
|
|
|
res.redirect("/api/version.json");
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get("/api/v1", async (req, res) => {
|
|
|
|
res.redirect("https://invid-api.poketube.fun/api/v1/stats");
|
|
|
|
});
|
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
app.get("/api/version.json", async (req, res) => {
|
2023-03-07 18:21:34 +01:00
|
|
|
const invidious = await modules
|
2023-03-09 16:51:54 +01:00
|
|
|
.fetch("https://invid-api.poketube.fun/api/v1/stats")
|
2023-03-07 18:21:34 +01:00
|
|
|
.then((res) => res.text())
|
|
|
|
.then((txt) => getJson(txt));
|
|
|
|
|
|
|
|
const response = {
|
|
|
|
pt_version: ver,
|
|
|
|
branch,
|
2023-05-08 18:33:48 +02:00
|
|
|
relaseunixdate,
|
2023-03-07 18:21:34 +01:00
|
|
|
vernum: versionnumber,
|
|
|
|
codename,
|
|
|
|
packages: {
|
|
|
|
libpt: version,
|
|
|
|
node: process.version,
|
|
|
|
v8: process.versions.v8,
|
|
|
|
},
|
|
|
|
invidious,
|
|
|
|
flac: {
|
2023-03-24 21:58:24 +01:00
|
|
|
poketube_flac: "1.2a",
|
|
|
|
apple_musickit: "1.2.3",
|
2023-03-07 18:21:34 +01:00
|
|
|
poketube_normalize_volume: "1.2.23-yt",
|
|
|
|
},
|
|
|
|
piwik: "master",
|
|
|
|
process: process.versions,
|
|
|
|
dependencies: pkg.dependencies,
|
2023-09-09 18:58:37 +02:00
|
|
|
poketubeapicode: btoa(Date.now() + invidious.software.version),
|
2023-03-07 18:21:34 +01:00
|
|
|
};
|
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
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) => {
|
2023-09-16 19:03:11 +02:00
|
|
|
const { fetch } = await import("undici");
|
|
|
|
|
2023-01-07 17:28:31 +01:00
|
|
|
try {
|
|
|
|
const url = `https://codeberg.org/Ashley/poketube/raw/branch/main/instances.json`;
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2023-09-16 19:03:11 +02:00
|
|
|
let f = await fetch(url)
|
2023-01-07 17:28:31 +01:00
|
|
|
.then((res) => res.text())
|
|
|
|
.then((json) => JSON.parse(json));
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2023-01-07 17:28:31 +01:00
|
|
|
res.json(f);
|
|
|
|
} catch {
|
|
|
|
res.json("error while fetching instances");
|
|
|
|
}
|
2022-11-15 17:40:40 +01:00
|
|
|
});
|
|
|
|
};
|
2022-11-16 11:27:48 +01:00
|
|
|
|
2022-11-16 15:00:15 +01:00
|
|
|
module.exports.api = versionnumber;
|