How to use the ytdl-core.getBasicInfo function in ytdl-core

To help you get started, we’ve selected a few ytdl-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Crow08 / discord-uberbot / music.js View on Github external
if (!suffix) {
        return msg.channel.send(musicbot.note("fail", "No video specified!"));
      }
      if (musicbot.getQueue(msg.guild.id).songs.length >= musicbot.maxQueueSize && musicbot.maxQueueSize !== 0) {
        return msg.channel.send(musicbot.note("fail", "Maximum queue size reached!"));
      }
      let searchstring = suffix.trim();
      if (searchstring.includes("youtu.be/") || searchstring.includes("youtube.com/")) {
        if (searchstring.includes("&")) {
          searchstring = searchstring.split("&")[0];
        }
        if (searchstring.includes("watch") || searchstring.includes("youtu.be/")) {
          // Youtube video url detected:
          msg.channel.send(musicbot.note("search", "Get song from Youtube url~"));

          ytdl.getBasicInfo(searchstring, {}, (err, info) => {
            if (err) {
              return msg.channel.send(musicbot.note("fail", "Something went wrong fetching the video!"));
            }
            const queue = musicbot.getQueue(msg.guild.id);
            const video = {};
            video.url = info.video_url;
            video.channelTitle = info.author.name;
            video.channelURL = info.author.channel_url || info.author.user_url;
            video.requester = msg.author.id;
            video.position = queue.songs ? queue.songs.length : 0;
            video.queuedOn = new Date().toLocaleDateString(musicbot.dateLocal, {"weekday": "long", "hour": "numeric"});
            if (musicbot.requesterName) {
              video.requesterAvatarURL = msg.author.displayAvatarURL;
            }
            queue.songs.push(video);
            if (queue.songs.length === 1 || !baseClient.voiceConnections.find((val) => val.channel.guild.id === msg.guild.id)) {
github moshfeu / y2mp3 / src / services / api.ts View on Github external
async function fetchVideoFromSingle(videoUrl: string): Promise {
  try {
    const { title, video_id } = await getBasicInfo(videoUrl);
    return [createVideoEntity(title, video_id)];
  } catch (error) {
    return [];
  }
}
github Crow08 / discord-uberbot / src / YoutubeService.js View on Github external
return new Promise((resolve, reject) => {
      ytdl.getBasicInfo(searchString, {}, (err, info) => {
        if (err) {
          return reject(new Error("Something went wrong fetching the song!"));
        }
        const song = new Song();
        song.title = info.title;
        song.url = info.video_url;
        song.artist = info.author.name;
        song.src = Song.srcType.YT;
        return resolve([song]);
      });
    });
  }