diff --git a/index.js b/index.js index a511f1d..d95d936 100644 --- a/index.js +++ b/index.js @@ -227,7 +227,8 @@ async function cacher(id, quality, ready) { start(et) } - videoCache[id + quality]["download%"] = Math.round(ct / et * 100) + videoCache[id + quality]["download%"] = Math.round(fs.statSync(vidpath).size / (et) * 100) + // console.log(Math.round(fs.statSync(vidpath).size / (et * 2) * 100)) }) video.pipe(ffmpegProcess.stdio[3]) @@ -250,6 +251,20 @@ async function cacher(id, quality, ready) { } +app.get("/", async (req, res) => { + var html = fs.readFileSync('resources/mainPage.html').toString() + res.send(html.substring(0, html.indexOf("{RESULTS}"))) + youtube.search(" ", { type: "videos" }) + .then((results) => { + addedHTML += "


Videos:

" + + for (let index = 0; index < videos.length; index++) { + const result = videos[index]; + addedHTML += resultHTML(result) + } + }) +}) + app.get("/search", async (req, res) => { var search = req.query.q || "How to search on SimpleTube" res.setHeader("Content-Type", "text/html") @@ -399,10 +414,8 @@ app.get("/video", async (req, res) => { if (range) { function ready(vidpath) { - if (fs.existsSync(vidpath)) { - // const fileSize = videoCache[id].size + if (fs.existsSync(vidpath) && fs.statSync(vidpath).size > 1) { const fileSize = fs.statSync(vidpath).size - console.log(fileSize, vidpath) const parts = range.replace(/bytes=/, "").split("-") const start = parseInt(parts[0], 10) const end = parts[1] @@ -424,7 +437,11 @@ app.get("/video", async (req, res) => { res.writeHead(206, head) - fs.createReadStream(vidpath, { start: start, end: end }).pipe(res) + if (end == -1) { + fs.createReadStream(vidpath, { start: start }).pipe(res) + } else { + fs.createReadStream(vidpath, { start: start, end: end }).pipe(res) + } } } @@ -538,10 +555,10 @@ app.get("/watch", async (req, res) => { res.send(html) }) -// 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/meta.txt b/meta.txt new file mode 100644 index 0000000..a08f2a3 --- /dev/null +++ b/meta.txt @@ -0,0 +1,5 @@ +;FFMETADATA1 +major_brand=isom +minor_version=512 +compatible_brands=isomiso6iso2avc1mp41 +encoder=Lavf58.45.100 diff --git a/static/index.html b/resources/mainPage.html similarity index 80% rename from static/index.html rename to resources/mainPage.html index 33f3af8..53f301d 100644 --- a/static/index.html +++ b/resources/mainPage.html @@ -25,11 +25,12 @@

Welcome to SimpleTube

-

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! -
- (Sorry!)

+

SimpleTube is a Youtube client that aims to be free, fast, and javascript free. (and has no ads!)

+ +
+ {RESULTS} +
+

More about the project:

Find this project on codeberg!