Fix non ogx formats

This commit is contained in:
Bingus_Violet 2024-02-01 18:54:38 -06:00
parent f236ecb9dd
commit ad1d3996b9
2 changed files with 12 additions and 20 deletions

View file

@ -14,6 +14,8 @@ var formats = {
"mkv": "matroska"
}
var fastFormats = ["mp4", "mkv", "mp3", "wav"]
app.get("/convert", async (req, res) => {
var file = req.query.file || ""
var format = req.query.format
@ -26,17 +28,6 @@ app.get("/convert", async (req, res) => {
var name = ytdlpProcess.stdout.toString()
name = name.substring(0, name.lastIndexOf("[") - 1)
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(name)}.${format}"`);
const ffmpegProcess = cp.spawn(ffmpeg, [
'-i', filePath,
'-f', formats[format] || format,
'-movflags', 'frag_keyframe+empty_moov',
'-c', 'copy',
'-'
], {
stdio: [
'pipe', 'pipe', 'pipe', 'pipe', 'pipe',
],
})
// ffmpegProcess.stderr.setEncoding('utf-8')
// ffmpegProcess.stderr.on('data', (data) => {
@ -140,7 +131,7 @@ app.get("/download", async (req, res) => {
}
exited = true
})
} else if (["mp3", "wav", "ogx"].includes(format)) {
} else if (["mp3", "wav", "opus"].includes(format)) {
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(videoName)}.${format}"`);
var ytdlpProcess = cp.spawn('yt-dlp', [
@ -156,7 +147,6 @@ app.get("/download", async (req, res) => {
'-i', 'pipe:3',
'-f', formats[format] || format,
'-movflags', 'frag_keyframe+empty_moov',
'-c:a', 'libmp3lame',
'-preset','ultrafast',
'-crf', '23',
'-loglevel', 'error',
@ -213,6 +203,14 @@ app.get("/download", async (req, res) => {
})
process.on('uncaughtException', (err, origin) => {
fs.writeSync(
process.stderr.fd,
`Caught exception: ${err}\n` +
`Exception origin: ${origin}`,
);
});
app.use(express.static(path.join(__dirname, 'static')))
app.listen(PORT, function () {