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}) 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')) fs.mkdirSync(path.join(__dirname, 'cached'))
const cacheDuration = 15 || process.env.CACHEDUR const cacheDuration = 15 || process.env.CACHEDUR
@ -53,7 +65,7 @@ app.get("/getLink", async (req, res) => {
var integer = 1 var integer = 1
var percent = (Math.ceil(ctotal / etotal * 100)) var percent = (Math.ceil(ctotal / etotal * 100))
if (percent % integer == 0 && lastp != percent) { 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(` res.write(`
<style> <style>
#percent${lastp} { #percent${lastp} {
@ -70,13 +82,20 @@ app.get("/getLink", async (req, res) => {
var proc = new ffmpeg(ytpath) 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>`) // 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) 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) { proc.then(function (video) {
video video
.setVideoDuration(vidinfo.videoDetails.lengthSeconds) .setVideoDuration(vidinfo.videoDetails.lengthSeconds)
.setVideoFormat(format) .setVideoFormat(format)
.save(endpath, (error, file)=>{ .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>`) 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(()=>{ setTimeout(()=>{
if (fs.existsSync(ytpath)) { if (fs.existsSync(ytpath)) {
@ -89,30 +108,33 @@ app.get("/getLink", async (req, res) => {
}) })
}) })
var count = 0
var integer = 1 var integer = 1
var lastc = 0 var lastc = -1
var percent = 0 var percent = 0
async function update() { async function update() {
if (fs.existsSync(endpath)) { if (fs.existsSync(endpath)) {
var ffile = await fs.readFileSync(endpath) var ffile = await fs.readFileSync(endpath)
var yt = await fs.readFileSync(ytpath) var yt = await fs.readFileSync(ytpath)
percent = (Math.round(ffile.length / yt.length * (100 / integer))) * integer percent = (Math.round(ffile.length / yt.length * (100 / integer))) * integer
if (percent % integer == 0 && percent != lastc) { // console.log(ffile.length)
res.write(`<p id="convert${percent}">Converting... ${Math.min(percent, 100)}% (Potentially Innacurate, Experimental!)</p>`) // if (ffile.length != lastc) {
res.write(`<p class="cv" id="convert${count}">Converting... (${formatBytes(ffile.length)})</p>`)
res.write(` res.write(`
<style> <style>
#convert${lastc} { #convert${count - 1} {
display: none; display: none;
} }
</style> </style>
`) `)
lastc = percent lastc = percent
} count += 1
// }
} }
if (percent < 100) { if (percent < 100) {
setTimeout(() => { setTimeout(() => {
update() update()
}, 500); }, 1500);
} }
} }
update() update()

View file

@ -43,6 +43,7 @@
<input type="submit" placeholder="test"> <input type="submit" placeholder="test">
</form> </form>
<hr> <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>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> <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> </body>