Add size to quality guessing
And cleanup searcher
This commit is contained in:
1 parent
e51ddd7a50
commit
bfe8aa5f5f
3 files changed
+35
-27
No files matched your search
@@ -87,28 +87,17 @@ class Searcher(SearcherBase):
|
|||||||
def containsOtherQuality(self, nzb, movie_year = None, preferred_quality = None):
|
def containsOtherQuality(self, nzb, movie_year = None, preferred_quality = None):
|
||||||
if not preferred_quality: preferred_quality = {}
|
if not preferred_quality: preferred_quality = {}
|
||||||
|
|
||||||
name = nzb['name']
|
|
||||||
size = nzb.get('size', 0)
|
|
||||||
nzb_words = re.split('\W+', simplifyString(name))
|
|
||||||
|
|
||||||
qualities = fireEvent('quality.all', single = True)
|
|
||||||
|
|
||||||
found = {}
|
|
||||||
for quality in qualities:
|
|
||||||
# Main in words
|
|
||||||
if quality['identifier'] in nzb_words:
|
|
||||||
found[quality['identifier']] = True
|
|
||||||
|
|
||||||
# Alt in words
|
|
||||||
if list(set(nzb_words) & set(quality['alternative'])):
|
|
||||||
found[quality['identifier']] = True
|
|
||||||
|
|
||||||
# Try guessing via quality tags
|
# Try guessing via quality tags
|
||||||
guess = fireEvent('quality.guess', [nzb.get('name')], single = True)
|
guess = fireEvent('quality.guess', [nzb.get('name')], nzb.get('size', None), single = True)
|
||||||
if guess:
|
if guess:
|
||||||
found[guess['identifier']] = True
|
return not guess['identifier'] == preferred_quality.get('identifier')
|
||||||
|
|
||||||
|
|
||||||
# Hack for older movies that don't contain quality tag
|
# Hack for older movies that don't contain quality tag
|
||||||
|
name = nzb['name']
|
||||||
|
size = nzb.get('size', 0)
|
||||||
|
|
||||||
|
found = {}
|
||||||
year_name = fireEvent('scanner.name_year', name, single = True)
|
year_name = fireEvent('scanner.name_year', name, single = True)
|
||||||
if len(found) == 0 and movie_year < datetime.datetime.now().year - 3 and not year_name.get('year', None):
|
if len(found) == 0 and movie_year < datetime.datetime.now().year - 3 and not year_name.get('year', None):
|
||||||
if size > 20000: # Assume bd50
|
if size > 20000: # Assume bd50
|
||||||
@@ -121,11 +110,6 @@ class Searcher(SearcherBase):
|
|||||||
log.info('Quality was missing in name, assuming it\'s a DVD-Rip based on the size: %s', size)
|
log.info('Quality was missing in name, assuming it\'s a DVD-Rip based on the size: %s', size)
|
||||||
found['dvdrip'] = True
|
found['dvdrip'] = True
|
||||||
|
|
||||||
# Allow other qualities
|
|
||||||
for allowed in preferred_quality.get('allow'):
|
|
||||||
if found.get(allowed):
|
|
||||||
del found[allowed]
|
|
||||||
|
|
||||||
return not (found.get(preferred_quality['identifier']) and len(found) == 1)
|
return not (found.get(preferred_quality['identifier']) and len(found) == 1)
|
||||||
|
|
||||||
def correct3D(self, nzb, preferred_quality = None):
|
def correct3D(self, nzb, preferred_quality = None):
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ class QualityPlugin(Plugin):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def guess(self, files, extra = None):
|
def guess(self, files, extra = None, size = None):
|
||||||
if not extra: extra = {}
|
if not extra: extra = {}
|
||||||
|
|
||||||
# Create hash for cache
|
# Create hash for cache
|
||||||
@@ -205,6 +205,11 @@ class QualityPlugin(Plugin):
|
|||||||
|
|
||||||
self.calcScore(score, quality, contains_score, threedscore)
|
self.calcScore(score, quality, contains_score, threedscore)
|
||||||
|
|
||||||
|
# Evaluate score based on size
|
||||||
|
for quality in qualities:
|
||||||
|
size_score = self.guessSizeScore(quality, size = size)
|
||||||
|
self.calcScore(score, quality, size_score)
|
||||||
|
|
||||||
# Try again with loose testing
|
# Try again with loose testing
|
||||||
for quality in qualities:
|
for quality in qualities:
|
||||||
loose_score = self.guessLooseScore(quality, extra = extra)
|
loose_score = self.guessLooseScore(quality, extra = extra)
|
||||||
@@ -308,6 +313,19 @@ class QualityPlugin(Plugin):
|
|||||||
|
|
||||||
return score
|
return score
|
||||||
|
|
||||||
|
|
||||||
|
def guessSizeScore(self, quality, size = None):
|
||||||
|
|
||||||
|
score = 0
|
||||||
|
|
||||||
|
if size:
|
||||||
|
|
||||||
|
if tryInt(size) >= tryInt(quality['size_min']) and tryInt(size) < tryInt(quality['size_max']):
|
||||||
|
log.info2('Found %s via release size: %s MB < %s MB < %s MB', (quality['identifier'], quality['size_min'], size, quality['size_max']))
|
||||||
|
score += 5
|
||||||
|
|
||||||
|
return score
|
||||||
|
|
||||||
def calcScore(self, score, quality, add_score, threedscore = (0, None)):
|
def calcScore(self, score, quality, add_score, threedscore = (0, None)):
|
||||||
|
|
||||||
score[quality['identifier']]['score'] += add_score
|
score[quality['identifier']]['score'] += add_score
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ class Scanner(Plugin):
|
|||||||
identifiers = [identifier]
|
identifiers = [identifier]
|
||||||
|
|
||||||
# Identifier with quality
|
# Identifier with quality
|
||||||
quality = fireEvent('quality.guess', [file_path], single = True) if not is_dvd_file else {'identifier':'dvdr'}
|
quality = fireEvent('quality.guess', files = [file_path], size = self.getFileSize(file_path), single = True) if not is_dvd_file else {'identifier':'dvdr'}
|
||||||
if quality:
|
if quality:
|
||||||
identifier_with_quality = '%s %s' % (identifier, quality.get('identifier', ''))
|
identifier_with_quality = '%s %s' % (identifier, quality.get('identifier', ''))
|
||||||
identifiers = [identifier_with_quality, identifier]
|
identifiers = [identifier_with_quality, identifier]
|
||||||
@@ -450,7 +450,7 @@ class Scanner(Plugin):
|
|||||||
data['quality'] = None
|
data['quality'] = None
|
||||||
if release_download and release_download.get('quality'):
|
if release_download and release_download.get('quality'):
|
||||||
data['quality'] = fireEvent('quality.single', release_download.get('quality'), single = True)
|
data['quality'] = fireEvent('quality.single', release_download.get('quality'), single = True)
|
||||||
data['quality']['is_3d'] = release_download.get('is_3d', False)
|
data['quality']['is_3d'] = release_download.get('is_3d', 0)
|
||||||
|
|
||||||
if not data['quality']:
|
if not data['quality']:
|
||||||
data['quality'] = fireEvent('quality.guess', files = files, extra = data, single = True)
|
data['quality'] = fireEvent('quality.guess', files = files, extra = data, single = True)
|
||||||
@@ -709,12 +709,18 @@ class Scanner(Plugin):
|
|||||||
if not file_size: file_size = []
|
if not file_size: file_size = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return (file_size.get('min', 0) * 1048576) < os.path.getsize(file) < (file_size.get('max', 100000) * 1048576)
|
return file_size.get('min', 0) < self.getFileSize(file) < file_size.get('max', 100000)
|
||||||
except:
|
except:
|
||||||
log.error('Couldn\'t get filesize of %s.', file)
|
log.error('Couldn\'t get filesize of %s.', file)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def getFileSize(self, file):
|
||||||
|
try:
|
||||||
|
return os.path.getsize(file) / 1024 / 1024
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def createStringIdentifier(self, file_path, folder = '', exclude_filename = False):
|
def createStringIdentifier(self, file_path, folder = '', exclude_filename = False):
|
||||||
|
|
||||||
year = self.findYear(file_path)
|
year = self.findYear(file_path)
|
||||||
|
|||||||
Reference in new issue
Block a user