Simpler notifications
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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(',')
|
||||
|
||||
@@ -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(",")]
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -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'))
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user