Improved scoring
This commit is contained in:
@@ -4,7 +4,8 @@ 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
|
||||
sizeScore, providerScore, duplicateScore, partialIgnoredScore, namePositionScore, \
|
||||
halfMultipartScore
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -21,6 +22,7 @@ class Score(Plugin):
|
||||
|
||||
for movie_title in movie['library']['titles']:
|
||||
score += nameRatioScore(toUnicode(nzb['name']), toUnicode(movie_title['title']))
|
||||
score += namePositionScore(toUnicode(nzb['name']), toUnicode(movie_title['title']))
|
||||
|
||||
score += sizeScore(nzb['size'])
|
||||
|
||||
@@ -41,6 +43,9 @@ class Score(Plugin):
|
||||
# Partial ignored words
|
||||
score += partialIgnoredScore(nzb['name'], getTitle(movie['library']))
|
||||
|
||||
# Ignore single downloads from multipart
|
||||
score += halfMultipartScore(nzb['name'])
|
||||
|
||||
# Extra provider specific check
|
||||
extra_score = nzb.get('extra_score')
|
||||
if extra_score:
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from couchpotato.core.event import fireEvent
|
||||
from couchpotato.core.helpers.encoding import simplifyString
|
||||
from couchpotato.core.helpers.variable import tryInt
|
||||
from couchpotato.core.plugins.scanner.main import Scanner
|
||||
from couchpotato.environment import Env
|
||||
import re
|
||||
|
||||
@@ -16,11 +18,12 @@ name_scores = [
|
||||
'german:-10', 'french:-10', 'spanish:-10', 'swesub:-20', 'danish:-10', 'dutch:-10',
|
||||
# Release groups
|
||||
'imbt:1', 'cocain:1', 'vomit:1', 'fico:1', 'arrow:1', 'pukka:1', 'prism:1', 'devise:1', 'esir:1', 'ctrlhd:1',
|
||||
'metis:1', 'diamond:1', 'wiki:1', 'cbgb:1', 'crossbow:1', 'sinners:1', 'amiable:1', 'refined:1', 'twizted:1', 'felony:1', 'hubris:1', 'machd:1',
|
||||
'metis:10', 'diamond:10', 'wiki:10', 'cbgb:10', 'crossbow:1', 'sinners:10', 'amiable:10', 'refined:1', 'twizted:1', 'felony:1', 'hubris:1', 'machd:1',
|
||||
# Extras
|
||||
'extras:-40', 'trilogy:-40',
|
||||
]
|
||||
|
||||
|
||||
def nameScore(name, year):
|
||||
''' Calculate score for words in the NZB name '''
|
||||
|
||||
@@ -47,8 +50,8 @@ def nameScore(name, year):
|
||||
|
||||
return score
|
||||
|
||||
def nameRatioScore(nzb_name, movie_name):
|
||||
|
||||
def nameRatioScore(nzb_name, movie_name):
|
||||
nzb_words = re.split('\W+', fireEvent('scanner.create_file_identifier', nzb_name, single = True))
|
||||
movie_words = re.split('\W+', simplifyString(movie_name))
|
||||
|
||||
@@ -56,15 +59,68 @@ def nameRatioScore(nzb_name, movie_name):
|
||||
return 10 - len(left_over)
|
||||
|
||||
|
||||
def namePositionScore(nzb_name, movie_name):
|
||||
score = 0
|
||||
|
||||
nzb_words = re.split('\W+', simplifyString(nzb_name))
|
||||
qualities = fireEvent('quality.all', single = True)
|
||||
|
||||
try:
|
||||
nzb_name = re.search(r'([\'"])[^\1]*\1', nzb_name).group(0)
|
||||
except:
|
||||
pass
|
||||
|
||||
name_year = fireEvent('scanner.name_year', nzb_name, single = True)
|
||||
|
||||
# Give points for movies beginning with the correct name
|
||||
name_split = simplifyString(nzb_name).split(simplifyString(movie_name))
|
||||
if name_split[0].strip() == '':
|
||||
score += 10
|
||||
|
||||
# If year is second in line, give more points
|
||||
if len(name_split) > 1 and name_year:
|
||||
after_name = name_split[1].strip()
|
||||
if tryInt(after_name[:4]) == name_year.get('year', None):
|
||||
score += 10
|
||||
after_name = after_name[4:]
|
||||
|
||||
# Give -point to crap between year and quality
|
||||
found_quality = None
|
||||
for quality in qualities:
|
||||
# Main in words
|
||||
if quality['identifier'] in nzb_words:
|
||||
found_quality = quality['identifier']
|
||||
|
||||
# Alt in words
|
||||
for alt in quality['alternative']:
|
||||
if alt in nzb_words:
|
||||
found_quality = alt
|
||||
break
|
||||
|
||||
if not found_quality:
|
||||
return score - 20
|
||||
|
||||
allowed = []
|
||||
for value in name_scores:
|
||||
name, sc = value.split(':')
|
||||
allowed.append(name)
|
||||
|
||||
inbetween = re.split('\W+', after_name.split(found_quality)[0].strip())
|
||||
|
||||
score -= (10 * len(set(inbetween) - set(allowed)))
|
||||
|
||||
return score
|
||||
|
||||
|
||||
def sizeScore(size):
|
||||
return 0 if size else -20
|
||||
|
||||
|
||||
def providerScore(provider):
|
||||
if provider in ['NZBMatrix', 'Nzbs', 'Newzbin']:
|
||||
return 30
|
||||
return 20
|
||||
|
||||
if provider in ['Newznab', 'Moovee', 'X264']:
|
||||
if provider in ['Newznab']:
|
||||
return 10
|
||||
|
||||
return 0
|
||||
@@ -94,3 +150,16 @@ def partialIgnoredScore(nzb_name, movie_name):
|
||||
score -= 5
|
||||
|
||||
return score
|
||||
|
||||
def halfMultipartScore(nzb_name):
|
||||
|
||||
wrong_found = 0
|
||||
for nr in [1, 2, 3, 4, 5, 'i', 'ii', 'iii', 'iv', 'v', 'a', 'b', 'c', 'd', 'e']:
|
||||
for wrong in ['cd', 'part', 'dis', 'disc', 'dvd']:
|
||||
if '%s%s' % (wrong, nr) in nzb_name.lower():
|
||||
wrong_found += 1
|
||||
|
||||
if wrong_found == 1:
|
||||
return -30
|
||||
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user