Searching
This commit is contained in:
parent
add7a5439d
commit
e83a557f65
1 changed files with 21 additions and 4 deletions
25
index.js
25
index.js
|
@ -32,8 +32,8 @@ function getThumbor() {
|
|||
function searchResultToHTML(results) {
|
||||
var addedHTML = ""
|
||||
for (let index = 0; index < results.length; index++) {
|
||||
const result = results[index].content;
|
||||
if (result && result.type == "Video" && result.published.text) {
|
||||
const result = results[index].content || results[index];
|
||||
if (result && result.type == "Video" && result.published) {
|
||||
addedHTML += `
|
||||
<div class="col-xxl-4 col-sm-6 resultContainer">
|
||||
<div class="videoResult container-fluid row">
|
||||
|
@ -46,7 +46,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.text}</p>
|
||||
<p class="resultDescription">${(result.description_snippet || result.snippets[0].text.runs[0]).text}</p>
|
||||
<p style="display: block;">${result.published.text}</p>
|
||||
</a>
|
||||
</div>
|
||||
|
@ -70,7 +70,7 @@ app.get("/", async (req, res) => {
|
|||
|
||||
res.setHeader("Content-Type", "text/html")
|
||||
res.setHeader("X-Accel-Buffering", "no")
|
||||
|
||||
|
||||
var html = fs.readFileSync(path.join(resources, 'mainPage.html')).toString()
|
||||
|
||||
res.write(html.substring(0, html.indexOf("{RESULTS}")))
|
||||
|
@ -82,6 +82,23 @@ app.get("/", async (req, res) => {
|
|||
res.write(addedHTML + html.substring(html.indexOf("{RESULTS}") + 9), () => {res.end()})
|
||||
})
|
||||
|
||||
app.get("/search", async (req, res) => {
|
||||
var innerTube = await ytjs.Innertube.create()
|
||||
|
||||
res.setHeader("Content-Type", "text/html")
|
||||
res.setHeader("X-Accel-Buffering", "no")
|
||||
|
||||
var html = fs.readFileSync(path.join(resources, 'searchPage.html')).toString()
|
||||
|
||||
res.write(html.substring(0, html.indexOf("{RESULTS}")))
|
||||
|
||||
var results = (await innerTube.search('test'))
|
||||
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue