Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to receive video metadata for some random videos #774

Closed
AMDBartek opened this issue Nov 15, 2020 · 2 comments
Closed

Unable to receive video metadata for some random videos #774

AMDBartek opened this issue Nov 15, 2020 · 2 comments
Labels

Comments

@AMDBartek
Copy link

AMDBartek commented Nov 15, 2020

I have a Discord music bot and one of my friends tried to play this video (warning, it is loud): https://youtu.be/ihmDR7W1P1o and it threw an error (sometimes there is no error at all but it still doesn’t play), this does not happen in 3.4.2 however it does happen with version 4 and above.

The audio part of my code:

client.on("message", message => {
    
  var ismusicCommand = message.content.toLowerCase().startsWith(config.prefix + "play") || message.content.toLowerCase().startsWith(config.prefix + "skip") || message.content.toLowerCase().startsWith(config.prefix + "stop");
    
  if (message.author.bot) return;
  
  if (!message.channel.guild) {
      if (ismusicCommand == true) {
      message.react("723607808255197244");
      message.channel.send("Music functionality can only be used while in a guild!");
    return;
      }
      return;
  }

  const serverQueue = queue.get(message.guild.id);

  if (message.content.toLowerCase().startsWith(config.prefix + `play`)) {
    message.react("723607808062390363");
    execute(message, serverQueue);
    return;
  } else if (message.content.toLowerCase().startsWith(config.prefix + `skip`)) {
    message.react("723607808062390363");
    skip(message, serverQueue);
    return;
  } else if (message.content.toLowerCase().startsWith(config.prefix + `stop`)) {
    message.react("723607808062390363");
    stop(message, serverQueue);
    return;
  }
});

async function execute(message, serverQueue) {
  const args = message.content.split(" ");

  const voiceChannel = message.member.voice.channel;
  if (!voiceChannel)
    return message.channel.send("You need to be in a voice channel to play audio!");
  const permissions = voiceChannel.permissionsFor(message.client.user);
  if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
    return message.channel.send("I need the permissions to join and play audio in your voice channel!");
  }

  const songInfo = await ytdl.getInfo(args[1]);
  const song = {
    title: songInfo.videoDetails.title,
    author: songInfo.videoDetails.author.name,
    url: songInfo.videoDetails.video_url
  };

  if (!serverQueue) {
    const queueContruct = {
      textChannel: message.channel,
      voiceChannel: voiceChannel,
      connection: null,
      songs: [],
      volume: 5,
      playing: true
    };

    queue.set(message.guild.id, queueContruct);

    queueContruct.songs.push(song);

    try {
      var connection = await voiceChannel.join();
      queueContruct.connection = connection;
      play(message.guild, queueContruct.songs[0]);
    } catch (err) {
      console.log(err);
      queue.delete(message.guild.id);
      return message.channel.send(err);
    }
  } else {
    serverQueue.songs.push(song);
    return message.channel.send(`${song.title} **by** ${song.author} has been added to the queue!`);
  }
}

function skip(message, serverQueue) {
  if (!message.member.voice.channel)
    return message.channel.send("You have to be in a voice channel to skip audio!");
  if (!serverQueue)
    return message.channel.send("There is no audio that I could skip!");
  serverQueue.connection.dispatcher.end();
}

function stop(message, serverQueue) {
  if (!message.member.voice.channel)
    return message.channel.send("You have to be in a voice channel to stop audio playback!");
  serverQueue.songs = [];
  serverQueue.connection.dispatcher.end();
  message.channel.send("Successfully stopped audio playback and left voice channel.")
}

function play(guild, song) {
  const serverQueue = queue.get(guild.id);
  if (!song) {
    serverQueue.voiceChannel.leave();
    queue.delete(guild.id);
    return;
  }

  const dispatcher = serverQueue.connection
    .play(ytdl(song.url), {bitrate: 192000 /* 192kbps */})
    .on("finish", () => {
      serverQueue.songs.shift();
      play(guild, serverQueue.songs[0]);
    })
    .on("error", error => console.error(error));
  dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
  serverQueue.textChannel.send(`Started playing: ${song.title} **by** ${song.author}`);
}

The error that I am getting:

(node:262965) UnhandledPromiseRejectionWarning: Error: Unable to retrieve video metadata
    at getJSONWatchPage (/media/bitlockermount/My Files/Things I've Made/(Discord Bots)/[AMD]Bot+/node_modules/ytdl-core/lib/info.js:192:11)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async retryFn (/media/bitlockermount/My Files/Things I've Made/(Discord Bots)/[AMD]Bot+/node_modules/ytdl-core/lib/info.js:136:16)
    at async exports.getBasicInfo (/media/bitlockermount/My Files/Things I've Made/(Discord Bots)/[AMD]Bot+/node_modules/ytdl-core/lib/info.js:35:14)
    at async exports.getInfo (/media/bitlockermount/My Files/Things I've Made/(Discord Bots)/[AMD]Bot+/node_modules/ytdl-core/lib/info.js:257:14)
    at async execute (/media/bitlockermount/My Files/Things I've Made/(Discord Bots)/[AMD]Bot+/bot.js:460:20)
(node:262965) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:262965) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Is this a problem with my code or is it a problem with ytdl-core? It only happens on specific videos.

I am not very good at programming so if I made a mistake please point it out, if you need more info please don’t hesitate to ask.

Sorry for the messy issue layout, I wrote this issue on my phone.

@BlazeIsClone
Copy link

BlazeIsClone commented Nov 15, 2020

yup im getting this randomly too(note that the error goes away after another try). I clean installed ytdl-core as well but no luck.

@BR88C
Copy link

BR88C commented Nov 15, 2020

I am also encountering this error, sometimes waiting resolves it, other times it doesn't, and it appears to happen at random. It also will sometimes resolve itself if I restart my application.

@fent fent closed this as completed in 5a9a1f4 Nov 16, 2020
@fent fent added the bug label Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants