Fixed block and other things
This commit is contained in:
parent
f1a07dff8f
commit
ab698f112b
2 changed files with 20 additions and 19 deletions
37
index.js
37
index.js
|
@ -47,26 +47,33 @@ app.get("/getLink", async (req, res) => {
|
|||
if (!ytdl.validateURL(url)) {
|
||||
res.header("Content-Type", "text/html")
|
||||
res.write(`<link rel="stylesheet" href="/style.css">`)
|
||||
res.write(`<p>Invalid URL! Check the url for any errors! <br> ${url}</p>`)
|
||||
res.write(`<p>Invalid URL! Check the url for any errors! <br>URL: ${url}</p>`)
|
||||
return
|
||||
}
|
||||
if (["mp4", "webm"].includes(format)) {
|
||||
var ytvid = ytdl(url, { 'quality': quality, 'format': format })
|
||||
var debounce = false
|
||||
ytvid.on("progress", (chunk, cd, td) => {
|
||||
if (!debounce) {
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${filename}.${format}";`);
|
||||
res.setHeader("Content-Length", td)
|
||||
ytvid.pipe(res)
|
||||
// console.log(td)
|
||||
debounce = true
|
||||
}
|
||||
})
|
||||
ytvid.on("progress", (chunk, cd, td) => {
|
||||
if (!debounce) {
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${filename}.${format}";`);
|
||||
res.setHeader("Content-Length", td)
|
||||
ytvid.pipe(res)
|
||||
// console.log(td)
|
||||
debounce = true
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (redir != "redirect") {
|
||||
res.setHeader("Content-Type", "text/html");
|
||||
|
||||
res.write(`<link rel="stylesheet" href="/style.css">`)
|
||||
res.write(`
|
||||
<style>
|
||||
p {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
`)
|
||||
}
|
||||
|
||||
|
||||
|
@ -148,16 +155,11 @@ app.get("/getLink", async (req, res) => {
|
|||
})
|
||||
|
||||
var count = 0
|
||||
var integer = 1
|
||||
var lastc = 0
|
||||
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
|
||||
// console.log(ffile.length)
|
||||
// if (ffile.length != lastc) {
|
||||
res.write(`<p class="cv" id="convert${count}">Converting... (${formatBytes(ffile.length)})</p>`)
|
||||
res.write(`
|
||||
<style>
|
||||
|
@ -166,11 +168,10 @@ app.get("/getLink", async (req, res) => {
|
|||
}
|
||||
</style>
|
||||
`)
|
||||
lastc = percent
|
||||
count += 1
|
||||
// }
|
||||
}
|
||||
if (percent < 100 && redir != "redirect") {
|
||||
if ( redir != "redirect") {
|
||||
setTimeout(() => {
|
||||
update()
|
||||
}, 2000);
|
||||
|
|
|
@ -24,7 +24,7 @@ input {
|
|||
|
||||
p {
|
||||
margin: 5px;
|
||||
display: inline-block
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
body,
|
||||
|
|
Loading…
Reference in a new issue