function createSong(path, title, stream, bitrate) { let self = this; let x = new ffmpeg(stream) .audioBitrate(bitrate) .saveToFile(path + title + '.mp3') .on('error', (err) => self.emit('error', err)) .on('end', function() { numVideos--; self.emit('conversion', title); if (!numVideos) { self.emit('finished'); return; } }) }
function downloadMp3({ mp3File, params: { videoId } }, res, next) { if ( mp3File ) { next() } ytdl.getInfo(`http://www.youtube.com/watch?v=${videoId}`, { quality: 'highestaudio' }, function(err, info) { var stream = ytdl.downloadFromInfo(info, { quality: 'highestaudio' }) ffmpeg(stream) .audioBitrate(info.formats[0].audioBitrate) .withAudioCodec("libmp3lame") .toFormat("mp3") .saveToFile(`mp3/${videoId}.mp3`) .on("error", function(err) { console.log('error', err) res.json(err) }) .on("end", function() { next() }) }) }