From ff496892d77aeca3cef9455a0c22244f3e689124 Mon Sep 17 00:00:00 2001 From: Bingus_Violet Date: Wed, 14 Feb 2024 09:03:53 -0600 Subject: [PATCH] Add channels to search --- index.js | 63 ++++++++++++++++++++++++++++++++++++-------- static/mainStyle.css | 5 ++++ 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 64997ef..fc69c6c 100644 --- a/index.js +++ b/index.js @@ -30,11 +30,20 @@ function getThumbor() { } function searchResultToHTML(results) { + var videosHTML = "

Videos:

" + var channelsHTML = "

Channels:

" var addedHTML = "" for (let index = 0; index < results.length; index++) { const result = results[index].content || results[index]; - if (result && result.type == "Video" && result.published) { - addedHTML += ` + if (result && result.type == "Video" && result.published && result.duration != "N/A") { + if (!result.description_snippet) { + if (result.snippets) { + result.description_snippet = result.snippets[0].text.runs[0] + } else { + result.description_snippet = {text: ''} + } + } + videosHTML += `
` + } else if (result.type == "Channel" && result.author.thumbnails[0]) { + channelsHTML += ` + + ` + } else { + console.log(result.type) } } + if (channelsHTML.length > 30) { + addedHTML += channelsHTML + } + if (videosHTML.length > 30) { + addedHTML += videosHTML + } + return addedHTML } @@ -83,6 +121,7 @@ app.get("/", async (req, res) => { }) app.get("/search", async (req, res) => { + var search = req.query.q var innerTube = await ytjs.Innertube.create() res.setHeader("Content-Type", "text/html") @@ -90,19 +129,21 @@ app.get("/search", async (req, res) => { var html = fs.readFileSync(path.join(resources, 'searchPage.html')).toString() + html = html.replaceAll("{SEARCH}", search) + res.write(html.substring(0, html.indexOf("{RESULTS}"))) - var results = (await innerTube.search('test')) + var results = (await innerTube.search(search, {type: "all"})) var addedHTML = searchResultToHTML(results.results) res.write(addedHTML + html.substring(html.indexOf("{RESULTS}") + 9), () => {res.end()}) }) -process.on('uncaughtException', (err, origin) => { - fs.writeSync( - process.stderr.fd, - `Caught exception: ${err}\n` + - `Exception origin: ${origin}`, - ); -}); \ No newline at end of file +// process.on('uncaughtException', (err, origin) => { +// fs.writeSync( +// process.stderr.fd, +// `Caught exception: ${err}\n` + +// `Exception origin: ${origin}`, +// ); +// }); \ No newline at end of file diff --git a/static/mainStyle.css b/static/mainStyle.css index 259ed07..7e15958 100644 --- a/static/mainStyle.css +++ b/static/mainStyle.css @@ -196,6 +196,11 @@ hr { margin: 20px auto; } +.note { + color: darkgray; + font-size: 0.9rem +} + #channelBar { background-color: rgb(15, 10, 25); border-bottom: 2px gray solid;