From 3c5710e1929a7d3a90a1345908c9fc9b01816b3f Mon Sep 17 00:00:00 2001 From: ashley Date: Sat, 15 Jun 2024 11:49:13 +0000 Subject: [PATCH] woo :3 --- .../init/pages-channel-and-download.js | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/libpoketube/init/pages-channel-and-download.js b/src/libpoketube/init/pages-channel-and-download.js index 8a51bbad..1d031d2d 100644 --- a/src/libpoketube/init/pages-channel-and-download.js +++ b/src/libpoketube/init/pages-channel-and-download.js @@ -184,7 +184,69 @@ module.exports = function (app, config, renderTemplate) { }); app.get("/web", async (req, res) => { - res.redirect("/") + const query = req.query.query; + const tab = req.query.tab; + + const { fetch } = await import("undici"); + + const search = await fetch(atob("aHR0cHM6Ly80Z2V0LnN1ZG92YW5pbGxhLm9yZy9hcGkvdjEvd2ViP3M9") + query); + const web = getJson(await search.text()); + + if (req.query.lucky === "true") { + res.redirect("/im-feeling-lucky?query=" + query); + } + + var uaos = req.useragent.os; + var IsOldWindows; + + if (uaos == "Windows 7" && req.useragent.browser == "Firefox") { + IsOldWindows = true; + } else if (uaos == "Windows 8" && req.useragent.browser == "Firefox") { + IsOldWindows = true; + } else { + IsOldWindows = false; + } + + const poketube_universe_value = "poketube_smart_search"; + + if (query?.includes("youtube.com/watch?v=")) { + try { + var videoid = query?.split("v="); + + res.redirect("/watch?v=" + videoid[1]); + } catch { + return; + } + } + + if (query && query.startsWith("!") && query.length > 2) { + res.redirect("https://lite.duckduckgo.com/lite/?q=" + query); + } + + if (!query) { + return renderTemplate(res, req, "search-web-main.ejs"); + } + + let continuation = req.query.continuation || ""; + + try { + const results = web.web; + + renderTemplate(res, req, "search-web.ejs", { + j: "", + IsOldWindows, + h: "", + tab, + continuation, + isMobile: req.useragent.isMobile, + results: results, + q: query, + summary: "", + }); + } catch (error) { + console.error(`Error while searching for '${query}':`, error); + res.redirect("/"); + } }); app.get("/channel/", async (req, res) => {