From 050d8ccfdabb712e6a7ae51afaae2f390f3f4ab7 Mon Sep 17 00:00:00 2001 From: Dean Gardiner Date: Fri, 25 Jul 2014 11:58:27 +1200 Subject: [PATCH] Added "library.root" event, fixes to "matcher", "release" and "score" to use "library.root" + handle missing "year" --- couchpotato/core/media/_base/library/main.py | 10 ++++++++++ couchpotato/core/media/_base/matcher/main.py | 6 +++--- couchpotato/core/plugins/release/main.py | 2 +- couchpotato/core/plugins/score/main.py | 2 +- couchpotato/core/plugins/score/scores.py | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/couchpotato/core/media/_base/library/main.py b/couchpotato/core/media/_base/library/main.py index 2eccfce6..b90f4c38 100644 --- a/couchpotato/core/media/_base/library/main.py +++ b/couchpotato/core/media/_base/library/main.py @@ -11,6 +11,7 @@ class Library(LibraryBase): def __init__(self): addEvent('library.title', self.title) addEvent('library.related', self.related) + addEvent('library.root', self.root) addApiView('library.query', self.queryView) addApiView('library.related', self.relatedView) @@ -54,3 +55,12 @@ class Library(LibraryBase): result[cur['type']] = cur return result + + def root(self, media): + db = get_db() + cur = media + + while cur and cur.get('parent_id'): + cur = db.get('id', cur['parent_id']) + + return cur diff --git a/couchpotato/core/media/_base/matcher/main.py b/couchpotato/core/media/_base/matcher/main.py index 2034249b..64e13ae6 100644 --- a/couchpotato/core/media/_base/matcher/main.py +++ b/couchpotato/core/media/_base/matcher/main.py @@ -40,7 +40,7 @@ class Matcher(MatcherBase): return False def correctTitle(self, chain, media): - root_library = media['library']['root_library'] + root = fireEvent('library.root', media, single = True) if 'show_name' not in chain.info or not len(chain.info['show_name']): log.info('Wrong: missing show name in parsed result') @@ -50,10 +50,10 @@ class Matcher(MatcherBase): chain_words = [x.lower() for x in chain.info['show_name']] # Build a list of possible titles of the media we are searching for - titles = root_library['info']['titles'] + titles = root['info']['titles'] # Add year suffix titles (will result in ['', ' ', '', ...]) - suffixes = [None, root_library['info']['year']] + suffixes = [None, root['info']['year']] titles = [ title + ((' %s' % suffix) if suffix else '') diff --git a/couchpotato/core/plugins/release/main.py b/couchpotato/core/plugins/release/main.py index 08f02480..7f389f2b 100644 --- a/couchpotato/core/plugins/release/main.py +++ b/couchpotato/core/plugins/release/main.py @@ -315,7 +315,7 @@ class Release(Plugin): rls['download_info'] = download_result db.update(rls) - log_movie = '%s (%s) in %s' % (getTitle(media), media['info']['year'], rls['quality']) + log_movie = '%s (%s) in %s' % (getTitle(media), media['info'].get('year'), rls['quality']) snatch_message = 'Snatched "%s": %s' % (data.get('name'), log_movie) log.info(snatch_message) fireEvent('%s.snatched' % data['type'], message = snatch_message, data = rls) diff --git a/couchpotato/core/plugins/score/main.py b/couchpotato/core/plugins/score/main.py index e6fef253..08a18551 100644 --- a/couchpotato/core/plugins/score/main.py +++ b/couchpotato/core/plugins/score/main.py @@ -24,7 +24,7 @@ class Score(Plugin): try: preferred_words = removeDuplicate(preferred_words + splitString(movie['category']['preferred'].lower())) except: pass - score = nameScore(toUnicode(nzb['name']), movie['info']['year'], preferred_words) + score = nameScore(toUnicode(nzb['name']), movie['info'].get('year'), preferred_words) for movie_title in movie['info']['titles']: score += nameRatioScore(toUnicode(nzb['name']), toUnicode(movie_title)) diff --git a/couchpotato/core/plugins/score/scores.py b/couchpotato/core/plugins/score/scores.py index a53608c0..ddae4305 100644 --- a/couchpotato/core/plugins/score/scores.py +++ b/couchpotato/core/plugins/score/scores.py @@ -44,7 +44,7 @@ def nameScore(name, year, preferred_words): score += add # points if the year is correct - if str(year) in name: + if year and str(year) in name: score += 5 # Contains preferred word