Fix SD mp4s
This commit is contained in:
parent
d7edce0c95
commit
ad0e0ff1e6
1 changed files with 32 additions and 26 deletions
52
index.js
52
index.js
|
@ -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,26 +139,32 @@ 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`,
|
||||||
'-preset', preset,
|
'-preset', preset,
|
||||||
'-f', format,
|
'-f', format,
|
||||||
'-loglevel', 'error',
|
'-loglevel', 'error',
|
||||||
'-'
|
'-'
|
||||||
], {
|
], {
|
||||||
stdio: [
|
stdio: [
|
||||||
'pipe', 'pipe', 'pipe', 'pipe', 'pipe',
|
'pipe', 'pipe', 'pipe', 'pipe', 'pipe',
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
video.pipe(ffmpegProcess.stdio[3])
|
video.pipe(ffmpegProcess.stdio[3])
|
||||||
|
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="${filename}.${formats[format] || format}"`);
|
res.setHeader('Content-Disposition', `attachment; filename="${filename}.${formats[format] || format}"`);
|
||||||
// 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue