Optimize quality caching
This commit is contained in:
@@ -156,36 +156,37 @@ class QualityPlugin(Plugin):
|
|||||||
if not extra: extra = {}
|
if not extra: extra = {}
|
||||||
|
|
||||||
# Create hash for cache
|
# Create hash for cache
|
||||||
hash = md5(str([f.replace('.' + getExt(f), '') for f in files]))
|
cache_key = md5(str([f.replace('.' + getExt(f), '') for f in files]))
|
||||||
cached = self.getCache(hash)
|
cached = self.getCache(cache_key)
|
||||||
if cached and extra is {}: return cached
|
if cached and len(extra) == 0: return cached
|
||||||
|
|
||||||
|
qualities = self.all()
|
||||||
for cur_file in files:
|
for cur_file in files:
|
||||||
words = re.split('\W+', cur_file.lower())
|
words = re.split('\W+', cur_file.lower())
|
||||||
|
|
||||||
found = {}
|
found = {}
|
||||||
for quality in self.all():
|
for quality in qualities:
|
||||||
contains = self.containsTag(quality, words, cur_file)
|
contains = self.containsTag(quality, words, cur_file)
|
||||||
if contains:
|
if contains:
|
||||||
found[quality['identifier']] = True
|
found[quality['identifier']] = True
|
||||||
|
|
||||||
for quality in self.all():
|
for quality in qualities:
|
||||||
|
|
||||||
# Check identifier
|
# Check identifier
|
||||||
if quality['identifier'] in words:
|
if quality['identifier'] in words:
|
||||||
if len(found) == 0 or len(found) == 1 and found.get(quality['identifier']):
|
if len(found) == 0 or len(found) == 1 and found.get(quality['identifier']):
|
||||||
log.debug('Found via identifier "%s" in %s', (quality['identifier'], cur_file))
|
log.debug('Found via identifier "%s" in %s', (quality['identifier'], cur_file))
|
||||||
return self.setCache(hash, quality)
|
return self.setCache(cache_key, quality)
|
||||||
|
|
||||||
# Check alt and tags
|
# Check alt and tags
|
||||||
contains = self.containsTag(quality, words, cur_file)
|
contains = self.containsTag(quality, words, cur_file)
|
||||||
if contains:
|
if contains:
|
||||||
return self.setCache(hash, quality)
|
return self.setCache(cache_key, quality)
|
||||||
|
|
||||||
# Try again with loose testing
|
# Try again with loose testing
|
||||||
quality = self.guessLoose(hash, files = files, extra = extra)
|
quality = self.guessLoose(cache_key, files = files, extra = extra)
|
||||||
if quality:
|
if quality:
|
||||||
return self.setCache(hash, quality)
|
return self.setCache(cache_key, quality)
|
||||||
|
|
||||||
log.debug('Could not identify quality for: %s', files)
|
log.debug('Could not identify quality for: %s', files)
|
||||||
return None
|
return None
|
||||||
@@ -205,7 +206,7 @@ class QualityPlugin(Plugin):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def guessLoose(self, hash, files = None, extra = None):
|
def guessLoose(self, cache_key, files = None, extra = None):
|
||||||
|
|
||||||
if extra:
|
if extra:
|
||||||
for quality in self.all():
|
for quality in self.all():
|
||||||
@@ -213,15 +214,15 @@ class QualityPlugin(Plugin):
|
|||||||
# Check width resolution, range 20
|
# Check width resolution, range 20
|
||||||
if quality.get('width') and (quality.get('width') - 20) <= extra.get('resolution_width', 0) <= (quality.get('width') + 20):
|
if quality.get('width') and (quality.get('width') - 20) <= extra.get('resolution_width', 0) <= (quality.get('width') + 20):
|
||||||
log.debug('Found %s via resolution_width: %s == %s', (quality['identifier'], quality.get('width'), extra.get('resolution_width', 0)))
|
log.debug('Found %s via resolution_width: %s == %s', (quality['identifier'], quality.get('width'), extra.get('resolution_width', 0)))
|
||||||
return self.setCache(hash, quality)
|
return self.setCache(cache_key, quality)
|
||||||
|
|
||||||
# Check height resolution, range 20
|
# Check height resolution, range 20
|
||||||
if quality.get('height') and (quality.get('height') - 20) <= extra.get('resolution_height', 0) <= (quality.get('height') + 20):
|
if quality.get('height') and (quality.get('height') - 20) <= extra.get('resolution_height', 0) <= (quality.get('height') + 20):
|
||||||
log.debug('Found %s via resolution_height: %s == %s', (quality['identifier'], quality.get('height'), extra.get('resolution_height', 0)))
|
log.debug('Found %s via resolution_height: %s == %s', (quality['identifier'], quality.get('height'), extra.get('resolution_height', 0)))
|
||||||
return self.setCache(hash, quality)
|
return self.setCache(cache_key, quality)
|
||||||
|
|
||||||
if 480 <= extra.get('resolution_width', 0) <= 720:
|
if 480 <= extra.get('resolution_width', 0) <= 720:
|
||||||
log.debug('Found as dvdrip')
|
log.debug('Found as dvdrip')
|
||||||
return self.setCache(hash, self.single('dvdrip'))
|
return self.setCache(cache_key, self.single('dvdrip'))
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user