diff --git a/couchpotato/core/notifications/base.py b/couchpotato/core/notifications/base.py index 85c762e4..3965973f 100644 --- a/couchpotato/core/notifications/base.py +++ b/couchpotato/core/notifications/base.py @@ -12,15 +12,19 @@ class Notification(Plugin): default_title = 'CouchPotato' test_message = 'ZOMG Lazors Pewpewpew!' - listen_to = [] + listen_to = ['movie.downloaded', 'movie.snatched'] dont_listen_to = [] def __init__(self): - addEvent('notify', self.notify) addEvent('notify.%s' % self.getName().lower(), self.notify) addApiView(self.testNotifyName(), self.test) + # Attach listeners + for listener in self.listen_to: + if not listener in self.dont_listen_to: + addEvent(listener, self.notify) + def notify(self, message = '', data = {}, type = ''): pass @@ -36,12 +40,7 @@ class Notification(Plugin): type = test_type ) - #return jsonified({'success': success}) - - def dontNotify(self, type = ''): - return (not type in self.listen_to and len(self.listen_to) == 0 and type != self.testNotifyName()) \ - or type in self.dont_listen_to \ - or self.isDisabled() + return jsonified({'success': success}) def testNotifyName(self): return 'notify.%s.test' % self.getName().lower() diff --git a/couchpotato/core/notifications/core/main.py b/couchpotato/core/notifications/core/main.py index 1b1d6288..a5a478b2 100644 --- a/couchpotato/core/notifications/core/main.py +++ b/couchpotato/core/notifications/core/main.py @@ -27,7 +27,7 @@ class CoreNotifier(Notification): # Library update, frontend refresh addEvent('library.update_finish', lambda data: fireEvent('notify.frontend', type = 'library.update', data = data)) - def notify(self, message = '', data = {}, type = None): + def notify(self, message = '', data = {}): self.add(data = { 'message': message, 'raw': data, diff --git a/couchpotato/core/notifications/growl/main.py b/couchpotato/core/notifications/growl/main.py index 76d44936..b46a8de8 100644 --- a/couchpotato/core/notifications/growl/main.py +++ b/couchpotato/core/notifications/growl/main.py @@ -12,13 +12,10 @@ log = CPLog(__name__) class Growl(Notification): - listen_to = ['movie.downloaded', 'movie.snatched'] - def conf(self, attr): return Env.setting(attr, 'growl') - def notify(self, message = '', data = {}, type = None): - if self.dontNotify(type): return + def notify(self, message = '', data = {}): hosts = [x.strip() for x in self.conf('host').split(",")] password = self.conf('password') diff --git a/couchpotato/core/notifications/history/main.py b/couchpotato/core/notifications/history/main.py index 05d38b8d..c56ad23d 100644 --- a/couchpotato/core/notifications/history/main.py +++ b/couchpotato/core/notifications/history/main.py @@ -10,7 +10,7 @@ log = CPLog(__name__) class History(Notification): - listen_to = ['movie.downloaded', 'movie.snatched', 'movie.renaming.'] + listen_to = ['movie.downloaded', 'movie.snatched', 'renamer.canceled'] def __init__(self): @@ -19,8 +19,7 @@ class History(Notification): addEvent('app.load', self.test) - def notify(self, message = '', data = {}, type = None): - if self.dontNotify(type): return + def notify(self, message = '', data = {}): db = get_session() history = Hist( diff --git a/couchpotato/core/notifications/nmj/main.py b/couchpotato/core/notifications/nmj/main.py index 32c143e2..6b322ded 100644 --- a/couchpotato/core/notifications/nmj/main.py +++ b/couchpotato/core/notifications/nmj/main.py @@ -18,8 +18,6 @@ log = CPLog(__name__) class NMJ(Notification): - listen_to = ['movie.downloaded', 'movie.snatched'] - def __init__(self): super(NMJ, self).__init__() @@ -75,8 +73,7 @@ class NMJ(Notification): 'mount': mount, }) - def notify(self, message = '', data = {}, type = None): - if self.dontNotify(type): return + def notify(self, message = '', data = {}): host = self.conf('host') mount = self.conf('mount') diff --git a/couchpotato/core/notifications/notifo/main.py b/couchpotato/core/notifications/notifo/main.py index feafc3b4..fd462046 100644 --- a/couchpotato/core/notifications/notifo/main.py +++ b/couchpotato/core/notifications/notifo/main.py @@ -16,13 +16,10 @@ class Notifo(Notification): url = 'https://api.notifo.com/v1/send_notification' - listen_to = ['movie.downloaded', 'movie.snatched'] - def conf(self, attr): return Env.setting(attr, 'notifo') - def notify(self, message = '', data = {}, type = None): - if self.dontNotify(type): return + def notify(self, message = '', data = {}): try: data = urllib.urlencode({ diff --git a/couchpotato/core/notifications/notifymyandroid/main.py b/couchpotato/core/notifications/notifymyandroid/main.py index 860e7610..0c119346 100644 --- a/couchpotato/core/notifications/notifymyandroid/main.py +++ b/couchpotato/core/notifications/notifymyandroid/main.py @@ -7,10 +7,7 @@ log = CPLog(__name__) class NotifyMyAndroid(Notification): - listen_to = ['movie.downloaded', 'movie.snatched'] - - def notify(self, message = '', data = {}, type = None): - if self.dontNotify(type): return + def notify(self, message = '', data = {}): nma = pynma.PyNMA() keys = self.conf('api_key').split(',') diff --git a/couchpotato/core/notifications/plex/main.py b/couchpotato/core/notifications/plex/main.py index b93e114b..2008286a 100644 --- a/couchpotato/core/notifications/plex/main.py +++ b/couchpotato/core/notifications/plex/main.py @@ -10,10 +10,7 @@ log = CPLog(__name__) class Plex(Notification): - listen_to = ['movie.downloaded', 'movie.snatched'] - - def notify(self, message = '', data = {}, type = None): - if self.dontNotify(type): return + def notify(self, message = '', data = {}): log.info('Sending notification to Plex') hosts = [x.strip() for x in self.conf('host').split(",")] diff --git a/couchpotato/core/notifications/prowl/main.py b/couchpotato/core/notifications/prowl/main.py index a43ab5e9..3b851b39 100644 --- a/couchpotato/core/notifications/prowl/main.py +++ b/couchpotato/core/notifications/prowl/main.py @@ -9,10 +9,7 @@ log = CPLog(__name__) class Prowl(Notification): - listen_to = ['movie.downloaded', 'movie.snatched'] - - def notify(self, message = '', data = {}, type = None): - if self.dontNotify(type): return + def notify(self, message = '', data = {}): http_handler = HTTPSConnection('api.prowlapp.com') diff --git a/couchpotato/core/notifications/twitter/main.py b/couchpotato/core/notifications/twitter/main.py index 2b815796..8ba04ae8 100644 --- a/couchpotato/core/notifications/twitter/main.py +++ b/couchpotato/core/notifications/twitter/main.py @@ -10,8 +10,6 @@ log = CPLog(__name__) class Twitter(Notification): - listen_to = ['movie.downloaded', 'movie.snatched'] - consumer_key = "3POVsO3KW90LKZXyzPOjQ" consumer_secret = "Qprb94hx9ucXvD4Wvg2Ctsk4PDK7CcQAKgCELXoyIjE" @@ -21,8 +19,7 @@ class Twitter(Notification): 'authorize': 'https://api.twitter.com/oauth/authorize', } - def notify(self, message = '', data = {}, type = None): - if self.dontNotify(type): return + def notify(self, message = '', data = {}): api = Api(self.consumer_key, self.consumer_secret, self.conf('username'), self.conf('password')) diff --git a/couchpotato/core/notifications/xbmc/main.py b/couchpotato/core/notifications/xbmc/main.py index ead59b38..b9dcb03d 100644 --- a/couchpotato/core/notifications/xbmc/main.py +++ b/couchpotato/core/notifications/xbmc/main.py @@ -9,10 +9,7 @@ log = CPLog(__name__) class XBMC(Notification): - listen_to = ['movie.downloaded', 'movie.snatched'] - - def notify(self, message = '', data = {}, type = None): - if self.dontNotify(type): return + def notify(self, message = '', data = {}): for host in [x.strip() for x in self.conf('host').split(",")]: self.send({'command': 'ExecBuiltIn', 'parameter': 'Notification(CouchPotato, %s)' % message}, host) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 04bfa7f2..9ec86e3f 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -156,7 +156,7 @@ class Renamer(Plugin): # Notify on download download_message = 'Download of %s (%s) successful.' % (group['library']['titles'][0]['title'], replacements['quality']) - fireEvent('notify', type = 'movie.downloaded', message = download_message, data = group) + fireEvent('movie.downloaded', message = download_message, data = group) # Before renaming, remove the lower quality files db = get_session() @@ -184,7 +184,7 @@ 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('notify', type = 'movie.renaming.canceled', message = download_message, data = group) + fireEvent('movie.renaming.canceled', message = download_message, data = group) break diff --git a/couchpotato/core/plugins/searcher/main.py b/couchpotato/core/plugins/searcher/main.py index bef8faaa..93d85f35 100644 --- a/couchpotato/core/plugins/searcher/main.py +++ b/couchpotato/core/plugins/searcher/main.py @@ -108,7 +108,7 @@ class Searcher(Plugin): db.commit() log.info('Downloading of %s successful.' % nzb.get('name')) - fireEvent('notify', type = 'movie.snatched', message = 'Downloading of %s successful.' % nzb.get('name'), data = rls.to_dict()) + fireEvent('movie.snatched', message = 'Downloading of %s successful.' % nzb.get('name'), data = rls.to_dict()) return True @@ -117,6 +117,10 @@ class Searcher(Plugin): log.info('Better quality (%s) already available or snatched for %s' % (type['quality']['label'], default_title)) break + # Break if CP wants to shut down + if self.shuttingDown(): + break + return False