<commit_before>'use strict';

var Request = require('./request.js');

function Search(options) {
  this.item = options.item;
  this.url = 'https://api-v2launch.trakt.tv/search';
  this.episodeUrl = 'https://api-v2launch.trakt.tv/shows';
};

Search.prototype = {
  getUrl: function() {
    return this.url + '?type=' + this.item.type + '&query=' + this.item.title;
  },

  getEpisodeUrl: function(item, slug) {
    return this.episodeUrl + '/' + slug + '/seasons/' + item.season
      + '/episodes/' + item.episode + '?extended=images';
  },

  findMovie: function(options) {
    Request.send({
      method: 'GET',
      url: this.getUrl(),
      success: function(response) {
        options.success.call(this, response[0]);
      },
      error: function(status, response) {
        options.error.call(this, status, response);
      }
    });
  },

  findEpisode: function(options) {
    Request.send({
      method: 'GET',
      url: this.getUrl(),
      success: function(response) {
        var data = JSON.parse(response)[0];

        Request.send({
          method: 'GET',
          url: this.getEpisodeUrl(item, data['show']['ids']['slug']),
          success: function(resp) {
            options.success.call(this, resp);
          },
          error: function(st, resp) {
            options.error.call(this, st, resp);
          }
        });
      },
      error: function(status, response) {
        options.error.call(this, status, response);
      }
    });
  }
}

module.exports = Search;<commit_msg>Finishing search component<commit_after>'use strict';

var Request = require('./request.js');

function Search(options) {
  this.item = options.item;
  this.url = 'https://api-v2launch.trakt.tv/search';
  this.episodeUrl = 'https://api-v2launch.trakt.tv/shows';
};

Search.prototype = {
  getUrl: function() {
    return this.url + '?type=' + this.item.type + '&query=' + this.item.title;
  },

  getEpisodeUrl: function(slug) {
    return this.episodeUrl + '/' + slug + '/seasons/' + this.item.season
      + '/episodes/' + this.item.episode + '?extended=images';
  },

  findMovie: function(options) {
    Request.send({
      method: 'GET',
      url: this.getUrl(),
      success: function(response) {
        var data = JSON.parse(response)[0];
        options.success.call(this, data);
      },
      error: function(status, response) {
        options.error.call(this, status, response);
      }
    });
  },

  findEpisode: function(options) {
    Request.send({
      method: 'GET',
      url: this.getUrl(),
      success: function(response) {
        var data = JSON.parse(response)[0];

        Request.send({
          method: 'GET',
          url: this.getEpisodeUrl(data['show']['ids']['slug']),
          success: function(resp) {
            options.success.call(this, resp);
          },
          error: function(st, resp) {
            options.error.call(this, st, resp);
          }
        });
      }.bind(this),
      error: function(status, response) {
        options.error.call(this, status, response);
      }
    });
  }
}

module.exports = Search;
{'fraction_non_alphanumeric': 0.16995153473344105, 'fraction_numerical': 0.002584814216478191, 'mean_word_length': 2.405940594059406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5771024', 'n_tokens_mistral': 1003, 'n_tokens_neox': 978, 'n_words': 175}