diff --git a/index.js b/index.js index 3e9b4cc..8d7ca09 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,8 @@ const express = require("express"), fs = require("fs"), ytdl = require("ytdl-core"), bodyParser = require("body-parser"), - youtube = require("scrape-youtube") + youtube = require("scrape-youtube"), + ytExt = require("youtube-ext") const PORT = process.env.PORT || 8080 @@ -18,6 +19,7 @@ const searchCacheDur = (process.env.SEARCH_DUR || 24) * 3600000 const playerPath = path.join(resources, 'player.html') const searchPath = path.join(resources, 'searchPage.html') +const channelPath = path.join(resources, 'channelPage.html') const cssHeader = `` @@ -93,7 +95,6 @@ app.get("/search", async (req, res) => { var addedHTML = "" var channels = results.channels - if (channels.length > 0) { addedHTML += "


Channels:

" @@ -120,11 +121,12 @@ app.get("/search", async (req, res) => { } } - addedHTML += "


Videos:

" + if (videos.length > 0) { + addedHTML += "


Videos:

" - for (let index = 0; index < videos.length; index++) { - const result = videos[index]; - addedHTML += ` + for (let index = 0; index < videos.length; index++) { + const result = videos[index]; + addedHTML += `
@@ -149,6 +151,7 @@ app.get("/search", async (req, res) => {
` + } } res.send(html.replace("{RESULTS}", addedHTML)) @@ -178,6 +181,73 @@ app.get("/search", async (req, res) => { } }) +app.get("/channel", async (req, res) => { + var section = req.query.s || "videos" + var channel = req.query.q || "UChcrBJNJLZucy3TPyGyAY2g" + + var html = fs.readFileSync(channelPath).toString() + + var info = await ytExt.channelInfo(channel, { includeVideos: true }) + + var videos = info.videos + console.log(info) + var addedHTML = "" + if (section == "videos") { + for (let index = 0; index < videos.length; index++) { + const result = videos[index]; + if (result.title != undefined) { + addedHTML += ` +
+ +
+ ` + } else { + addedHTML = "" + } + + } + } else if (section == "about") { + addedHTML += ` +
+

Description:

+

${info.description}

+

Subscribers: ${info.subscribers.pretty} +

+ ` + } + + if (addedHTML == "") { + addedHTML = `

Failed to load ${section}! Sorry... T^T

` + } + + html = html.replace("{RESULTS}", addedHTML) + + html = html.replace("{CHANNEL_NAME}", info.name) + html = html.replace("{CHANNEL_DESC}", info.description) + + for (let index = 0; index < 3; index++) { + html = html.replace("{CHANNEL_ID}", info.id) + + } + + html = html.replace("{CHANNEL_PFP}", info.thumbnails[0].url) + html = html.replace("{SUB_COUNT}", info.subscribers.pretty) + + res.send(html) +}) + app.get("/video", async (req, res) => { var id = req.query.q || req.query.v var range = req.headers.range diff --git a/package-lock.json b/package-lock.json index af9cc52..8b73a01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,9 +12,18 @@ "body-parser": "^1.20.2", "express": "^4.18.2", "scrape-youtube": "^2.4.0", + "youtube-ext": "^1.1.16", "ytdl-core": "^4.11.5" } }, + "node_modules/@fastify/busboy": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.0.0.tgz", + "integrity": "sha512-JUFJad5lv7jxj926GPgymrWQxxjPYuJNiNjNMzqT+HiuP6Vl3dk5xzG+8sTX96np0ZAluvaMzPsjhHZ5rNuNQQ==", + "engines": { + "node": ">=14" + } + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -699,6 +708,17 @@ "node": ">= 0.6" } }, + "node_modules/undici": { + "version": "5.27.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.27.0.tgz", + "integrity": "sha512-l3ydWhlhOJzMVOYkymLykcRRXqbUaQriERtR70B9LzNkZ4bX52Fc8wbTDneMiwo8T+AemZXvXaTx+9o5ROxrXg==", + "dependencies": { + "@fastify/busboy": "^2.0.0" + }, + "engines": { + "node": ">=14.0" + } + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -723,6 +743,14 @@ "node": ">= 0.8" } }, + "node_modules/youtube-ext": { + "version": "1.1.16", + "resolved": "https://registry.npmjs.org/youtube-ext/-/youtube-ext-1.1.16.tgz", + "integrity": "sha512-vyzHSwxlCAwqWUxZKJ/5g139BgnbmZFTy9I0nxDwqlbAh74dB1LjayCoB5BgLaaIkSMruEQwlf5bF+EeR235qA==", + "dependencies": { + "undici": "^5.26.3" + } + }, "node_modules/ytdl-core": { "version": "4.11.5", "resolved": "https://registry.npmjs.org/ytdl-core/-/ytdl-core-4.11.5.tgz", diff --git a/package.json b/package.json index 8cc35e5..9545e24 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "body-parser": "^1.20.2", "express": "^4.18.2", "scrape-youtube": "^2.4.0", + "youtube-ext": "^1.1.16", "ytdl-core": "^4.11.5" } } diff --git a/resources/channelPage.html b/resources/channelPage.html new file mode 100644 index 0000000..684c86a --- /dev/null +++ b/resources/channelPage.html @@ -0,0 +1,51 @@ + + + + + + + + + + + SimpleTube + + + +
+ +
+
+ +
+
+
+
+

* Channels are still a work in progress.

+
+ +

Subscribers: {SUB_COUNT}

+
+
+

{CHANNEL_NAME}

+

{CHANNEL_DESC}

+
+ +
+ Videos +
+
+ About +
+
+
+
+ {RESULTS} +
+
+ + + \ No newline at end of file diff --git a/static/index.html b/static/index.html index 985e319..67d8fd4 100644 --- a/static/index.html +++ b/static/index.html @@ -25,7 +25,7 @@

Welcome to SimpleTube

-

SimpleTube is a Youtube client that aims to be free of Javascript, as small as possible, and lack annoyances. +

SimpleTube is a Youtube client that aims to be free and fast. (and have no ads!)
Currently SimpleTube does not have a trending tab or anything, so please use the search function at the top!
diff --git a/static/mainStyle.css b/static/mainStyle.css index d771c97..c27d41b 100644 --- a/static/mainStyle.css +++ b/static/mainStyle.css @@ -124,7 +124,7 @@ p { overflow: hidden; } -@media (max-width: 720px) { +/* @media (max-width: 720px) { .resultContainer { max-width: 450px; } @@ -140,7 +140,7 @@ p { .resultContainer { max-width: 550px; } -} +} */ .resultContainer { margin: 0 auto; @@ -194,4 +194,20 @@ main { hr { margin: 20px auto; +} + +#channelBar { + background-color: rgb(15, 10, 25); + border-bottom: 2px gray solid; + padding: 20px; + margin: 0; + width: 100%; +} + +.channelLink { + color: white; + font-size: 1.5rem; + border: 2px white solid; + display: inline-block; + padding: 10px } \ No newline at end of file