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");
|
2024-03-27 12:37:57 +01:00
|
|
|
const os = require('os');
|
2023-11-13 18:05:08 +01:00
|
|
|
const cnf = require("../../../config.json");
|
2024-02-16 05:23:07 +01:00
|
|
|
const innertube = require("../libpoketube-youtubei-objects.json");
|
2024-07-03 22:54:59 +02:00
|
|
|
const { execSync } = require('child_process');
|
2023-11-29 20:30:47 +01:00
|
|
|
|
2024-06-19 13:01:01 +02:00
|
|
|
const verfull = "v24.1906-sho-MAJOR_UPDATE-stable-dev-nonLTS-git-MTcxODc5NDY3NQ==";
|
|
|
|
const versmol = "v24.1906-sho"
|
2023-11-18 10:19:29 +01:00
|
|
|
const branch = "dev/master";
|
2024-06-19 13:01:01 +02:00
|
|
|
const codename = "sho";
|
|
|
|
const versionnumber = "293";
|
|
|
|
const relaseunixdate = "MTcxODc5NDY3NQ=="
|
|
|
|
const updatequote = "pls fund vennie plush -Bims"
|
2023-11-29 20:30:47 +01:00
|
|
|
|
2022-11-16 11:27:48 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
module.exports = function (app, config, renderTemplate) {
|
2023-11-13 18:05:08 +01:00
|
|
|
|
2023-11-07 15:55:10 +01:00
|
|
|
app.get("/vi/:v/:t", async function (req, res) {
|
2024-08-26 22:56:09 +02:00
|
|
|
var url = `https://iv.ggtyler.dev/vi/${req.params.v}/${req.params.t}`
|
2023-11-29 20:30:47 +01:00
|
|
|
|
|
|
|
let f = await modules.fetch(url + `?cachefixer=${btoa(Date.now())}`, {
|
2023-11-07 15:55:10 +01:00
|
|
|
method: req.method,
|
|
|
|
});
|
|
|
|
|
2023-11-29 20:30:47 +01:00
|
|
|
f.body.pipe(res);
|
2023-11-07 16:04:56 +01:00
|
|
|
|
2023-11-29 20:30:47 +01:00
|
|
|
});
|
2023-11-29 20:18:05 +01:00
|
|
|
|
2023-11-29 20:30:47 +01:00
|
|
|
app.get("/avatars/:v", async function (req, res) {
|
2024-08-26 22:56:09 +02:00
|
|
|
var url = `https://iv.ggtyler.dev/ggpht/${req.params.v}`;
|
2023-11-07 17:00:57 +01:00
|
|
|
|
2023-11-29 20:30:47 +01:00
|
|
|
let f = await modules.fetch(url + `?cachefixer=${btoa(Date.now())}`, {
|
2023-11-07 16:04:56 +01:00
|
|
|
method: req.method,
|
|
|
|
});
|
|
|
|
|
2023-11-29 20:30:47 +01:00
|
|
|
f.body.pipe(res);
|
2023-11-07 17:00:57 +01:00
|
|
|
});
|
|
|
|
|
2023-11-20 15:20:38 +01:00
|
|
|
app.get("/ggpht/:v", async function (req, res) {
|
2024-08-26 22:56:09 +02:00
|
|
|
var url = `https://iv.ggtyler.dev/ggpht/${req.params.v}`;
|
2023-11-20 15:20:38 +01:00
|
|
|
|
2023-11-29 20:30:47 +01:00
|
|
|
let f = await modules.fetch(url + `?cachefixer=${btoa(Date.now())}`, {
|
2023-11-20 15:20:38 +01:00
|
|
|
method: req.method,
|
|
|
|
});
|
|
|
|
|
2023-11-29 20:30:47 +01:00
|
|
|
f.body.pipe(res);
|
2023-11-20 15:20:38 +01:00
|
|
|
});
|
|
|
|
|
2023-11-29 20:22:11 +01:00
|
|
|
|
2023-11-29 20:30:47 +01:00
|
|
|
app.get("/avatars/ytc/:v", async function (req, res) {
|
2024-08-26 17:24:23 +02:00
|
|
|
var url = `https://ca1.iv.ggtyler.dev/ggpht/ytc/${req.params.v.replace("ytc", "")}`;
|
2023-11-07 16:04:56 +01:00
|
|
|
|
2023-11-29 20:30:47 +01:00
|
|
|
let f = await modules.fetch(url + `?cachefixer=${btoa(Date.now())}`, {
|
2023-11-07 17:00:57 +01:00
|
|
|
method: req.method,
|
|
|
|
});
|
|
|
|
|
2023-11-29 20:30:47 +01:00
|
|
|
f.body.pipe(res);
|
2023-11-07 16:04:56 +01:00
|
|
|
});
|
2023-11-29 20:30:47 +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
|
|
|
|
2024-06-09 10:32:16 +02:00
|
|
|
const url = `https://tube-nightly.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) => {
|
2023-09-17 21:43:43 +02:00
|
|
|
const { fetch } = await import("undici");
|
2023-11-29 20:30:47 +01:00
|
|
|
|
2022-11-15 17:40:40 +01:00
|
|
|
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 {
|
2024-08-26 22:56:09 +02:00
|
|
|
let url = `https://iv.ggtyler.dev/api/v1/captions/${id}?label=${l}`;
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2023-09-17 21:43:43 +02:00
|
|
|
let f = await fetch(url);
|
2023-09-09 18:58:37 +02:00
|
|
|
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
|
|
|
});
|
2024-03-20 17:01:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
app.use("/sb/i/:v/:imagePath/:img", async function (req, res) {
|
|
|
|
const { v, imagePath, img } = req.params;
|
|
|
|
const { sqp, xywh } = req.query;
|
|
|
|
const sighMatch = req.url.match(/&sigh=([^&#]+)/);
|
|
|
|
const sigh = sighMatch ? sighMatch[1] : undefined;
|
|
|
|
|
|
|
|
|
|
|
|
const url = `https://yt.miruku.cafe/sb/i/${v}/${imagePath}/${img}?sqp=${sqp}&sigh=${sigh}&xywh=${req.query.xywh}`;
|
|
|
|
|
|
|
|
try {
|
|
|
|
let f = await modules.fetch(url + `?cachefixer=${btoa(Date.now())}`, {
|
|
|
|
method: req.method,
|
|
|
|
});
|
|
|
|
|
|
|
|
f.body.pipe(res);
|
|
|
|
console.log(url)
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error fetching image:", error);
|
|
|
|
res.status(500).send("Error fetching image");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get("/api/storyboards", async (req, res) => {
|
|
|
|
const { fetch } = await import("undici");
|
|
|
|
|
|
|
|
const id = req.query.v;
|
|
|
|
const l = req.query.h;
|
|
|
|
|
|
|
|
try {
|
|
|
|
let url = `https://yt.miruku.cafe/api/v1/storyboards/${id}?width=320&height=180`;
|
|
|
|
|
|
|
|
let f = await fetch(url);
|
|
|
|
let body = await f.text();
|
|
|
|
|
|
|
|
body = body.replace(/#xywh=(\d+),(\d+),(\d+),(\d+)/g, (match, x, y, w, h) => {
|
|
|
|
return `&xywh=${x},${y},${w},${h}`;
|
|
|
|
});
|
|
|
|
|
|
|
|
res.send(body);
|
|
|
|
} catch {}
|
|
|
|
});
|
2022-11-09 17:51:10 +01:00
|
|
|
|
2024-07-03 10:06:38 +02: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);
|
|
|
|
});
|
2023-01-01 11:00:04 +01:00
|
|
|
|
2024-08-01 16:25:29 +02:00
|
|
|
app.get("/api/manifest/dash/id/:id", async (req, res) => {
|
|
|
|
const id = req.params.id;
|
|
|
|
|
|
|
|
let url = `https://invid-api.poketube.fun/bHj665PpYhUdPWuKPfZuQGoX/api/manifest/dash/id/${id}`;
|
|
|
|
|
|
|
|
let f = await modules.fetch(url, {
|
|
|
|
method: req.method,
|
|
|
|
});
|
|
|
|
|
|
|
|
f.body.pipe(res);
|
|
|
|
});
|
|
|
|
|
2024-08-21 14:22:40 +02:00
|
|
|
app.get("/api/improving-poke/suggestions", async (req, res) => {
|
2024-07-03 10:49:11 +02:00
|
|
|
const query = req.query.q;
|
|
|
|
|
2024-07-14 13:00:19 +02:00
|
|
|
let url = `https://invid-api.poketube.fun/bHj665PpYhUdPWuKPfZuQGoX/api/v1/search/suggestions?q=${query}`;
|
2024-07-03 10:49:11 +02:00
|
|
|
|
|
|
|
let f = await modules.fetch(url, {
|
|
|
|
method: req.method,
|
|
|
|
});
|
2024-08-21 15:10:52 +02:00
|
|
|
|
2024-08-21 22:20:41 +02:00
|
|
|
f.body.pipe(res);
|
2024-07-03 10:49:11 +02:00
|
|
|
});
|
|
|
|
|
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) => {
|
2024-05-09 16:58:20 +02:00
|
|
|
let latestCommitHash;
|
|
|
|
|
2023-03-07 18:21:34 +01:00
|
|
|
const invidious = await modules
|
2024-07-14 13:00:19 +02:00
|
|
|
.fetch("https://invid-api.poketube.fun/bHj665PpYhUdPWuKPfZuQGoX/api/v1/stats")
|
2023-03-07 18:21:34 +01:00
|
|
|
.then((res) => res.text())
|
|
|
|
.then((txt) => getJson(txt));
|
2024-03-27 12:37:57 +01:00
|
|
|
|
|
|
|
const cpus = os.cpus();
|
2024-03-27 12:40:30 +01:00
|
|
|
const totalMemory = os.totalmem() / (1024 * 1024 * 1024);
|
|
|
|
const roundedMemory = totalMemory.toFixed(2);
|
2023-03-07 18:21:34 +01:00
|
|
|
|
2024-07-03 22:52:22 +02:00
|
|
|
execSync('git rev-list HEAD -n 1 --abbrev-commit', (error, stdout, stderr) => {
|
2024-05-09 17:03:50 +02:00
|
|
|
if (error || stderr) {
|
|
|
|
console.error(`Error executing command: ${error || stderr}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
latestCommitHash = stdout.trim();
|
|
|
|
});
|
2024-05-09 16:58:20 +02:00
|
|
|
|
2023-03-07 18:21:34 +01:00
|
|
|
const response = {
|
2023-11-18 10:21:57 +01:00
|
|
|
pt_version: {
|
2023-11-29 20:30:47 +01:00
|
|
|
version:versmol,
|
2024-07-03 22:56:58 +02:00
|
|
|
version_full:verfull,
|
|
|
|
commit: latestCommitHash
|
2023-11-18 10:21:57 +01:00
|
|
|
},
|
2023-03-07 18:21:34 +01:00
|
|
|
branch,
|
2023-11-18 10:19:29 +01:00
|
|
|
updatequote,
|
2023-05-08 18:33:48 +02:00
|
|
|
relaseunixdate,
|
2023-03-07 18:21:34 +01:00
|
|
|
vernum: versionnumber,
|
|
|
|
codename,
|
2023-11-29 20:30:47 +01:00
|
|
|
config:cnf,
|
2024-03-27 12:37:57 +01:00
|
|
|
system:{
|
2024-03-27 12:40:30 +01:00
|
|
|
ram:`${roundedMemory} GB`,
|
2024-03-27 12:37:57 +01:00
|
|
|
cpu:cpus[0].model,
|
|
|
|
},
|
2023-03-07 18:21:34 +01:00
|
|
|
packages: {
|
|
|
|
libpt: version,
|
|
|
|
node: process.version,
|
|
|
|
v8: process.versions.v8,
|
|
|
|
},
|
|
|
|
invidious,
|
2024-02-16 05:23:07 +01:00
|
|
|
innertube,
|
2023-03-07 18:21:34 +01:00
|
|
|
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 {
|
2024-06-02 00:24:55 +02:00
|
|
|
const url = `https://raw.githubusercontent.com/ashley0143/poke/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;
|