Browse Source

Better quality guessing

tags/build/2.0.0.pre1
Ruud 13 years ago
parent
commit
965e2af338
  1. 2
      couchpotato/core/plugins/movie/static/movie.js
  2. 32
      couchpotato/core/plugins/quality/main.py
  3. 30
      couchpotato/core/plugins/renamer/main.py

2
couchpotato/core/plugins/movie/static/movie.js

@ -82,7 +82,7 @@ var Movie = new Class({
if(!q && (status.identifier == 'snatched' || status.identifier == 'done'))
var q = self.addQuality(release.quality_id)
if (q)
if (status && q)
q.addClass(status.identifier);
});

32
couchpotato/core/plugins/quality/main.py

@ -21,7 +21,7 @@ class QualityPlugin(Plugin):
{'identifier': '720p', 'hd': True, 'size': (3500, 10000), 'label': '720P', 'width': 1280, 'alternative': [], 'allow': [], 'ext':['mkv', 'm2ts', 'ts']},
{'identifier': 'brrip', 'hd': True, 'size': (700, 7000), 'label': 'BR-Rip', 'alternative': ['bdrip'], 'allow': ['720p'], 'ext':['avi']},
{'identifier': 'dvdr', 'size': (3000, 10000), 'label': 'DVD-R', 'alternative': [], 'allow': [], 'ext':['iso', 'img'], 'tags': ['pal', 'ntsc', 'video_ts', 'audio_ts']},
{'identifier': 'dvdrip', 'size': (600, 2400), 'label': 'DVD-Rip', 'alternative': ['dvdrip'], 'allow': [], 'ext':['avi', 'mpg', 'mpeg']},
{'identifier': 'dvdrip', 'size': (600, 2400), 'label': 'DVD-Rip', 'width': 720, 'alternative': ['dvdrip'], 'allow': [], 'ext':['avi', 'mpg', 'mpeg']},
{'identifier': 'scr', 'size': (600, 1600), 'label': 'Screener', 'alternative': ['screener', 'dvdscr', 'ppvrip'], 'allow': ['dvdr', 'dvd'], 'ext':['avi', 'mpg', 'mpeg']},
{'identifier': 'r5', 'size': (600, 1000), 'label': 'R5', 'alternative': [], 'allow': ['dvdr'], 'ext':['avi', 'mpg', 'mpeg']},
{'identifier': 'tc', 'size': (600, 1000), 'label': 'TeleCine', 'alternative': ['telecine'], 'allow': [], 'ext':['avi', 'mpg', 'mpeg']},
@ -151,7 +151,7 @@ class QualityPlugin(Plugin):
return True
def guess(self, files, extra = {}, loose = False):
def guess(self, files, extra = {}):
# Create hash for cache
hash = md5(str([f.replace('.' + getExt(f), '') for f in files]))
@ -182,25 +182,25 @@ class QualityPlugin(Plugin):
log.debug('Found %s via tag %s in %s' % (quality['identifier'], quality.get('tags'), cur_file))
return self.setCache(hash, quality)
# Check on unreliable stuff
if loose:
# Try again with loose testing
quality = self.guessLoose(hash, extra = extra)
if quality:
return self.setCache(hash, quality)
log.debug('Could not identify quality for: %s' % files)
return None
def guessLoose(self, hash, extra):
for quality in self.all():
# Last check on resolution only
if quality.get('width', 480) == extra.get('resolution_width', 0):
log.debug('Found %s via resolution_width: %s == %s' % (quality['identifier'], quality.get('width', 480), extra.get('resolution_width', 0)))
return self.setCache(hash, quality)
# Check extension + filesize
if list(set(quality.get('ext', [])) & set(words)) and size >= quality['size_min'] and size <= quality['size_max']:
log.debug('Found %s via ext and filesize %s in %s' % (quality['identifier'], quality.get('ext'), words))
return self.setCache(hash, quality)
# Try again with loose testing
if not loose:
quality = self.guess(files, extra = extra, loose = True)
if quality:
return self.setCache(hash, quality)
if 480 <= extra.get('resolution_width', 0) <= 720:
log.debug('Found as dvdrip')
return self.setCache(hash, self.single('dvdrip'))
log.debug('Could not identify quality for: %s' % files)
return None

30
couchpotato/core/plugins/renamer/main.py

@ -6,7 +6,7 @@ from couchpotato.core.helpers.request import jsonified
from couchpotato.core.helpers.variable import getExt, mergeDicts
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.core.settings.model import Library, File
from couchpotato.core.settings.model import Library, File, Profile
from couchpotato.environment import Env
import os
import re
@ -67,6 +67,12 @@ class Renamer(Plugin):
nfo_name = self.conf('nfo_name')
separator = self.conf('separator')
# Statusses
done_status = fireEvent('status.get', 'done', single = True)
active_status = fireEvent('status.get', 'active', single = True)
downloaded_status = fireEvent('status.get', 'downloaded', single = True)
snatched_status = fireEvent('status.get', 'snatched', single = True)
db = get_session()
for group_identifier in groups:
@ -240,10 +246,15 @@ class Renamer(Plugin):
cd += 1
# Before renaming, remove the lower quality files
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
remove_leftovers = True
# Add it to the wanted list before we continue
if len(library.movies) == 0:
profile = db.query(Profile).filter_by(core = True, label = group['meta_data']['quality']['label']).first()
fireEvent('movie.add', params = {'identifier': group['library']['identifier'], 'profile_id': profile.id}, search_after = False)
db.expire_all()
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
done_status = fireEvent('status.get', 'done', single = True)
active_status = fireEvent('status.get', 'active', single = True)
for movie in library.movies:
@ -293,14 +304,25 @@ class Renamer(Plugin):
# Notify on rename fail
download_message = 'Renaming of %s (%s) canceled, exists in %s already.' % (movie.library.titles[0].title, group['meta_data']['quality']['label'], release.quality.label)
fireEvent('movie.renaming.canceled', message = download_message, data = group)
remove_leftovers = False
break
elif release.status_id is snatched_status.get('id'):
print release.quality.label, group['meta_data']['quality']['label']
if release.quality.id is group['meta_data']['quality']['id']:
log.debug('Marking release as downloaded')
release.status_id = downloaded_status.get('id')
db.commit()
# Remove leftover files
if self.conf('cleanup') and not self.conf('move_leftover'):
if self.conf('cleanup') and not self.conf('move_leftover') and remove_leftovers:
log.debug('Removing leftover files')
for current_file in group['files']['leftover']:
remove_files.append(current_file)
elif not remove_leftovers: # Don't remove anything
remove_files = []
continue
# Rename all files marked
group['renamed_files'] = []

Loading…
Cancel
Save