How to use the ytdl-core.getInfo 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 funo-bot / Funo / src / util / musicHandler.js View on Github external
async addSong(song_url, textchannel, cb) {
    try {
      this.emit("addSong", {
        data: await YTDL.getInfo(song_url),
        cb: cb,
        channel: textchannel.id
      })
    } catch (err) {
      cb(err)
    }
    // console.log(await YTDL.getInfo(song_url))
  }
github efoxbr / megacubo / assets / js / playback.js View on Github external
self.run = () => {
        console.log('run() called');
        if(typeof(ytdl)=='undefined'){
            ytdl = require('ytdl-core')
        }
        var id = ytdl.getURLVideoID(self.entry.url);
        console.log('run() id', id, self.entry.url);
        ytdl.getInfo(id, (err, info) => {
            if (err){
                console.log('YTDL error');
                self.error = 'connect';
                self.trigger('error')
                throw err;
            } else {
                console.log('YT Info', info);
                if(info.title) {
                    self.rename(info.title, info.thumbnail_url)
                }
                var live = [];
                for(var i=0;i
github mihirpathak97 / audius / src / modules / YTDownload.js View on Github external
return new Promise(function(resolve, reject) {
    const outputFormat = settings.has('defaultAudioOut') ? settings.get('defaultAudioOut') : 'mp3';
    const outputCodec = outputFormat === 'mp3' ? "libmp3lame" : "aac";
    const infoOptions = {
      quality: 'highestaudio'
    }
    const fileName = path.join(settings.get('downloadDirectory'), sanitize(spotifyMetadata === null ? youtubeMetadata.title : spotifyMetadata.name) + '.' + outputFormat);

    ytdl.getInfo(youtubeMetadata.link, infoOptions, function(err, info) {
      if (err) {
        log.error('YTDownload', JSON.stringify(err));
        reject(err.message);
      }

      var downloadOptions = {
        quality: 'highestaudio',
        requestOptions: { maxRedirects: 5 },
        format: ytdl.filterFormats(info.formats, 'audioonly')[0]
      }

      // Setup stream
      var stream = ytdl.downloadFromInfo(info, downloadOptions);
      stream.on("response", function(httpResponse) {

        // TODO: Add event emitter to share progress with caller
github dmhacker / dmhacker-youtube / api / regular-player.js View on Github external
function fetch_target_id(req, res) {
  var id = req.params.id;
  var url = YOUTUBE_URL_PREFIX + id;

  // Fetch information about the video first
  ytdl.getInfo(url, function(err, info) {
    if (err) {
      res.status(500).json({
        state: 'error',
        message: err.message
      });
    } else {
      // Get output file
      var output_file = path.join(__dirname, '..', 'public', 'site', id + '.mp4');
      var writer = fs.createWriteStream(output_file);

      // Writer sends response back after finishing
      writer.on('finish', function() {
        res.status(200).json({
          state: 'success',
          link: '/site/' + id + '.mp4',
          info: {
github amishshah / ytdl-core-discord / index.js View on Github external
return new Promise((resolve, reject) => {
		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,
github andrewrk / groovebasin / lib / import_url_filters.js View on Github external
var isYouTube = (parsedUrl.pathname === '/watch' &&
    (parsedUrl.hostname === 'youtube.com' ||
     parsedUrl.hostname === 'www.youtube.com' ||
     parsedUrl.hostname === 'm.youtube.com')) ||
    parsedUrl.hostname === 'youtu.be' ||
    parsedUrl.hostname === 'www.youtu.be';

  if (!isYouTube) {
    cb();
    return;
  }

  var bestFormat = null;
  try {
    ytdl.getInfo(urlString, {downloadURL: true}, gotYouTubeInfo);
  } catch (e) {
    // Error: Video id (blah) does not match expected format (/^[a-zA-Z0-9-_]{11}$/)
    cb();
    return;
  }

  function gotYouTubeInfo(err, info) {
    if (err) return cb(err);
    if (info.requires_purchase) {
      cb(new Error("this YouTube video requires purchase"));
      return;
    }
    for (var i = 0; i < info.formats.length; i += 1) {
      var format = info.formats[i];
      if (bestFormat == null || format.audioBitrate > bestFormat.audioBitrate ||
         (format.audioBitrate === bestFormat.audioBitrate &&
github eritislami / evobot / commands / play.js View on Github external
url: songInfo.video_url,
          duration: songInfo.length_seconds
        };
      } catch (error) {
        if (error.message.includes("copyright")) {
          return message
            .reply("⛔ The video could not be played due to copyright protection ⛔")
            .catch(console.error);
        } else {
          console.error(error);
        }
      }
    } else {
      try {
        const results = await youtube.searchVideos(search, 1);
        songInfo = await ytdl.getInfo(results[0].url);
        song = {
          title: songInfo.title,
          url: songInfo.video_url,
          duration: songInfo.length_seconds
        };
      } catch (error) {
        console.error(error);
      }
    }

    if (serverQueue) {
      serverQueue.songs.push(song);
      return serverQueue.textChannel
        .send(`✅ **${song.title}** has been added to the queue by ${message.author}`)
        .catch(console.error);
    } else {
github sogehige / sogeBot / src / bot / systems / songs.js View on Github external
var id = (match && match[1].length === 11) ? match[1] : opts.parameters

    let imported = 0
    let done = 0

    let idsFromDB = (await global.db.engine.find(this.collection.playlist)).map(o => o.videoID)
    let banFromDb = (await global.db.engine.find(this.collection.ban)).map(o => o.videoID)

    if (idsFromDB.includes(id)) {
      global.log.info(`=> Skipped ${id} - Already in playlist`)
      done++
    } else if (banFromDb.includes(id)) {
      global.log.info(`=> Skipped ${id} - Song is banned`)
      done++
    } else {
      ytdl.getInfo('https://www.youtube.com/watch?v=' + id, async (err, videoInfo) => {
        done++
        if (err) return global.log.error(`=> Skipped ${id} - ${err.message}`)
        else if (!_.isNil(videoInfo) && !_.isNil(videoInfo.title)) {
          global.log.info(`=> Imported ${id} - ${videoInfo.title}`)
          global.db.engine.update(this.collection.playlist, { videoID: id }, { videoID: id, title: videoInfo.title, loudness: videoInfo.loudness, length_seconds: videoInfo.length_seconds, lastPlayedAt: new Date().getTime(), seed: 1 })
          imported++
        }
      })
    }

    const waitForImport = function () {
      return new Promise((resolve) => {
        const check = (resolve) => {
          if (done === 1) resolve()
          else setTimeout(() => check(resolve), 500)
        }
github rem-bot-industries / rem-v2 / modules / worker / playlist.js View on Github external
function loadSong(info, cb) {
    ytdl.getInfo(info.url, (err, info) => {
        if (err) {
            return cb(err);
        } else {
            info.id = info.video_id;
            cb(null, info);
        }
    });
}
function prefetch(info) {
github dmhacker / dmhacker-youtube / app.js View on Github external
function fetch_target_id(req, res) {
  var id = req.params.id;
  var old_url = 'https://www.youtube.com/watch?v=' + id;
  ytdl.getInfo(old_url, function(err, info) {
    if (err) {
      res.status(500).json({
        state: 'error',
        message: err.message
      });
    } else {
      var new_url = path.join(__dirname, 'public', 'site', id + '.mp4');
      var writer = fs.createWriteStream(new_url);
      writer.on('finish', function() {
        res.status(200).json({
          state: 'success',
          link: '/site/' + id + '.mp4',
          info: {
            id: id,
            title: info.title
          }