avoid ffmpeg and audio if audio already there
This commit is contained in:
parent
bab9a0ad4c
commit
2aca36295a
8
index.js
8
index.js
|
@ -122,7 +122,7 @@ app.get('/videos/:id', async (req, res) => {
|
||||||
|
|
||||||
app.ws('/download/:id/:quality', async (ws, req) => {
|
app.ws('/download/:id/:quality', async (ws, req) => {
|
||||||
const yt = await Innertube.create();
|
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 = {
|
const videoOptions = {
|
||||||
format: 'mp4',
|
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(`[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 = {
|
const audioOptions = {
|
||||||
type: 'audio',
|
type: 'audio',
|
||||||
quality: 'bestefficiency'
|
quality: 'bestefficiency'
|
||||||
|
@ -186,6 +187,9 @@ app.ws('/download/:id/:quality', async (ws, req) => {
|
||||||
ws.send('Downloaded video and audio. Merging them together.')
|
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`)
|
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}_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`)
|
if (fs.existsSync(`./output/${req.params.id}_video.mp4`)) fs.rmSync(`./output/${req.params.id}_video.mp4`)
|
||||||
|
|
Loading…
Reference in New Issue