From af46827eb27952dc6cf71d5f53a3db8acacf75a1 Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 6 Mar 2012 23:37:55 +0100 Subject: [PATCH] Better score calculating --- couchpotato/core/plugins/score/main.py | 8 +++++- couchpotato/core/plugins/score/scores.py | 25 +++++++++++++++++-- couchpotato/core/providers/base.py | 2 +- .../core/providers/nzb/nzbclub/main.py | 8 +++--- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/couchpotato/core/plugins/score/main.py b/couchpotato/core/plugins/score/main.py index ee7c9806..49dbba41 100644 --- a/couchpotato/core/plugins/score/main.py +++ b/couchpotato/core/plugins/score/main.py @@ -3,7 +3,7 @@ from couchpotato.core.helpers.encoding import toUnicode from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.core.plugins.score.scores import nameScore, nameRatioScore, \ - sizeScore + sizeScore, providerScore, duplicateScore log = CPLog(__name__) @@ -31,4 +31,10 @@ class Score(Plugin): except: pass + # Provider score + score += providerScore(nzb['provider']) + + # Duplicates in name + score += duplicateScore(nzb['name'], movie['library']['titles'][0]['title']) + return score diff --git a/couchpotato/core/plugins/score/scores.py b/couchpotato/core/plugins/score/scores.py index ccf993ec..1a2f2b88 100644 --- a/couchpotato/core/plugins/score/scores.py +++ b/couchpotato/core/plugins/score/scores.py @@ -27,14 +27,14 @@ def nameScore(name, year): score = 0 name = name.lower() - #give points for the cool stuff + # give points for the cool stuff for value in name_scores: v = value.split(':') add = int(v.pop()) if v.pop() in name: score = score + add - #points if the year is correct + # points if the year is correct if str(year) in name: score = score + 5 @@ -58,3 +58,24 @@ def nameRatioScore(nzb_name, movie_name): def sizeScore(size): return 0 if size else -20 + + +def providerScore(provider): + if provider in ['NZBMatrix', 'Nzbs', 'Newzbin']: + return 30 + + if provider in ['Newznab', 'Moovee', 'X264']: + return 10 + + return 0 + + +def duplicateScore(nzb_name, movie_name): + + nzb_words = re.split('\W+', simplifyString(nzb_name)) + movie_words = re.split('\W+', simplifyString(movie_name)) + + # minus for duplicates + duplicates = [x for i, x in enumerate(nzb_words) if nzb_words[i:].count(x) > 1] + + return len(list(set(duplicates) - set(movie_words))) * -4 diff --git a/couchpotato/core/providers/base.py b/couchpotato/core/providers/base.py index 148b2e7c..0d00179b 100644 --- a/couchpotato/core/providers/base.py +++ b/couchpotato/core/providers/base.py @@ -102,4 +102,4 @@ class YarrProvider(Provider): return [self.cat_backup_id] def found(self, new): - log.info('Found: score(%(score)s): %(name)s' % new) + log.info('Found: score(%(score)s) on %(provider)s: %(name)s' % new) diff --git a/couchpotato/core/providers/nzb/nzbclub/main.py b/couchpotato/core/providers/nzb/nzbclub/main.py index 78ef5d70..07ae2c2d 100644 --- a/couchpotato/core/providers/nzb/nzbclub/main.py +++ b/couchpotato/core/providers/nzb/nzbclub/main.py @@ -59,9 +59,7 @@ class NZBClub(NZBProvider, RSS): size = enclosure['length'] date = self.getTextElement(nzb, "pubDate") - description = '' - if 'nfo files' in self.getTextElement(nzb, "description"): - description = toUnicode(self.getCache('nzbclub.%s' % nzbclub_id, self.getTextElement(nzb, "link"), timeout = 25920000)) + description = toUnicode(self.getCache('nzbclub.%s' % nzbclub_id, self.getTextElement(nzb, "link"), timeout = 25920000)) new = { 'id': nzbclub_id, @@ -77,6 +75,10 @@ class NZBClub(NZBProvider, RSS): } new['score'] = fireEvent('score.calculate', new, movie, single = True) + if 'ARCHIVE inside ARCHIVE' in description: + log.info('Wrong: Seems to be passworded files: %s' % new['name']) + continue + is_correct_movie = fireEvent('searcher.correct_movie', nzb = new, movie = movie, quality = quality, imdb_results = False, single_category = False, single = True)