From d3ebe531d578e7f495144eb73b3480686ed77a57 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 14 Oct 2012 14:13:10 +0200 Subject: [PATCH] Don't use 2 events after rename --- couchpotato/core/notifications/base.py | 6 +++--- couchpotato/core/notifications/core/main.py | 2 +- couchpotato/core/notifications/nmj/main.py | 8 ++++---- couchpotato/core/notifications/plex/main.py | 2 +- couchpotato/core/notifications/synoindex/main.py | 2 +- couchpotato/core/notifications/xbmc/main.py | 4 ++-- couchpotato/core/plugins/manage/main.py | 3 +-- couchpotato/core/plugins/renamer/main.py | 7 ++----- couchpotato/core/plugins/trailer/main.py | 2 +- couchpotato/core/providers/metadata/base.py | 12 ++++++------ 10 files changed, 22 insertions(+), 26 deletions(-) diff --git a/couchpotato/core/notifications/base.py b/couchpotato/core/notifications/base.py index c1c6350..52582b5 100644 --- a/couchpotato/core/notifications/base.py +++ b/couchpotato/core/notifications/base.py @@ -14,7 +14,7 @@ class Notification(Plugin): test_message = 'ZOMG Lazors Pewpewpew!' listen_to = [ - 'movie.downloaded', 'movie.snatched', + 'renamer.after', 'movie.snatched', 'updater.available', 'updater.updated', ] dont_listen_to = [] @@ -30,10 +30,10 @@ class Notification(Plugin): addEvent(listener, self.createNotifyHandler(listener)) def createNotifyHandler(self, listener): - def notify(message, data): + def notify(message = None, group = {}): if not self.conf('on_snatch', default = True) and listener == 'movie.snatched': return - return self.notify(message = message, data = data, listener = listener) + return self.notify(message = message, data = group, listener = listener) return notify diff --git a/couchpotato/core/notifications/core/main.py b/couchpotato/core/notifications/core/main.py index 33f90d5..f965b92 100644 --- a/couchpotato/core/notifications/core/main.py +++ b/couchpotato/core/notifications/core/main.py @@ -22,7 +22,7 @@ class CoreNotifier(Notification): listeners = [] listen_to = [ - 'movie.downloaded', 'movie.snatched', + 'renamer.after', 'movie.snatched', 'updater.available', 'updater.updated', ] diff --git a/couchpotato/core/notifications/nmj/main.py b/couchpotato/core/notifications/nmj/main.py index 1a794fb..cdf531d 100644 --- a/couchpotato/core/notifications/nmj/main.py +++ b/couchpotato/core/notifications/nmj/main.py @@ -69,7 +69,7 @@ class NMJ(Notification): 'mount': mount, }) - def addToLibrary(self, group = {}): + def addToLibrary(self, message = None, group = {}): if self.isDisabled(): return host = self.conf('host') @@ -114,8 +114,8 @@ class NMJ(Notification): def failed(self): return jsonified({'success': False}) - + def test(self): return jsonified({'success': self.addToLibrary()}) - - + + diff --git a/couchpotato/core/notifications/plex/main.py b/couchpotato/core/notifications/plex/main.py index fed9f5e..9790ccf 100644 --- a/couchpotato/core/notifications/plex/main.py +++ b/couchpotato/core/notifications/plex/main.py @@ -17,7 +17,7 @@ class Plex(Notification): super(Plex, self).__init__() addEvent('renamer.after', self.addToLibrary) - def addToLibrary(self, group = {}): + def addToLibrary(self, message = None, group = {}): if self.isDisabled(): return log.info('Sending notification to Plex') diff --git a/couchpotato/core/notifications/synoindex/main.py b/couchpotato/core/notifications/synoindex/main.py index 6c4966d..01bd2fc 100644 --- a/couchpotato/core/notifications/synoindex/main.py +++ b/couchpotato/core/notifications/synoindex/main.py @@ -16,7 +16,7 @@ class Synoindex(Notification): super(Synoindex, self).__init__() addEvent('renamer.after', self.addToLibrary) - def addToLibrary(self, group = {}): + def addToLibrary(self, message = None, group = {}): if self.isDisabled(): return command = [self.index_path, '-A', group.get('destination_dir')] diff --git a/couchpotato/core/notifications/xbmc/main.py b/couchpotato/core/notifications/xbmc/main.py index 1c83bdd..f59de60 100644 --- a/couchpotato/core/notifications/xbmc/main.py +++ b/couchpotato/core/notifications/xbmc/main.py @@ -8,7 +8,7 @@ log = CPLog(__name__) class XBMC(Notification): - listen_to = ['movie.downloaded'] + listen_to = ['renamer.after'] def notify(self, message = '', data = {}, listener = None): if self.isDisabled(): return @@ -21,7 +21,7 @@ class XBMC(Notification): if self.send({'command': 'ExecBuiltIn', 'parameter': 'XBMC.updatelibrary(video)'}, host): successful += 1 - return successful == len(hosts)*2 + return successful == len(hosts) * 2 def send(self, command, host): diff --git a/couchpotato/core/plugins/manage/main.py b/couchpotato/core/plugins/manage/main.py index a5d41fd..c5f3828 100644 --- a/couchpotato/core/plugins/manage/main.py +++ b/couchpotato/core/plugins/manage/main.py @@ -22,10 +22,9 @@ class Manage(Plugin): fireEvent('scheduler.interval', identifier = 'manage.update_library', handle = self.updateLibrary, hours = 2) addEvent('manage.update', self.updateLibrary) - addEvent('manage.scan_files', self.scanFilesToLibrary) # Add files after renaming - def after_rename(group): + def after_rename(message = None, group = {}): return self.scanFilesToLibrary(folder = group['destination_dir'], files = group['renamed_files']) addEvent('renamer.after', after_rename) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 993575c..60692a5 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -377,12 +377,9 @@ class Renamer(Plugin): except: log.error('Failed removing %s: %s', (group['parentdir'], traceback.format_exc())) - # Search for trailers etc - fireEventAsync('renamer.after', group) - - # Notify on download + # Notify on download, search for trailers etc download_message = 'Downloaded %s (%s)' % (movie_title, replacements['quality']) - fireEventAsync('movie.downloaded', message = download_message, data = group) + fireEventAsync('renamer.after', message = download_message, group = group) # Break if CP wants to shut down if self.shuttingDown(): diff --git a/couchpotato/core/plugins/trailer/main.py b/couchpotato/core/plugins/trailer/main.py index 0524684..8b9f1e1 100644 --- a/couchpotato/core/plugins/trailer/main.py +++ b/couchpotato/core/plugins/trailer/main.py @@ -12,7 +12,7 @@ class Trailer(Plugin): def __init__(self): addEvent('renamer.after', self.searchSingle) - def searchSingle(self, group): + def searchSingle(self, message = None, group = {}): if self.isDisabled() or len(group['files']['trailer']) > 0: return diff --git a/couchpotato/core/providers/metadata/base.py b/couchpotato/core/providers/metadata/base.py index cf2e303..078d7e1 100644 --- a/couchpotato/core/providers/metadata/base.py +++ b/couchpotato/core/providers/metadata/base.py @@ -16,23 +16,23 @@ class MetaDataBase(Plugin): def __init__(self): addEvent('renamer.after', self.create) - def create(self, release): + def create(self, message = None, group = {}): if self.isDisabled(): return log.info('Creating %s metadata.', self.getName()) # Update library to get latest info try: - updated_library = fireEvent('library.update', release['library']['identifier'], force = True, single = True) - release['library'] = mergeDicts(release['library'], updated_library) + updated_library = fireEvent('library.update', group['library']['identifier'], force = True, single = True) + group['library'] = mergeDicts(group['library'], updated_library) except: log.error('Failed to update movie, before creating metadata: %s', traceback.format_exc()) - root_name = self.getRootName(release) + root_name = self.getRootName(group) meta_name = os.path.basename(root_name) root = os.path.dirname(root_name) - movie_info = release['library'].get('info') + movie_info = group['library'].get('info') for file_type in ['nfo', 'thumbnail', 'fanart']: try: @@ -42,7 +42,7 @@ class MetaDataBase(Plugin): if name and self.conf('meta_' + file_type): # Get file content - content = getattr(self, 'get' + file_type.capitalize())(movie_info = movie_info, data = release) + content = getattr(self, 'get' + file_type.capitalize())(movie_info = movie_info, data = group) if content: log.debug('Creating %s file: %s', (file_type, name)) if os.path.isfile(content):