Fix SD mp4s

This commit is contained in:
Bingus_Violet 2024-01-07 16:37:37 -06:00
parent d7edce0c95
commit ad0e0ff1e6

View file

@ -23,13 +23,13 @@ var uploads = multer({ dest: 'uploads/' })
const characters = "abcdefghijklmnopqrstuvwxyz!@$%^*()[]_-=+ " const characters = "abcdefghijklmnopqrstuvwxyz!@$%^*()[]_-=+ "
process.on('uncaughtException', (err, origin) => { // process.on('uncaughtException', (err, origin) => {
fs.writeSync( // fs.writeSync(
process.stderr.fd, // process.stderr.fd,
`Caught exception: ${err}\n` + // `Caught exception: ${err}\n` +
`Exception origin: ${origin}`, // `Exception origin: ${origin}`,
); // );
}); // });
app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.urlencoded({ extended: false }))
@ -139,7 +139,8 @@ app.get("/download", async (req, res) => {
ffmpegProcess.stdio[1].pipe(res) ffmpegProcess.stdio[1].pipe(res)
} else { } else {
var video = ytdl(url, { filter: 'videoandaudio', quality: quality }) if (format != 'mp4') {
var video = ytdl(url, { filter: 'videoandaudio', quality: quality, highWaterMark: 1 << 25 })
const ffmpegProcess = cp.spawn(ffmpeg, [ const ffmpegProcess = cp.spawn(ffmpeg, [
'-i', `pipe:3`, '-i', `pipe:3`,
@ -159,6 +160,11 @@ app.get("/download", async (req, res) => {
// res.setHeader('Content-Length', fs.readFileSync(dest).length) // res.setHeader('Content-Length', fs.readFileSync(dest).length)
ffmpegProcess.stdio[1].pipe(res) ffmpegProcess.stdio[1].pipe(res)
} else {
var video = ytdl(url, { filter: 'videoandaudio', quality: quality, highWaterMark: 1 << 25 })
res.setHeader('Content-Disposition', `attachment; filename="${filename}.${formats[format] || format}"`);
video.pipe(res)
}
} }
}) })