From 65c9953f05635414a2aa3667fb32ae34733be362 Mon Sep 17 00:00:00 2001 From: Ashley Date: Wed, 18 Oct 2023 18:20:07 +0000 Subject: [PATCH] add a new page for web search results to make the search faster --- .../init/pages-channel-and-download.js | 85 ++++++++++++++----- 1 file changed, 62 insertions(+), 23 deletions(-) diff --git a/src/libpoketube/init/pages-channel-and-download.js b/src/libpoketube/init/pages-channel-and-download.js index acc22be7..db07674c 100644 --- a/src/libpoketube/init/pages-channel-and-download.js +++ b/src/libpoketube/init/pages-channel-and-download.js @@ -119,35 +119,74 @@ module.exports = function (app, config, renderTemplate) { didYouMean = JSON.parse(searchJson.Search.Results.DynamicItem.Title); } - if (tab) { - search({ query: `${req.query.query}` }) - .then((results) => { - renderTemplate(res, req, "search.ejs", { - j: searchJson, - IsOldWindows, - h: didYouMean, - tab, - continuation, - results: results, - q: query, - summary: "", - }); - }) - .catch((e) => { - console.log(e); - }); - } else { - renderTemplate(res, req, "search.ejs", { - j: searchJson, + renderTemplate(res, req, "search.ejs", { + j: searchJson, + IsOldWindows, + h: didYouMean, + tab, + continuation, + results: "", + q: query, + summary: "", + }); + } catch (error) { + console.error(`Error while searching for '${query}':`, error); + res.redirect("/"); + } + }); + + app.get("/web", async (req, res) => { + const query = req.query.query; + const tab = req.query.tab; + + const search = require("google-it"); + + 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 res.redirect("/"); + } + + let continuation = req.query.continuation || ""; + + try { + search({ query: `${req.query.query}` }).then((results) => { + renderTemplate(res, req, "search-web.ejs", { + j: "", IsOldWindows, - h: didYouMean, + h: "", tab, continuation, - results: "", + results: results, q: query, summary: "", }); - } + }); } catch (error) { console.error(`Error while searching for '${query}':`, error); res.redirect("/");