avoid ffmpeg and audio if audio already there

This commit is contained in:
localhost 2025-01-17 16:15:02 +01:00
parent bab9a0ad4c
commit 2aca36295a
1 changed files with 36 additions and 32 deletions

View File

@ -122,7 +122,7 @@ app.get('/videos/:id', async (req, res) => {
app.ws('/download/:id/:quality', async (ws, req) => {
const yt = await Innertube.create();
const info = await yt.getInfo(req.params.id, 'ANDROID');
const info = await yt.getInfo(req.params.id, 'WEB_EMBEDDED');
const videoOptions = {
format: 'mp4',
@ -153,8 +153,9 @@ app.ws('/download/:id/:quality', async (ws, req) => {
ws.send(`[video] ${(progress * 100).toFixed(2)}% of ${hr.fromBytes(videoTotal)} at ${speedInMBps.toFixed(2)} MB/s ETA ${secondsToTime(remainingTime.toFixed(0))}`)
}
ws.send('The video has been downloaded. Downloading the audio.')
ws.send(`The video has been downloaded. ${!videoFormat.has_audio ? ' Downloading the audio.' : ''}`)
if (!videoFormat.has_audio) {
const audioOptions = {
type: 'audio',
quality: 'bestefficiency'
@ -186,6 +187,9 @@ app.ws('/download/:id/:quality', async (ws, req) => {
ws.send('Downloaded video and audio. Merging them together.')
await mergeIt(`./output/${req.params.id}_audio.mp4`, `./output/${req.params.id}_video.mp4`, `./output/${req.params.id}.mp4`)
} else {
fs.renameSync(`./output/${req.params.id}_video.mp4`, `./output/${req.params.id}.mp4`)
}
if (fs.existsSync(`./output/${req.params.id}_audio.mp4`)) fs.rmSync(`./output/${req.params.id}_audio.mp4`)
if (fs.existsSync(`./output/${req.params.id}_video.mp4`)) fs.rmSync(`./output/${req.params.id}_video.mp4`)