<commit_before>﻿var config = require('../../config');
var request = require('request');
var FeedParser = require('feedparser');
var _ = require('lodash');
var path = require('path');
var fs = require('fs');

module.exports = function (model) {
	function findTorrentEntry(entries, torrentId) {
		for (var i = 0; i < entries.length; ++i) {
			if (!entries[i].sources) continue;

			for (var j = 0; j < entries[i].sources.length; ++j) {
				var dl = _.find(entries[i].sources[j].downloads, function (dl) { return dl.torrentId === torrentId; });
				if (dl) {
					return { entry: entries[i], source: entries[i].sources[j], idx: entries[i].sources[j].downloads.indexOf(dl) };
				}
			}
		}

		return null;
	}

	function linkExists(entries, link) {
		for (var i = 0; i < entries.length; ++i) {
			if (!entries[i].sources) continue;

			for (var j = 0; j < entries[i].sources.length; ++j) {
				var dl = _.find(entries[i].sources[j].downloads, function (dl) { return dl.link === link; });
				if (dl) {
					return true;
				}
			}
		}

		return false;
	}

	function assignFiles(entry, source, files) {
		function findSeason(needle) {
			return _.filter(entry.seasons, function (season) { return season.season == needle; })[0];
		}

		var orderedSeasons = _.filter(entry.seasons, function (season) { return season.season != 0; }).sort(function (a, b) { return a.season - b.season; });

		for (var i = 0; i < files.length; ++i) {
			var file = files[i];
			file.beautified = file.name.replace(/\.|_/g, ' ').replace(/\d+p|\d+x\d+|\[.*?\]|FLAC|Blu-?Ray|\w264/ig, '').replace(/(\(|\[)\s+(\)|\])/g, '').replace(/\s{2,}/g, ' ');

			var regex, match;

			if (source.assignMethod === 'sxe') {
				match = file.beautified.match(/s?((\d+)(e|x))(\d+)/i);
				if (!match) {
					continue;
				}
<commit_msg>Use the file name only to match episode/season<commit_after>﻿var config = require('../../config');
var request = require('request');
var FeedParser = require('feedparser');
var _ = require('lodash');
var path = require('path');
var fs = require('fs');

module.exports = function (model) {
	function findTorrentEntry(entries, torrentId) {
		for (var i = 0; i < entries.length; ++i) {
			if (!entries[i].sources) continue;

			for (var j = 0; j < entries[i].sources.length; ++j) {
				var dl = _.find(entries[i].sources[j].downloads, function (dl) { return dl.torrentId === torrentId; });
				if (dl) {
					return { entry: entries[i], source: entries[i].sources[j], idx: entries[i].sources[j].downloads.indexOf(dl) };
				}
			}
		}

		return null;
	}

	function linkExists(entries, link) {
		for (var i = 0; i < entries.length; ++i) {
			if (!entries[i].sources) continue;

			for (var j = 0; j < entries[i].sources.length; ++j) {
				var dl = _.find(entries[i].sources[j].downloads, function (dl) { return dl.link === link; });
				if (dl) {
					return true;
				}
			}
		}

		return false;
	}

	function assignFiles(entry, source, files) {
		function findSeason(needle) {
			return _.filter(entry.seasons, function (season) { return season.season == needle; })[0];
		}

		var orderedSeasons = _.filter(entry.seasons, function (season) { return season.season != 0; }).sort(function (a, b) { return a.season - b.season; });

		for (var i = 0; i < files.length; ++i) {
			var file = files[i];
			var splitted = file.name.split('/');
			file.beautified = splitted[splitted.length - 1].replace(/\.|_/g, ' ').replace(/\d+p|\d+x\d+|\[.*?\]|FLAC|Blu-?Ray|\w264/ig, '').replace(/(\(|\[)\s+(\)|\])/g, '').replace(/\s{2,}/g, ' ');

			var regex, match;

			if (source.assignMethod === 'sxe') {
				match = file.beautified.match(/s?((\d+)(e|x))(\d+)/i);
				if (!match) {
					continue;
				}

{'fraction_non_alphanumeric': 0.21414965986394557, 'fraction_numerical': 0.006258503401360544, 'mean_word_length': 3.376190476190476, 'pattern_counts': {'":': 0, '<': 13, '<?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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2207551', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1310, 'n_words': 305}