Download length header added, fast download back!
This commit is contained in:
parent
66ac5c3a29
commit
23f9cc6e3a
3 changed files with 163 additions and 124 deletions
18
index.js
18
index.js
|
@ -50,7 +50,19 @@ app.get("/getLink", async (req, res) => {
|
|||
res.write(`<p>Invalid URL! Check the url for any errors! <br> ${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
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (redir != "redirect") {
|
||||
res.setHeader("Content-Type", "text/html");
|
||||
|
||||
|
@ -166,6 +178,7 @@ app.get("/getLink", async (req, res) => {
|
|||
}
|
||||
update()
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/download', (req, res) => {
|
||||
|
@ -174,7 +187,8 @@ app.get('/download', (req, res) => {
|
|||
var dest = path.join(__dirname, 'cached/', file)
|
||||
|
||||
if (fs.existsSync(dest)) {
|
||||
res.header('Content-Disposition', `attachment; filename="${filename}"`);
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
|
||||
res.setHeader('Content-Length', fs.readFileSync(dest).length)
|
||||
fs.createReadStream(dest).pipe(res)
|
||||
} else {
|
||||
res.header("Content-Type", "text/html")
|
||||
|
|
|
@ -12,25 +12,33 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Youtube Downloader <p>v2.1</p>
|
||||
<h1>Youtube Downloader <p>v2.2</p>
|
||||
<hr>
|
||||
</h1>
|
||||
|
||||
<form action="/getLink" method="get" target="_blank">
|
||||
<div class="setting">
|
||||
<p style="margin-bottom: 1px;">Video URL:</p>
|
||||
<input required id="url" placeholder="Enter url" name="url">
|
||||
</div>
|
||||
|
||||
<div class="setting">
|
||||
<p>Quality:</p>
|
||||
<select required id="quality" name="quality">
|
||||
<option value="highest">Highest</option>
|
||||
<option value="lowest">Lowest</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="setting">
|
||||
<p>Filename:</p>
|
||||
<input required id="filename" placeholder="Enter filename" name="filename"><br>
|
||||
<input required id="filename" placeholder="Enter filename" name="filename">
|
||||
</div>
|
||||
<div class="setting">
|
||||
<p>Format:</p>
|
||||
<select required id="format" name="format">
|
||||
<option disabled>Video Options</option>
|
||||
<option value="mp4">.mp4</option>
|
||||
<option value="webm">.webm</option>
|
||||
<option value="mp4" class="tooltip1">.mp4 (fastest)</option>
|
||||
<option value="webm" class="tooltip1">.webm (fastest)</option>
|
||||
<option value="flv">.flv</option>
|
||||
<option value="avi">.avi</option>
|
||||
<option value="mpeg">.mpeg</option>
|
||||
|
@ -40,20 +48,22 @@
|
|||
<option value="ogg">.ogg</option>
|
||||
<option value="wav">.wav</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- <p class="note">* When using mp4 and webm, progress updates and redirect options are disabled, as it is directly downloaded to the browser.</p> -->
|
||||
<div class="setting">
|
||||
<p>Redirect:</p>
|
||||
<select required id="redirect" name="redirect">
|
||||
<option value="false">Don't redirect</option>
|
||||
<option value="redirectjs">Redirect (JS) *1</option>
|
||||
<option value="redirect">Redirect (disable progress) *2</option>
|
||||
<option value="redirectjs">Redirect (JS, reccomended)</option>
|
||||
<option value="false">Don't auto redirect</option>
|
||||
<option value="redirect">Redirect (disables progress, not reccomended)</option>
|
||||
</select>
|
||||
</div>
|
||||
<br>
|
||||
<input type="submit" placeholder="test">
|
||||
<input type="submit">
|
||||
</form>
|
||||
<hr>
|
||||
<p>*1: The "Redirect JS" Option is the same as the "Don't redirect" option, except it sends javascript to the browser letting you redirect. BOTH OPTIONS WORK FINE WITHOUT JAVASCRIPT!</p>
|
||||
<p>*2: The "Redirect (disable progress)" option doesn't use any javascript and automatically redirects to the download, but you are not given download progress updates!</p>
|
||||
<hr>
|
||||
<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>
|
||||
<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>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -24,6 +24,7 @@ input {
|
|||
|
||||
p {
|
||||
margin: 5px;
|
||||
display: inline-block
|
||||
}
|
||||
|
||||
body,
|
||||
|
@ -31,6 +32,10 @@ html {
|
|||
background-color: var(--background-color);
|
||||
}
|
||||
|
||||
/* body {
|
||||
padding: 20px;
|
||||
} */
|
||||
|
||||
.grid-container {
|
||||
width: 100%;
|
||||
margin: auto;
|
||||
|
@ -38,7 +43,7 @@ html {
|
|||
|
||||
select,
|
||||
input {
|
||||
display: inline-grid;
|
||||
display: inline-block;
|
||||
background-color: var(--second-bg-color);
|
||||
color: var(--text-color);
|
||||
margin: 5px auto;
|
||||
|
@ -64,3 +69,13 @@ label {
|
|||
hr {
|
||||
opacity: 0.3;
|
||||
}
|
||||
|
||||
.note {
|
||||
font-size: 1.1rem;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.setting {
|
||||
display: block;
|
||||
margin: 5px;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue