You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.2 KiB

from couchpotato.core.event import addEvent
13 years ago
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, CatnameScore, nameRatioScore, \
sizeScore, providerScore, duplicateScore, partialIgnoredScore, CatpartialIgnoredScore, namePositionScore, \
13 years ago
halfMultipartScore
log = CPLog(__name__)
class Score(Plugin):
def __init__(self):
addEvent('score.calculate', self.calculate)
def calculate(self, nzb, movie):
''' Calculate the score of a NZB, used for sorting later '''
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']))
13 years ago
score += namePositionScore(toUnicode(nzb['name']), toUnicode(movie_title['title']))
score += sizeScore(nzb['size'])
# Torrents only
if nzb.get('seeders'):
try:
score += nzb.get('seeders') / 5
score += nzb.get('leechers') / 10
except:
pass
# Provider score
score += providerScore(nzb['provider'])
# Duplicates in name
score += duplicateScore(nzb['name'], getTitle(movie['library']))
# Partial ignored words
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']))
13 years ago
# Ignore single downloads from multipart
score += halfMultipartScore(nzb['name'])
# Extra provider specific check
extra_score = nzb.get('extra_score')
if extra_score:
score += extra_score(nzb)
return score