<commit_before>var util = require('util');
var config = require('./../util/config');
var help = require('./../util/helpers');

var apiurl = util.format('%s/api', config.cp.url);

function CPHttp(logger, searcher) {
	this.logger = logger;
	this.searcher = searcher;
	this.client = require('./../client/http')(logger);
}

CPHttp.prototype.__profile = function(id, callback) {
	var self = this;
	var url = util.format('%s/%s/profile.list', apiurl, config.cp.apikey);

	self.client.json(url, {}, function(err, resp) {
		if (err) return callback(err);
		if ((typeof resp['list'] === 'undefined') || !resp['list'].length) return callback('Empty list of profiles received from CouchPotato');

		for (var i in resp['list']) {
			if (resp['list'][i]['id'] == id)
				return callback(null, resp['list'][i]);
		}

		callback('Could not find CouchPotato-profile with id: '+id);
	});
};

CPHttp.prototype.__qualities = function(ids, callback) {
	var self = this;
	var url = util.format('%s/%s/quality.list', apiurl, config.cp.apikey);

	self.client.json(url, {}, function(err, resp) {
		if (err) return callback(err);
		if ((typeof resp['list'] === 'undefined') || !resp['list'].length) return callback('Empty list of qualities received from CouchPotato');

		var results = [];

		for (var i in resp['list']) {
			if (help.inArray(resp['list'][i]['id'], ids))
				results.push(resp['list'][i]);
		}

		callback(null, results);
	});
};

CPHttp.prototype.profileQualities = function(id, callback) {
	var self = this;

	self.__profile(id, function(err, profile) {
		if (err) return callback(err, []);

		var qids = [];
		for (var i in profile['types'])
			qids.push(profile['types'][i]['quality_id']);

		self.__qualities(qids, callback);
	});
};

// status: 8:active, 4:done
CPHttp.prototype.__movies = function(status, callback) {
	var self = this;
	var url = util.format('%s/%s/movie.list/?status=%s', apiurl, config.cp.apikey, status);

	self.client.json(url, {}, function(err, resp) {
		if (err) return callback(err);
		if ((typeof resp['movies'] === 'undefined') || !resp['movies'].length) return callback(null, []);

		self.logger.debug('Got '+resp['movies'].length+' movies to go through from CouchPotato');
		callback(null, resp['movies']);
	});
};

CPHttp.prototype.movieReleases = function(id, callback) {
	var self = this;
	var url = util.format('%s/%s/release.for_movie/?id=%s', apiurl, config.cp.apikey, id);

	self.client.json(url, {}, function(err, resp) {
		if (err) return callback(err);
		if ((typeof resp['releases'] === 'undefined') || !resp['releases'].length) return callback(null, []);

		var results = [];
		for (var i in resp['releases']) {
			if (resp['releases'][i]['info']['provider'].trim().toLowerCase() == 'passthepopcorn')
				results.push(resp['releases'][i]);
		}

		self.logger.debug('Found '+results.length+' release(s) from CouchPotato for movie #'+id);
		callback(null, results);
	});
};
<commit_msg>Bugfix: PTPANTI fails on provider-less releases in CouchPotato<commit_after>var util = require('util');
var config = require('./../util/config');
var help = require('./../util/helpers');

var apiurl = util.format('%s/api', config.cp.url);

function CPHttp(logger, searcher) {
	this.logger = logger;
	this.searcher = searcher;
	this.client = require('./../client/http')(logger);
}

CPHttp.prototype.__profile = function(id, callback) {
	var self = this;
	var url = util.format('%s/%s/profile.list', apiurl, config.cp.apikey);

	self.client.json(url, {}, function(err, resp) {
		if (err) return callback(err);
		if ((typeof resp['list'] === 'undefined') || !resp['list'].length) return callback('Empty list of profiles received from CouchPotato');

		for (var i in resp['list']) {
			if (resp['list'][i]['id'] == id)
				return callback(null, resp['list'][i]);
		}

		callback('Could not find CouchPotato-profile with id: '+id);
	});
};

CPHttp.prototype.__qualities = function(ids, callback) {
	var self = this;
	var url = util.format('%s/%s/quality.list', apiurl, config.cp.apikey);

	self.client.json(url, {}, function(err, resp) {
		if (err) return callback(err);
		if ((typeof resp['list'] === 'undefined') || !resp['list'].length) return callback('Empty list of qualities received from CouchPotato');

		var results = [];

		for (var i in resp['list']) {
			if (help.inArray(resp['list'][i]['id'], ids))
				results.push(resp['list'][i]);
		}

		callback(null, results);
	});
};

CPHttp.prototype.profileQualities = function(id, callback) {
	var self = this;

	self.__profile(id, function(err, profile) {
		if (err) return callback(err, []);

		var qids = [];
		for (var i in profile['types'])
			qids.push(profile['types'][i]['quality_id']);

		self.__qualities(qids, callback);
	});
};

// status: 8:active, 4:done
CPHttp.prototype.__movies = function(status, callback) {
	var self = this;
	var url = util.format('%s/%s/movie.list/?status=%s', apiurl, config.cp.apikey, status);

	self.client.json(url, {}, function(err, resp) {
		if (err) return callback(err);
		if ((typeof resp['movies'] === 'undefined') || !resp['movies'].length) return callback(null, []);

		self.logger.debug('Got '+resp['movies'].length+' movies to go through from CouchPotato');
		callback(null, resp['movies']);
	});
};

CPHttp.prototype.movieReleases = function(id, callback) {
	var self = this;
	var url = util.format('%s/%s/release.for_movie/?id=%s', apiurl, config.cp.apikey, id);

	self.client.json(url, {}, function(err, resp) {
		if (err) return callback(err);
		if ((typeof resp['releases'] === 'undefined') || !resp['releases'].length) return callback(null, []);

		var results = [];
		for (var i in resp['releases']) {
			if (typeof resp['releases'][i]['info'] === 'undefined') continue;
			if (typeof resp['releases'][i]['info']['provider'] === 'undefined') continue;
			if (resp['releases'][i]['info']['provider'].trim().toLowerCase() == 'passthepopcorn')
				results.push(resp['releases'][i]);
		}

		self.logger.debug('Found '+results.length+' release(s) from CouchPotato for movie #'+id);
		callback(null, results);
	});
};

{'fraction_non_alphanumeric': 0.20843672456575682, 'fraction_numerical': 0.0006617038875103391, 'mean_word_length': 4.807877041306436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1637907', 'n_tokens_mistral': 2168, 'n_tokens_neox': 2021, 'n_words': 465}