OMG ITS FIXED :DDD !!!!
This commit is contained in:
parent
56835a9221
commit
cf43b56572
5 changed files with 51 additions and 57 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -130,4 +130,4 @@ dist
|
|||
.pnp.*
|
||||
|
||||
# ytdl
|
||||
uploads
|
||||
cached
|
42
index.js
42
index.js
|
@ -1,8 +1,9 @@
|
|||
const { randomInt } = require('crypto');
|
||||
const ytdl = require('ytdl-core'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
express = require('express'),
|
||||
ffmpeg = require('fluent-ffmpeg'),
|
||||
ffmpeg = require('ffmpeg'),
|
||||
bodyParser = require('body-parser')
|
||||
|
||||
const PORT = process.env.PORT || 8080
|
||||
|
@ -18,7 +19,7 @@ process.on('uncaughtException', (err, origin) => {
|
|||
|
||||
app.use(bodyParser.urlencoded({ extended: false }))
|
||||
|
||||
app.get("/download", (req, res) => {
|
||||
app.get("/download", async (req, res) => {
|
||||
const filename = req.query.filename
|
||||
const url = req.query.url
|
||||
const format = req.query.format
|
||||
|
@ -29,17 +30,36 @@ app.get("/download", (req, res) => {
|
|||
return
|
||||
}
|
||||
|
||||
if (format != "mp4" && format != "webm") {
|
||||
res.header('Content-Disposition', `attachment; filename="${filename}.${format};"`);
|
||||
res.header('Content-Disposition', `attachment; filename="${filename}.${format}"`);
|
||||
|
||||
var ytpath = path.join(__dirname, 'cached/' + ytdl.getVideoID(url) + String(Math.floor(Math.random() * 100000)) + '.mp4')
|
||||
|
||||
var vidinfo = await ytdl.getBasicInfo(url)
|
||||
|
||||
var ytvid = ytdl(url, { 'quality': quality })
|
||||
.pipe(fs.createWriteStream(ytpath))
|
||||
.on("close", ()=> {
|
||||
console.log("Downloaded!")
|
||||
var proc = new ffmpeg(ytpath)
|
||||
proc.then(function(video) {
|
||||
video
|
||||
.setVideoDuration(vidinfo.videoDetails.lengthSeconds)
|
||||
.setVideoFormat(format)
|
||||
.save('cached/' + ytdl.getVideoID(url) + String(Math.floor(Math.random() * 100000)) + "Converted." + format,function (err, file) {
|
||||
console.log("Converted!")
|
||||
fs.createReadStream(file).pipe(res)
|
||||
.on("close", () => {
|
||||
console.log("Freed!")
|
||||
fs.unlinkSync(file)
|
||||
if (fs.existsSync(ytpath)) {
|
||||
fs.unlinkSync(ytpath)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
var proc = new ffmpeg({ source: ytdl(url, { 'quality': quality }) })
|
||||
.format(format)
|
||||
.pipe(res)
|
||||
|
||||
} else {
|
||||
res.header('Content-Disposition', `attachment; filename="${filename}.${format}"`);
|
||||
ytdl(url, { 'format': format, 'quality': quality }).pipe(res);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
|
50
package-lock.json
generated
50
package-lock.json
generated
|
@ -1,17 +1,17 @@
|
|||
{
|
||||
"name": "youtubeconverter",
|
||||
"version": "0.2.0",
|
||||
"version": "0.4.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "youtubeconverter",
|
||||
"version": "0.2.0",
|
||||
"version": "0.4.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.20.2",
|
||||
"express": "^4.18.2",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
"ffmpeg": "^0.0.4",
|
||||
"ytdl-core": "^4.11.5"
|
||||
}
|
||||
},
|
||||
|
@ -32,11 +32,6 @@
|
|||
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg=="
|
||||
},
|
||||
"node_modules/async": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz",
|
||||
"integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ=="
|
||||
},
|
||||
"node_modules/body-parser": {
|
||||
"version": "1.20.2",
|
||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
|
||||
|
@ -241,6 +236,14 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/ffmpeg": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/ffmpeg/-/ffmpeg-0.0.4.tgz",
|
||||
"integrity": "sha512-3TgWUJJlZGQn+crJFyhsO/oNeRRnGTy6GhgS98oUCIfZrOW5haPPV7DUfOm3xJcHr5q3TJpjk2GudPutrNisRA==",
|
||||
"dependencies": {
|
||||
"when": ">= 0.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/finalhandler": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz",
|
||||
|
@ -258,18 +261,6 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/fluent-ffmpeg": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/fluent-ffmpeg/-/fluent-ffmpeg-2.1.2.tgz",
|
||||
"integrity": "sha512-IZTB4kq5GK0DPp7sGQ0q/BWurGHffRtQQwVkiqDgeO6wYJLLV5ZhgNOQ65loZxxuPMKZKZcICCUnaGtlxBiR0Q==",
|
||||
"dependencies": {
|
||||
"async": ">=0.2.9",
|
||||
"which": "^1.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/forwarded": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||
|
@ -365,11 +356,6 @@
|
|||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/isexe": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="
|
||||
},
|
||||
"node_modules/m3u8stream": {
|
||||
"version": "0.8.6",
|
||||
"resolved": "https://registry.npmjs.org/m3u8stream/-/m3u8stream-0.8.6.tgz",
|
||||
|
@ -675,16 +661,10 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/which": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
|
||||
"integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
|
||||
"dependencies": {
|
||||
"isexe": "^2.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"which": "bin/which"
|
||||
}
|
||||
"node_modules/when": {
|
||||
"version": "3.7.8",
|
||||
"resolved": "https://registry.npmjs.org/when/-/when-3.7.8.tgz",
|
||||
"integrity": "sha512-5cZ7mecD3eYcMiCH4wtRPA5iFJZ50BJYDfckI5RRpQiktMiYTcn0ccLTZOvcbBume+1304fQztxeNzNS9Gvrnw=="
|
||||
},
|
||||
"node_modules/ytdl-core": {
|
||||
"version": "4.11.5",
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
"dependencies": {
|
||||
"body-parser": "^1.20.2",
|
||||
"express": "^4.18.2",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
"ffmpeg": "^0.0.4",
|
||||
"ytdl-core": "^4.11.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,27 +29,21 @@
|
|||
<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">.mp4</option>
|
||||
<option value="webm">.webm</option>
|
||||
<option value="flv">.flv</option>
|
||||
<option value="avi">.avi</option>
|
||||
<option value="mpeg">.mpeg</option>
|
||||
<option value="mov">.mov</option>
|
||||
<option value="mgsts">.mgsts</option>
|
||||
<option disabled>Audio Options</option>
|
||||
<option value="mp3">.mp3</option>
|
||||
<option value="wmv">.wmv</option>
|
||||
<option value="ogg">.ogg</option>
|
||||
<option value="wav">.wav</option>
|
||||
</select>
|
||||
<input type="submit" placeholder="test">
|
||||
</form>
|
||||
<p>* using mp4s or webms is highly reccomended, as those are the default formats for youtube. <br>Any other format will require converting the video, slowing download speed.</p>
|
||||
<hr>
|
||||
<!-- <p><a>Please consider donating</a> or host the website yourself! (Check github below for more info)</p><br> -->
|
||||
<p>Please consider hosting the project yourself! (Check github for more details)</p>
|
||||
<p>Check out the <a id="github" href="https://github.com/Violets-puragtory/YoutubeConverter">Github page</a> to
|
||||
learn how to host it yourself, how it works, report bugs, and more.</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>
|
||||
|
||||
</html>
|
Loading…
Reference in a new issue