From 00eb2b59794b2901b28dccf25a7bfab4e9c68299 Mon Sep 17 00:00:00 2001 From: Violet <110205356+Violets-puragtory@users.noreply.github.com> Date: Sun, 29 Oct 2023 00:08:28 +0000 Subject: [PATCH] Searching!!! --- index.js | 46 ++++++++++++++++++++++-- resources/player.html | 18 +++++++--- resources/searchPage.html | 33 +++++++++++++++++ static/index.html | 13 +++++-- static/mainStyle.css | 76 +++++++++++++++++++++++++++++++++------ 5 files changed, 168 insertions(+), 18 deletions(-) create mode 100644 resources/searchPage.html diff --git a/index.js b/index.js index 727da4f..6a5c5d2 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ const resources = path.join(__dirname, 'resources') const cachePath = path.join(__dirname, 'cache') const playerPath = path.join(resources, 'player.html') +const searchPath = path.join(resources, 'searchPage.html') const cssHeader = `` @@ -39,6 +40,44 @@ app.listen(PORT, () => { console.log("Simpletube is now listening on port: " + PORT) }) +app.get("/search", async (req, res) => { + var search = req.query.q || "How to search on SimpleTube" + res.setHeader("Content-Type", "text/html") + youtube.search(search).then((results) => { + var videos = results.videos + var html = fs.readFileSync(searchPath).toString() + + html = html.replace("{SEARCH}", search) + + var addedHTML = "" + + for (let index = 0; index < videos.length; index++) { + const result = videos[index]; + addedHTML += ` +
+
+ + + +
+
+ +

${result.title}

+

${result.description}


+ +
${result.channel.name} + +
+
+ + ` + console.log(result) + } + + res.send(html.replace("{RESULTS}", addedHTML)) + }) +}) + app.get("/video", async (req, res) => { var id = req.query.q || req.query.v @@ -134,7 +173,7 @@ app.get("/video", async (req, res) => { }) app.get("/watch", async (req, res) => { - var id = req.query.q || req.query.v + var id = req.query.q || req.query.v || "ubFq-wV3Eic" res.setHeader("Content-Type", "text/html") @@ -157,7 +196,10 @@ app.get("/watch", async (req, res) => { html = html.replace("{CSS_HEADER}", cssHeader) - html = html.replace("{VIDEO_TITLE}", vidInfo.title) + for (let index = 0; index < 2; index++) { + html = html.replace("{VIDEO_TITLE}", vidInfo.title) + + } html = html.replace("{VIDEO_DESCRIPTION}", vidInfo.description || "No Description.") diff --git a/resources/player.html b/resources/player.html index 9197aab..a37005a 100644 --- a/resources/player.html +++ b/resources/player.html @@ -5,14 +5,24 @@ - {CSS_HEADER} + + - Document + + {VIDEO_TITLE} -
-

Simpletube

+
+ +
+
+ +
+