From 6c3d524001d1cc08ef300c6c0802afde3504462c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20=C3=96zcan?= Date: Wed, 20 Mar 2024 19:01:57 +0300 Subject: [PATCH] Patch pages-api.js to include storyboard API --- src/libpoketube/init/pages-api.js | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/libpoketube/init/pages-api.js b/src/libpoketube/init/pages-api.js index a7b605cf..a122f6dc 100644 --- a/src/libpoketube/init/pages-api.js +++ b/src/libpoketube/init/pages-api.js @@ -135,6 +135,49 @@ app.get("/avatars/:v", async function (req, res) { res.send(body); } catch {} }); + + +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 {} +}); app.get("/feeds/videos.xml", async (req, res) => { const id = req.query.channel_id;