Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3638

Audio greater than 6 Mb not getting transferred with ytdl-core

$
0
0

The following function downloads an audio from YouTube video, everything works fine on local host but when I tried to deploy it on sites like Vercel and Cyclic audios of large sizes does not gets downloaded instead returns an internal server error. On further investigation it was found that the platforms that support this deployment do not transfer any payload to client side larger than 6 MB. Is their any way to work around it so that even audios larger than 6Mb gets transferred??

const downloadAudio = async(videoUrl, res) => {      const videoInfo = await ytdl.getInfo(videoUrl);      const audioFormat = ytdl.chooseFormat(videoInfo.formats, { filter: 'audioonly' });      const audioStream = ytdl(videoUrl, { format: audioFormat });      const filename = "output.mp3";      res.set('Content-Type', 'audio/mpeg');      res.set('Content-Disposition', `attachment; filename="${filename}"`);      audioStream.on('data', (chunk) => {        res.write(chunk);      });      audioStream.on('end', () => {        res.end();      });      audioStream.on('error', (err) => {        console.error(err);        res.status(500).send('An error occurred while streaming audio.');      });    };

Viewing all articles
Browse latest Browse all 3638

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>