I'm creating YouTube video downloader and I'm working with ytdl-core
library and it cannot download high quality videos with audio, because youtube has it in another files, but I need to download it all in one file.
I already did this
app.get('/download', async (req, res, next) => {
const { videoId, format } = req.query;
ytdl.getInfo(videoId)
.then(info => {
const { title } = info.videoDetails;
res.header('Content-Disposition', `attachment; filename=${title}.mp4`);
const streams = {}
if (format === 'video') {
const resolution = req.query.resolution;
const videoFormat = chain(info.formats)
.filter(
format => format.height === +resolution && format.videoCodec?.startsWith('avc1')
)
.orderBy('fps', 'desc')
.head()
.value();
streams.video = ytdl(videoId, {
quality: videoFormat.itag,
format: 'mp4',
});
streams.audio = ytdl(videoId, { quality: 'highestaudio' });
}
});
});