add category preffered words and partial ignore.

This commit is contained in:
clinton-hall
2013-06-14 21:56:26 +09:30
parent 007597239f
commit 60034f2c96
2 changed files with 50 additions and 4 deletions
+10 -4
View File
@@ -3,8 +3,8 @@ from couchpotato.core.helpers.encoding import toUnicode
from couchpotato.core.helpers.variable import getTitle
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.core.plugins.score.scores import nameScore, nameRatioScore, \
sizeScore, providerScore, duplicateScore, partialIgnoredScore, namePositionScore, \
from couchpotato.core.plugins.score.scores import nameScore, CatnameScore, nameRatioScore, \
sizeScore, providerScore, duplicateScore, partialIgnoredScore, CatpartialIgnoredScore, namePositionScore, \
halfMultipartScore
log = CPLog(__name__)
@@ -18,7 +18,10 @@ class Score(Plugin):
def calculate(self, nzb, movie):
''' Calculate the score of a NZB, used for sorting later '''
score = nameScore(toUnicode(nzb['name']), movie['library']['year'])
if movie and movie['category'] and movie['category']['preferred']:
score = CatnameScore(toUnicode(nzb['name']), movie['library']['year'], movie['category']['preferred'])
else:
score = nameScore(toUnicode(nzb['name']), movie['library']['year'])
for movie_title in movie['library']['titles']:
score += nameRatioScore(toUnicode(nzb['name']), toUnicode(movie_title['title']))
@@ -41,7 +44,10 @@ class Score(Plugin):
score += duplicateScore(nzb['name'], getTitle(movie['library']))
# Partial ignored words
score += partialIgnoredScore(nzb['name'], getTitle(movie['library']))
if movie and movie['category'] and movie['category']['ignored']:
score = CatpartialIgnoredScore(nzb['name'], getTitle(movie['library']), movie['category']['ignored'])
else:
score += partialIgnoredScore(nzb['name'], getTitle(movie['library']))
# Ignore single downloads from multipart
score += halfMultipartScore(nzb['name'])
+40
View File
@@ -49,6 +49,32 @@ def nameScore(name, year):
return score
def CatnameScore(name, year, preferred):
''' Calculate score for words in the NZB name '''
score = 0
name = name.lower()
# 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
if str(year) in name:
score = score + 5
# Contains preferred word
nzb_words = re.split('\W+', simplifyString(name))
preferred_words = [x.strip() for x in preferred.split(',')]
for word in preferred_words:
if word.strip() and word.strip().lower() in nzb_words:
score = score + 100
return score
def nameRatioScore(nzb_name, movie_name):
nzb_words = re.split('\W+', fireEvent('scanner.create_file_identifier', nzb_name, single = True))
@@ -150,6 +176,20 @@ def partialIgnoredScore(nzb_name, movie_name):
return score
def CatpartialIgnoredScore(nzb_name, movie_name, ignored):
nzb_name = nzb_name.lower()
movie_name = movie_name.lower()
ignored_words = [x.strip().lower() for x in ignored.split(',')]
score = 0
for ignored_word in ignored_words:
if ignored_word in nzb_name and ignored_word not in movie_name:
score -= 5
return score
def halfMultipartScore(nzb_name):
wrong_found = 0