{"size": 788, "ext": "js", "max_stars_repo_path": "server.js", "max_stars_repo_name": "fetherston/puppy-bot", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server.js", "max_issues_repo_name": "fetherston/puppy-bot", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server.js", "max_forks_repo_name": "fetherston/puppy-bot", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.1851851852, "max_line_length": 76, "alphanum_fraction": 0.7068527919}
var YouTubeSearcher = require('./searchers/YouTubeSearcher');
var Logger = require('bug-killer');
var gifExtractor = require('./utils/GifExtractor');
var dogs = require('./terms/dogs');
var fs = require('fs-extra');

fs.removeSync('./temp');
fs.mkdirsSync('./temp/gifs');

var onVideoDownloadComplete = function(videoModel) {
    gifExtractor(videoModel);
};

var handleSearch = function(videoModels) {
    var model = videoModels[Math.floor(Math.random() * videoModels.length)];
    Logger.log('Found ' + videoModels.length, 'results.');
    model.download().then(onVideoDownloadComplete);
};

var term = dogs.random();
Logger.log('Searching for ' + term);

var ytSearch = new YouTubeSearcher(term);
ytSearch.search().then(handleSearch, function(err) {
    Logger.log(err, 'error');
});
