<commit_before>var Youtube = require("youtube-api");
var Soundcloud = require('node-soundcloud');

var GLOBAL_CONFIG = require("../../global-config.js");

module.exports = function(Search) {
  Search.youtube = function(keyword, pthis, next) {
    Youtube.authenticate({
      type: "key",
      key: GLOBAL_CONFIG.youtubeApiKey
    });

    Youtube.search.list({q:keyword, part:"snippet", maxResults:30, type:"video"}, function(err, data) {
      var youtubeUrl, orderNumber=0;

      data.items.forEach(function(item) {
        youtubeUrl = "http://www.youtube.com/watch?v=" + item.id.videoId;
        pthis.musics.create({title:item.snippet.title, type:"youtube", url:youtubeUrl, order:orderNumber}, function(err, obj){
        });
        orderNumber++;
      });

      next();
    });
  };

  Search.soundcloud = function(keyword, pthis, next) {
    Soundcloud.init(GLOBAL_CONFIG.soundcloud);

    Soundcloud.get('/tracks?q=' + keyword, function(err, tracks) {
      var youtubeUrl, orderNumber=0;

      tracks.forEach(function(track) {
        pthis.musics.create({title:track.title, type:"soundcloud", url:track.permalink_url, order:orderNumber}, function(err, obj){
        });

        orderNumber++;
      });

      next();
    });
  };

  Search.afterCreate = function(next) {
    var pthis = this;

    switch(this.source) {
      case "soundcloud":
        Search.soundcloud(this.keyword, pthis, next);
        break;

      case "youtube":
      default:
        Search.youtube(this.keyword, pthis, next);
        break;
    }
  };
};<commit_msg>通らなくなったテストの対応 searchモデルにsource要素が無い場合は追加<commit_after>var Youtube = require("youtube-api");
var Soundcloud = require('node-soundcloud');

var GLOBAL_CONFIG = require("../../global-config.js");

module.exports = function(Search) {
  Search.youtube = function(keyword, pthis, next) {
    Youtube.authenticate({
      type: "key",
      key: GLOBAL_CONFIG.youtubeApiKey
    });

    Youtube.search.list({q:keyword, part:"snippet", maxResults:30, type:"video"}, function(err, data) {
      var youtubeUrl, orderNumber=0;

      data.items.forEach(function(item) {
        youtubeUrl = "http://www.youtube.com/watch?v=" + item.id.videoId;
        pthis.musics.create({title:item.snippet.title, type:"youtube", url:youtubeUrl, order:orderNumber}, function(err, obj){
        });
        orderNumber++;
      });

      next();
    });
  };

  Search.soundcloud = function(keyword, pthis, next) {
    Soundcloud.init(GLOBAL_CONFIG.soundcloud);

    Soundcloud.get('/tracks?q=' + keyword, function(err, tracks) {
      var youtubeUrl, orderNumber=0;

      tracks.forEach(function(track) {
        pthis.musics.create({title:track.title, type:"soundcloud", url:track.permalink_url, order:orderNumber}, function(err, obj){
        });

        orderNumber++;
      });

      next();
    });
  };

  Search.beforeSave = function(next, modelInstance) {
    if (typeof this.source === "undefined") {
      this.source = "youtube";
    }

    next();
  };

  Search.afterCreate = function(next) {
    var pthis = this;

    switch(this.source) {
      case "soundcloud":
        Search.soundcloud(this.keyword, pthis, next);
        break;

      case "youtube":
      default:
        Search.youtube(this.keyword, pthis, next);
        break;
    }
  };
};
{'fraction_non_alphanumeric': 0.1578469912307227, 'fraction_numerical': 0.002419110976716057, 'mean_word_length': 3.024330900243309, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5412712', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1034, 'n_words': 173}