<commit_before>
// Initiate the client to the add-ons
app.factory("stremio", ["$http", "$rootScope", function($http, $rootScope) {
	var Stremio = require("stremio-addons");
	var stremio = new Stremio.Client();

	stremio.sorts = [{ name: "Popularity", prop: "popularity" }];

	// Default auth token for open-source projects ; not required for stremioget end-points
	stremio.setAuth("http://api9.strem.io", "2a240788ce82492744cdd42ca434fc26848ec616");

	// Hardcode default official Stremio add-ons - Cinemeta (IMDB metadata), Guidebox (iTunes/Hulu/Netflix/etc. links), Channels (YouTube), Filmon
	stremio.official = ["http://cinemeta.strem.io/stremioget", "http://guidebox.strem.io/stremioget", "http://channels.strem.io/stremioget", "http://filmon.strem.io/stremioget"];
	stremio.thirdparty = [];
	stremio.all = {};

	var add = stremio.add.bind(stremio);

	stremio.official.forEach(add);

	// Load add-ons from the central tracker
	$http.get("http://api9.strem.io/addons5").success(function(res) {
		stremio.official = res.official;
		stremio.thirdparty = res.thirdparty;
		stremio.all = res.responding || {};
		res.official.forEach(add);
		stremio.emit('addons-list', res);
	}).error(function(er) { console.error("add-ons tracker", er) });

	// VERY important -  update the rootScope when a new add-on is ready
	stremio.on("addon-ready", _.debounce(function() { !$rootScope.$phase && $rootScope.$apply() }, 300));

	stremio.on("addon-ready", function(addon) {
	        // Re-aggregate those always, so that we keep the same order as the add-ons
	        stremio.sorts = []; 
	        stremio.types = [];
	        
	        stremio.get().forEach(function(addon) {
	            var m = addon.manifest;
	            if (!m) return;
	
	            // Old, LID-based sort
	            var lid = stremio.LID = m.stremio_LID;
	            if (lid) stremio.sorts.push({ name: m.sortName || m.name, prop: "popularities."+lid, types: m.types, addon: addon.identifier() });
	
	            // New, .sorts property
	            if (Array.isArray(m.sorts)) m.sorts.forEach(function(s) { s.addon = addon.identifier(); stremio.sorts.push(s) });
	        
	            // Types
	            stremio.types = stremio.types.concat(m.types || []);
	        });
	
	        stremio.sorts = _.uniq(stremio.sorts, "prop");
	        stremio.types = _.uniq(stremio.types);
	})
<commit_msg>stremio.sorts: fix new .sorts aggregation logic<commit_after>
// Initiate the client to the add-ons
app.factory("stremio", ["$http", "$rootScope", function($http, $rootScope) {
	var Stremio = require("stremio-addons");
	var stremio = new Stremio.Client();

	stremio.sorts = [{ name: "Popularity", prop: "popularity" }];

	// Default auth token for open-source projects ; not required for stremioget end-points
	stremio.setAuth("http://api9.strem.io", "2a240788ce82492744cdd42ca434fc26848ec616");

	// Hardcode default official Stremio add-ons - Cinemeta (IMDB metadata), Guidebox (iTunes/Hulu/Netflix/etc. links), Channels (YouTube), Filmon
	stremio.official = ["http://cinemeta.strem.io/stremioget", "http://guidebox.strem.io/stremioget", "http://channels.strem.io/stremioget", "http://filmon.strem.io/stremioget"];
	stremio.thirdparty = [];
	stremio.all = {};

	var add = stremio.add.bind(stremio);

	stremio.official.forEach(add);

	// Load add-ons from the central tracker
	$http.get("http://api9.strem.io/addons5").success(function(res) {
		stremio.official = res.official;
		stremio.thirdparty = res.thirdparty;
		stremio.all = res.responding || {};
		res.official.forEach(add);
		stremio.emit('addons-list', res);
	}).error(function(er) { console.error("add-ons tracker", er) });

	// VERY important -  update the rootScope when a new add-on is ready
	stremio.on("addon-ready", _.debounce(function() { !$rootScope.$phase && $rootScope.$apply() }, 300));

	stremio.on("addon-ready", function(addon) {
	        // Re-aggregate those always, so that we keep the same order as the add-ons
	        stremio.sorts = []; 
	        stremio.types = [];
	        
	        stremio.get().forEach(function(addon) {
	            var m = addon.manifest;
	            if (!m) return;
	
	            // Old, LID-based sort
	            var lid = stremio.LID = m.stremio_LID;
	            if (lid) stremio.sorts.push({ name: m.sortName || m.name, prop: "popularities."+lid, types: m.types, addon: addon.identifier() });
	
	            // New, .sorts property
	            if (Array.isArray(m.sorts)) m.sorts.forEach(function(s) { s.addon = addon.identifier(); stremio.sorts.push(s) });
	        
	            // Types
	            stremio.types = stremio.types.concat(m.types || []);
	        });
	
	        stremio.sorts = _.uniq(stremio.sorts, function(x) { return x.addon+":"+x.prop });
	        stremio.types = _.uniq(stremio.types);
	});

{'fraction_non_alphanumeric': 0.16409507923269392, 'fraction_numerical': 0.014178482068390326, 'mean_word_length': 3.037878787878788, 'pattern_counts': {'":': 1, '<': 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': '2244251', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1687, 'n_words': 323}