Removed %s from Conversion, now shows data

This commit is contained in:
Violet 2023-10-23 15:57:35 +00:00
parent 7ab532c8c6
commit 66ff3d80d2
2 changed files with 32 additions and 9 deletions

View file

@ -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(`<p id="percent${percent}">Downloading... ${percent}%</p>`)
res.write(`<p class="percent" id="percent${percent}">Downloading... ${percent}% (${formatBytes(ctotal)})</p>`)
res.write(`
<style>
#percent${lastp} {
@ -70,13 +82,20 @@ app.get("/getLink", async (req, res) => {
var proc = new ffmpeg(ytpath)
// res.write(`<p>Converting... (May take a while, <a href="https://github.com/Violets-puragtory/NoJS-YTConverter"> doesn't support progress updates yet</a>)</p>`)
var endpath = ('cached/' + ytdl.getVideoID(url) + String(Math.floor(Math.random() * 100000)) + "Converted." + format)
res.write(`<p id="convert${0}">Converting... 0% (Potentially Innacurate, Experimental!)</p>`)
// res.write(`<p id="convert${0}">Converting... 0% (Potentially Innacurate, Experimental!)</p>`)
proc.then(function (video) {
video
.setVideoDuration(vidinfo.videoDetails.lengthSeconds)
.setVideoFormat(format)
.save(endpath, (error, file)=>{
res.write("<p>Converted!</p>")
res.write(`<p>Converted! (<a href="https://github.com/damianociarla/node-ffmpeg/issues/33">Why doesn't conversion support %s?</a>)</p>`)
res.write(`
<style>
.cv {
display: none;
}
</style>
`)
res.write(`<p><a href="/download?path=${path.basename(file)}&filename=${filename}.${format}" target="_blank">Link to video download!</a> (Link is deleted after 15 minutes!)</p>`)
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(`<p id="convert${percent}">Converting... ${Math.min(percent, 100)}% (Potentially Innacurate, Experimental!)</p>`)
// console.log(ffile.length)
// if (ffile.length != lastc) {
res.write(`<p class="cv" id="convert${count}">Converting... (${formatBytes(ffile.length)})</p>`)
res.write(`
<style>
#convert${lastc} {
#convert${count - 1} {
display: none;
}
</style>
`)
lastc = percent
}
count += 1
// }
}
if (percent < 100) {
setTimeout(() => {
update()
}, 500);
}, 1500);
}
}
update()

View file

@ -43,6 +43,7 @@
<input type="submit" placeholder="test">
</form>
<hr>
<p>Videos over a certain size may fail to download!</p>
<p>Currently video quality may not be too high, due to formats above 720p having seperated audio tracks. This is being worked on!</p>
<p><a href="https://ko-fi.com/bingus_violet">Please consider donating</a> or host the website yourself! Anything helps! (Check <a href="https://github.com/Violets-puragtory/NoJS-YTConverter">github</a> for more info)</p><br>
</body>