OMG ITS FIXED :DDD !!!!

This commit is contained in:
Violet 2023-10-18 20:04:42 -05:00
parent 56835a9221
commit cf43b56572
5 changed files with 51 additions and 57 deletions

2
.gitignore vendored
View file

@ -130,4 +130,4 @@ dist
.pnp.* .pnp.*
# ytdl # ytdl
uploads cached

View file

@ -1,8 +1,9 @@
const { randomInt } = require('crypto');
const ytdl = require('ytdl-core'), const ytdl = require('ytdl-core'),
fs = require('fs'), fs = require('fs'),
path = require('path'), path = require('path'),
express = require('express'), express = require('express'),
ffmpeg = require('fluent-ffmpeg'), ffmpeg = require('ffmpeg'),
bodyParser = require('body-parser') bodyParser = require('body-parser')
const PORT = process.env.PORT || 8080 const PORT = process.env.PORT || 8080
@ -18,7 +19,7 @@ process.on('uncaughtException', (err, origin) => {
app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.urlencoded({ extended: false }))
app.get("/download", (req, res) => { app.get("/download", async (req, res) => {
const filename = req.query.filename const filename = req.query.filename
const url = req.query.url const url = req.query.url
const format = req.query.format const format = req.query.format
@ -29,17 +30,36 @@ app.get("/download", (req, res) => {
return 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
View file

@ -1,17 +1,17 @@
{ {
"name": "youtubeconverter", "name": "youtubeconverter",
"version": "0.2.0", "version": "0.4.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "youtubeconverter", "name": "youtubeconverter",
"version": "0.2.0", "version": "0.4.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"body-parser": "^1.20.2", "body-parser": "^1.20.2",
"express": "^4.18.2", "express": "^4.18.2",
"fluent-ffmpeg": "^2.1.2", "ffmpeg": "^0.0.4",
"ytdl-core": "^4.11.5" "ytdl-core": "^4.11.5"
} }
}, },
@ -32,11 +32,6 @@
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" "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": { "node_modules/body-parser": {
"version": "1.20.2", "version": "1.20.2",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
@ -241,6 +236,14 @@
"node": ">= 0.8" "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": { "node_modules/finalhandler": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz",
@ -258,18 +261,6 @@
"node": ">= 0.8" "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": { "node_modules/forwarded": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -365,11 +356,6 @@
"node": ">= 0.10" "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": { "node_modules/m3u8stream": {
"version": "0.8.6", "version": "0.8.6",
"resolved": "https://registry.npmjs.org/m3u8stream/-/m3u8stream-0.8.6.tgz", "resolved": "https://registry.npmjs.org/m3u8stream/-/m3u8stream-0.8.6.tgz",
@ -675,16 +661,10 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/which": { "node_modules/when": {
"version": "1.3.1", "version": "3.7.8",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", "resolved": "https://registry.npmjs.org/when/-/when-3.7.8.tgz",
"integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", "integrity": "sha512-5cZ7mecD3eYcMiCH4wtRPA5iFJZ50BJYDfckI5RRpQiktMiYTcn0ccLTZOvcbBume+1304fQztxeNzNS9Gvrnw=="
"dependencies": {
"isexe": "^2.0.0"
},
"bin": {
"which": "bin/which"
}
}, },
"node_modules/ytdl-core": { "node_modules/ytdl-core": {
"version": "4.11.5", "version": "4.11.5",

View file

@ -25,7 +25,7 @@
"dependencies": { "dependencies": {
"body-parser": "^1.20.2", "body-parser": "^1.20.2",
"express": "^4.18.2", "express": "^4.18.2",
"fluent-ffmpeg": "^2.1.2", "ffmpeg": "^0.0.4",
"ytdl-core": "^4.11.5" "ytdl-core": "^4.11.5"
} }
} }

View file

@ -29,27 +29,21 @@
<p>Format:</p> <p>Format:</p>
<select required id="format" name="format"> <select required id="format" name="format">
<option disabled>Video Options</option> <option disabled>Video Options</option>
<option value="mp4">.mp4 (*)</option> <option value="mp4">.mp4</option>
<option value="webm">.webm (*)</option> <option value="webm">.webm</option>
<option value="flv">.flv</option> <option value="flv">.flv</option>
<option value="avi">.avi</option> <option value="avi">.avi</option>
<option value="mpeg">.mpeg</option> <option value="mpeg">.mpeg</option>
<option value="mov">.mov</option> <option value="mov">.mov</option>
<option value="mgsts">.mgsts</option>
<option disabled>Audio Options</option> <option disabled>Audio Options</option>
<option value="mp3">.mp3</option> <option value="mp3">.mp3</option>
<option value="wmv">.wmv</option>
<option value="ogg">.ogg</option> <option value="ogg">.ogg</option>
<option value="wav">.wav</option> <option value="wav">.wav</option>
</select> </select>
<input type="submit" placeholder="test"> <input type="submit" placeholder="test">
</form> </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> <hr>
<!-- <p><a>Please consider donating</a> or host the website yourself! (Check github below 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>
<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>
</body> </body>
</html> </html>