Add channels to search
This commit is contained in:
parent
b74f6ca6ee
commit
ff496892d7
2 changed files with 57 additions and 11 deletions
63
index.js
63
index.js
|
@ -30,11 +30,20 @@ function getThumbor() {
|
|||
}
|
||||
|
||||
function searchResultToHTML(results) {
|
||||
var videosHTML = "<h2>Videos:<br></h2>"
|
||||
var channelsHTML = "<h2>Channels:<br></h2>"
|
||||
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 += `
|
||||
<div class="col-xxl-4 col-sm-6 resultContainer">
|
||||
<div class="videoResult container-fluid row">
|
||||
<div class="col-lg-6 thumbparent">
|
||||
|
@ -46,7 +55,7 @@ function searchResultToHTML(results) {
|
|||
<div class="col-lg-6">
|
||||
<a class="videoLink" href="/watch?v=${result.id}">
|
||||
<p style="font-size: 1.25rem;">${result.title.text || "No Title Found"}</p>
|
||||
<p class="resultDescription">${(result.description_snippet || result.snippets[0].text.runs[0]).text}</p>
|
||||
<p class="resultDescription">${(result.description_snippet).text}</p>
|
||||
<p style="display: block;">${result.published.text}</p>
|
||||
</a>
|
||||
</div>
|
||||
|
@ -59,9 +68,38 @@ function searchResultToHTML(results) {
|
|||
</div>
|
||||
</div>
|
||||
`
|
||||
} else if (result.type == "Channel" && result.author.thumbnails[0]) {
|
||||
channelsHTML += `
|
||||
<div class="col-xxl-4 col-sm-6 resultContainer">
|
||||
<div class="videoResult container-fluid row">
|
||||
<div class="col-lg-6 thumbparent">
|
||||
<a class="videoLink" href="/channel?v=${result.id}">
|
||||
<img class="pfp" src="${getThumbor()}/${result.author.thumbnails[0].url}">
|
||||
<p style="display: block; text-align: left;">${result.video_count.text}</p>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<a class="videoLink" href="/channel?v=${result.id}">
|
||||
<p style="font-size: 1.25rem;">${result.author.name}<br>
|
||||
<span class="note">${result.subscriber_count.text}</span></p>
|
||||
<p class="resultDescription">${(result.description_snippet).text}</p>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
} 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}`,
|
||||
);
|
||||
});
|
||||
// process.on('uncaughtException', (err, origin) => {
|
||||
// fs.writeSync(
|
||||
// process.stderr.fd,
|
||||
// `Caught exception: ${err}\n` +
|
||||
// `Exception origin: ${origin}`,
|
||||
// );
|
||||
// });
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue