fent / node-ytdl-core

YouTube video downloader in javascript.
MIT License
4.52k stars 799 forks source link

Error if formats.some(fmt => fmt.isHLS) #1191

Open D3atHpR opened 1 year ago

D3atHpR commented 1 year ago

I'm using the latest version of ytdl-core My goal is to download the video and transform it into mp3 and send it, I'm using a whatsapp library but it's working perfectly what's giving me the problem is in fact the ytdl-core

I used several checks and logs to verify the error but it still falls straight into the error

if (message.body.startsWith('/yt ')) {

    console.log(formats); // Imprime o valor de formats
    if (Array.isArray(formats)) {
      if (formats.some(fmt => fmt.isHLS)) {
        const videoUrl = message.body.slice(4);
        const videoId = ytdl.getURLVideoID(videoUrl);
        console.log(`videoId: ${videoId}`); // Imprime o valor de videoId
        const info = await ytdl.getInfo(videoId);
        console.log(info); // Imprime o valor de retorno de ytdl.getInfo(videoId)
        if (Array.isArray(info.formats)) {
          const audioFormat = ytdl.chooseFormat(info.formats, { quality: 'highestaudio' });
          const audioFile = fs.createWriteStream('audio.mp3');
          await ytdl(videoUrl, { format: audioFormat })
            .pipe(audioFile);
          audioFile.on('finish', () => {
            message.reply(new MessageMedia('audio/mp3', fs.readFileSync('audio.mp3')));
            console.log('Sent audio file');
          });
        } else {
          console.error('info.formats is not an array');
        }
      }
    } else {
      console.error('formats is not an array');
    }
  }

image This is the error displayed

TimeForANinja commented 1 year ago

ok, that doesn't look right a) what did the console.log(info); / console.log(info.formats); show? b) the line 12 of the code you send is the line throwing the error, i suspect? c) if you simplify the code as much as possible (e.g. static id, moving to global context...) does it still occur?

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.