diff --git a/index.js b/index.js index fc8d61b..3714b0c 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,18 @@ if (fs.existsSync(path.join(__dirname, 'cached'))) { fs.rmSync(path.join(__dirname, 'cached'), { recursive: true, force: true}) } +function formatBytes(bytes, decimals = 2) { + if (!+bytes) return '0 Bytes' + + const k = 1024 + const dm = decimals < 0 ? 0 : decimals + const sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] + + const i = Math.floor(Math.log(bytes) / Math.log(k)) + + return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}` +} + fs.mkdirSync(path.join(__dirname, 'cached')) const cacheDuration = 15 || process.env.CACHEDUR @@ -53,7 +65,7 @@ app.get("/getLink", async (req, res) => { var integer = 1 var percent = (Math.ceil(ctotal / etotal * 100)) if (percent % integer == 0 && lastp != percent) { - res.write(`

Downloading... ${percent}%

`) + res.write(`

Downloading... ${percent}% (${formatBytes(ctotal)})

`) res.write(` + `) res.write(`

Link to video download! (Link is deleted after 15 minutes!)

`) setTimeout(()=>{ if (fs.existsSync(ytpath)) { @@ -89,30 +108,33 @@ app.get("/getLink", async (req, res) => { }) }) + var count = 0 var integer = 1 - var lastc = 0 + var lastc = -1 var percent = 0 async function update() { if (fs.existsSync(endpath)) { var ffile = await fs.readFileSync(endpath) var yt = await fs.readFileSync(ytpath) percent = (Math.round(ffile.length / yt.length * (100 / integer))) * integer - if (percent % integer == 0 && percent != lastc) { - res.write(`

Converting... ${Math.min(percent, 100)}% (Potentially Innacurate, Experimental!)

`) + // console.log(ffile.length) + // if (ffile.length != lastc) { + res.write(`

Converting... (${formatBytes(ffile.length)})

`) res.write(` `) lastc = percent - } + count += 1 + // } } if (percent < 100) { setTimeout(() => { update() - }, 500); + }, 1500); } } update() diff --git a/static/index.html b/static/index.html index bfc7347..1fb3988 100644 --- a/static/index.html +++ b/static/index.html @@ -43,6 +43,7 @@
+

Videos over a certain size may fail to download!

Currently video quality may not be too high, due to formats above 720p having seperated audio tracks. This is being worked on!

Please consider donating or host the website yourself! Anything helps! (Check github for more info)