diff --git a/couchpotato/core/plugins/movie/main.py b/couchpotato/core/plugins/movie/main.py index 0a99fe6..4b595dc 100644 --- a/couchpotato/core/plugins/movie/main.py +++ b/couchpotato/core/plugins/movie/main.py @@ -108,9 +108,8 @@ class MoviePlugin(Plugin): now = time.time() week = 262080 - done_status = fireEvent('status.get', 'done', single = True) - available_status = fireEvent('status.get', 'available', single = True) - snatched_status = fireEvent('status.get', 'snatched', single = True) + done_status, available_status, snatched_status = \ + fireEvent('status.get', ['done', 'available', 'snatched'], single = True) db = get_session() @@ -367,11 +366,8 @@ class MoviePlugin(Plugin): library = fireEvent('library.add', single = True, attrs = params, update_after = update_library) # Status - status_active = fireEvent('status.add', 'active', single = True) - snatched_status = fireEvent('status.add', 'snatched', single = True) - ignored_status = fireEvent('status.add', 'ignored', single = True) - done_status = fireEvent('status.add', 'done', single = True) - downloaded_status = fireEvent('status.add', 'downloaded', single = True) + status_active, snatched_status, ignored_status, done_status, downloaded_status = \ + fireEvent('status.get', ['active', 'snatched', 'ignored', 'done', 'downloaded'], single = True) default_profile = fireEvent('profile.default', single = True) @@ -549,8 +545,7 @@ class MoviePlugin(Plugin): def restatus(self, movie_id): - active_status = fireEvent('status.get', 'active', single = True) - done_status = fireEvent('status.get', 'done', single = True) + active_status, done_status = fireEvent('status.get', ['active', 'done'], single = True) db = get_session() diff --git a/couchpotato/core/plugins/release/main.py b/couchpotato/core/plugins/release/main.py index 5c4d39f..4967bce 100644 --- a/couchpotato/core/plugins/release/main.py +++ b/couchpotato/core/plugins/release/main.py @@ -46,8 +46,10 @@ class Release(Plugin): identifier = '%s.%s.%s' % (group['library']['identifier'], group['meta_data'].get('audio', 'unknown'), group['meta_data']['quality']['identifier']) + + done_status, snatched_status = fireEvent('status.get', ['done', 'snatched'], single = True) + # Add movie - done_status = fireEvent('status.get', 'done', single = True) movie = db.query(Movie).filter_by(library_id = group['library'].get('id')).first() if not movie: movie = Movie( @@ -59,7 +61,6 @@ class Release(Plugin): db.commit() # Add Release - snatched_status = fireEvent('status.get', 'snatched', single = True) rel = db.query(Relea).filter( or_( Relea.identifier == identifier, @@ -152,8 +153,7 @@ class Release(Plugin): rel = db.query(Relea).filter_by(id = id).first() if rel: - ignored_status = fireEvent('status.get', 'ignored', single = True) - available_status = fireEvent('status.get', 'available', single = True) + ignored_status, available_status = fireEvent('status.get', ['ignored', 'available'], single = True) rel.status_id = available_status.get('id') if rel.status_id is ignored_status.get('id') else ignored_status.get('id') db.commit() @@ -166,8 +166,7 @@ class Release(Plugin): db = get_session() id = getParam('id') - snatched_status = fireEvent('status.add', 'snatched', single = True) - done_status = fireEvent('status.get', 'done', single = True) + snatched_status, done_status = fireEvent('status.get', ['snatched', 'done'], single = True) rel = db.query(Relea).filter_by(id = id).first() if rel: diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 1a8be7a..5e886fb 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -131,10 +131,8 @@ class Renamer(Plugin): 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) + done_status, active_status, downloaded_status, snatched_status = \ + fireEvent('status.get', ['done', 'active', 'downloaded', 'snatched'], single = True) for group_identifier in groups: @@ -588,11 +586,8 @@ Remove it if you want it to be renamed (again, or at least let it try again) self.checking_snatched = True - snatched_status = fireEvent('status.get', 'snatched', single = True) - ignored_status = fireEvent('status.get', 'ignored', single = True) - failed_status = fireEvent('status.get', 'failed', single = True) - - done_status = fireEvent('status.get', 'done', single = True) + snatched_status, ignored_status, failed_status, done_status = \ + fireEvent('status.get', ['snatched', 'ignored', 'failed', 'done'], single = True) db = get_session() rels = db.query(Release).filter_by(status_id = snatched_status.get('id')).all() diff --git a/couchpotato/core/plugins/searcher/main.py b/couchpotato/core/plugins/searcher/main.py index e6e8174..dba0ea7 100644 --- a/couchpotato/core/plugins/searcher/main.py +++ b/couchpotato/core/plugins/searcher/main.py @@ -146,8 +146,7 @@ class Searcher(Plugin): pre_releases = fireEvent('quality.pre_releases', single = True) release_dates = fireEvent('library.update_release_date', identifier = movie['library']['identifier'], merge = True) - available_status = fireEvent('status.get', 'available', single = True) - ignored_status = fireEvent('status.get', 'ignored', single = True) + available_status, ignored_status = fireEvent('status.get', ['available', 'ignored'], single = True) found_releases = [] diff --git a/couchpotato/core/plugins/status/main.py b/couchpotato/core/plugins/status/main.py index f9fb513..c496c2d 100644 --- a/couchpotato/core/plugins/status/main.py +++ b/couchpotato/core/plugins/status/main.py @@ -28,12 +28,11 @@ class StatusPlugin(Plugin): status_cached = {} def __init__(self): - addEvent('status.add', self.add) - addEvent('status.get', self.add) # Alias for .add + addEvent('status.get', self.get) addEvent('status.get_by_id', self.getById) addEvent('status.all', self.all) addEvent('app.initialize', self.fill) - addEvent('app.load', self.all) + addEvent('app.load', self.all) # Cache all statuses addApiView('status.list', self.list, docs = { 'desc': 'Check for available update', @@ -74,26 +73,35 @@ class StatusPlugin(Plugin): return temp - def add(self, identifier): + def get(self, identifiers): - if self.status_cached.get(identifier): - return self.status_cached.get(identifier) + if not isinstance(identifiers, (list)): + identifiers = [identifiers] db = get_session() + return_list = [] - s = db.query(Status).filter_by(identifier = identifier).first() - if not s: - s = Status( - identifier = identifier, - label = toUnicode(identifier.capitalize()) - ) - db.add(s) - db.commit() + for identifier in identifiers: - status_dict = s.to_dict() + if self.status_cached.get(identifier): + return_list.append(self.status_cached.get(identifier)) + continue - self.status_cached[identifier] = status_dict - return status_dict + s = db.query(Status).filter_by(identifier = identifier).first() + if not s: + s = Status( + identifier = identifier, + label = toUnicode(identifier.capitalize()) + ) + db.add(s) + db.commit() + + status_dict = s.to_dict() + + self.status_cached[identifier] = status_dict + return_list.append(status_dict) + + return return_list if len(identifiers) > 1 else return_list[0] def fill(self): diff --git a/couchpotato/core/providers/movie/_modifier/main.py b/couchpotato/core/providers/movie/_modifier/main.py index f0f98e0..12d1e32 100644 --- a/couchpotato/core/providers/movie/_modifier/main.py +++ b/couchpotato/core/providers/movie/_modifier/main.py @@ -52,8 +52,7 @@ class MovieResultModifier(Plugin): if l: # Statuses - active_status = fireEvent('status.get', 'active', single = True) - done_status = fireEvent('status.get', 'done', single = True) + active_status, done_status = fireEvent('status.get', ['active', 'done'], single = True) for movie in l.movies: if movie.status_id == active_status['id']: