Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ytdl.getInfo(url, (err, info) => {
if (err) return reject(err);
// Prefer opus
const format = info.formats.find(filter);
const canDemux = format && info.length_seconds != 0;
if (canDemux) options = { ...options, filter };
else if (info.length_seconds != 0) options = { ...options, filter: 'audioonly' };
if (canDemux) {
const demuxer = new prism.opus.WebmDemuxer();
return resolve(ytdl.downloadFromInfo(info, options).pipe(demuxer).on('end', () => demuxer.destroy()));
} else {
const transcoder = new prism.FFmpeg({
args: [
'-reconnect', '1',
'-reconnect_streamed', '1',
'-reconnect_delay_max', '5',
'-i', nextBestFormat(info.formats).url,
'-analyzeduration', '0',
'-loglevel', '0',
'-f', 's16le',
'-ar', '48000',
'-ac', '2',
],
});
const opus = new prism.opus.Encoder({ rate: 48000, channels: 2, frameSize: 960 });
const stream = transcoder.pipe(opus);
stream.on('close', () => {
transcoder.destroy();
playUnknown(input, options) {
this.destroyDispatcher();
const isStream = input instanceof ReadableStream;
const args = isStream ? FFMPEG_ARGUMENTS.slice() : ['-i', input, ...FFMPEG_ARGUMENTS];
if (options.seek) args.unshift('-ss', String(options.seek));
const ffmpeg = new prism.FFmpeg({ args });
const streams = { ffmpeg };
if (isStream) {
streams.input = input;
input.pipe(ffmpeg);
}
return this.playPCMStream(ffmpeg, options, streams);
}