How to use youtube-search - 1 common examples

To help you get started, we’ve selected a few youtube-search 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 sogehige / sogeBot / src / bot / systems / songs.ts View on Github external
if (opts.parameters.length < 1 || !this.songrequest) {
      if (this.songrequest) {
        sendMessage(translate('core.usage') + ': !songrequest ', opts.sender, opts.attr);
      } else {
        sendMessage('$sender, ' + translate('core.settings.songs.songrequest.false'), opts.sender, opts.attr);
      }
      return;
    }

    const urlRegex = /^.*(?:youtu.be\/|v\/|e\/|u\/\w+\/|embed\/|v=)([^#&?]*).*/;
    const idRegex = /^[a-zA-Z0-9-_]{11}$/;
    const match = opts.parameters.match(urlRegex);
    const videoID = (match && match[1].length === 11) ? match[1] : opts.parameters;

    if (_.isNil(videoID.match(idRegex))) { // not id or url
      ytsearch(opts.parameters, { maxResults: 1, key: 'AIzaSyDYevtuLOxbyqBjh17JNZNvSQO854sngK0' }, (err, results) => {
        if (err) {
          return error(err);
        }
        if (typeof results !== 'undefined' && results[0].id) {
          opts.parameters = results[0].id;
          this.addSongToQueue(opts);
        }
      });
      return;
    }

    // is song banned?
    const ban = await getRepository(SongBan).findOne({ videoId: videoID });
    if (ban) {
      sendMessage(translate('songs.song-is-banned'), opts.sender, opts.attr);
      return;

youtube-search

Search for youtube videos

BSD
Latest version published 4 years ago

Package Health Score

42 / 100
Full package analysis

Popular youtube-search functions