diff --git a/index.js b/index.js index c55182a..a511f1d 100644 --- a/index.js +++ b/index.js @@ -61,6 +61,53 @@ app.listen(PORT, () => { console.log("Simpletube is now listening on port: " + PORT) }) +function resultHTML(result) { + + console.log(result) + + function thumbnailCheck() { + if (result.thumbnails) { + return result.thumbnails[0].url + } else { + return result.thumbnail + } + } + + function publishCheck() { + if (result.published) { + return result.published.text + } else { + return result.uploaded + } + } + + return ` +
Failed to load.
" } @@ -389,7 +400,9 @@ app.get("/video", async (req, res) => { if (range) { function ready(vidpath) { if (fs.existsSync(vidpath)) { - const fileSize = videoCache[id].size + // const fileSize = videoCache[id].size + 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] @@ -411,9 +424,7 @@ app.get("/video", async (req, res) => { res.writeHead(206, head) - if (fs.existsSync(vidpath)) { - fs.createReadStream(vidpath, { start: start }).pipe(res) - } + fs.createReadStream(vidpath, { start: start, end: end }).pipe(res) } } @@ -424,7 +435,7 @@ app.get("/video", async (req, res) => { videoCache[id].lastUsed = Date.now() } } else { - videoCache[id] = [] + videoCache[id + quality] = [] cacher(id, quality, ready) } @@ -456,7 +467,7 @@ app.get("/video", async (req, res) => { app.get("/watch", async (req, res) => { var id = req.query.q || req.query.v || "ubFq-wV3Eic" - var quality = req.query.quality || "sd" + var quality = req.query.quality || "hd" res.setHeader("Content-Type", "text/html") @@ -482,8 +493,6 @@ app.get("/watch", async (req, res) => { } - - var html = fs.readFileSync(playerPath).toString() if (quality == "sd") { @@ -508,14 +517,14 @@ app.get("/watch", async (req, res) => { } html = html.replace("{VIDEO_DESCRIPTION}", vidInfo.description || "No Description.") - - if (!(id in videoCache && videoCache[id]["downloaded"] == true)) { + console.log(videoCache) + if (!((id + quality) in videoCache && videoCache[id + quality].downloaded == true)) { html = html.replace("{CACHE_WARNING}", `Please note that this video has not been fully cached, and may have trouble loading!
{DOWNLOAD_PERCENT}% cached as of page load. If content fails to load after a minute, reload the page!