Simpler notifications
This commit is contained in:
@@ -12,15 +12,19 @@ class Notification(Plugin):
|
|||||||
default_title = 'CouchPotato'
|
default_title = 'CouchPotato'
|
||||||
test_message = 'ZOMG Lazors Pewpewpew!'
|
test_message = 'ZOMG Lazors Pewpewpew!'
|
||||||
|
|
||||||
listen_to = []
|
listen_to = ['movie.downloaded', 'movie.snatched']
|
||||||
dont_listen_to = []
|
dont_listen_to = []
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
addEvent('notify', self.notify)
|
|
||||||
addEvent('notify.%s' % self.getName().lower(), self.notify)
|
addEvent('notify.%s' % self.getName().lower(), self.notify)
|
||||||
|
|
||||||
addApiView(self.testNotifyName(), self.test)
|
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 = ''):
|
def notify(self, message = '', data = {}, type = ''):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -36,12 +40,7 @@ class Notification(Plugin):
|
|||||||
type = test_type
|
type = test_type
|
||||||
)
|
)
|
||||||
|
|
||||||
#return jsonified({'success': success})
|
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()
|
|
||||||
|
|
||||||
def testNotifyName(self):
|
def testNotifyName(self):
|
||||||
return 'notify.%s.test' % self.getName().lower()
|
return 'notify.%s.test' % self.getName().lower()
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class CoreNotifier(Notification):
|
|||||||
# Library update, frontend refresh
|
# Library update, frontend refresh
|
||||||
addEvent('library.update_finish', lambda data: fireEvent('notify.frontend', type = 'library.update', data = data))
|
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 = {
|
self.add(data = {
|
||||||
'message': message,
|
'message': message,
|
||||||
'raw': data,
|
'raw': data,
|
||||||
|
|||||||
@@ -12,13 +12,10 @@ log = CPLog(__name__)
|
|||||||
|
|
||||||
class Growl(Notification):
|
class Growl(Notification):
|
||||||
|
|
||||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
|
||||||
|
|
||||||
def conf(self, attr):
|
def conf(self, attr):
|
||||||
return Env.setting(attr, 'growl')
|
return Env.setting(attr, 'growl')
|
||||||
|
|
||||||
def notify(self, message = '', data = {}, type = None):
|
def notify(self, message = '', data = {}):
|
||||||
if self.dontNotify(type): return
|
|
||||||
|
|
||||||
hosts = [x.strip() for x in self.conf('host').split(",")]
|
hosts = [x.strip() for x in self.conf('host').split(",")]
|
||||||
password = self.conf('password')
|
password = self.conf('password')
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ log = CPLog(__name__)
|
|||||||
|
|
||||||
class History(Notification):
|
class History(Notification):
|
||||||
|
|
||||||
listen_to = ['movie.downloaded', 'movie.snatched', 'movie.renaming.']
|
listen_to = ['movie.downloaded', 'movie.snatched', 'renamer.canceled']
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
@@ -19,8 +19,7 @@ class History(Notification):
|
|||||||
addEvent('app.load', self.test)
|
addEvent('app.load', self.test)
|
||||||
|
|
||||||
|
|
||||||
def notify(self, message = '', data = {}, type = None):
|
def notify(self, message = '', data = {}):
|
||||||
if self.dontNotify(type): return
|
|
||||||
|
|
||||||
db = get_session()
|
db = get_session()
|
||||||
history = Hist(
|
history = Hist(
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ log = CPLog(__name__)
|
|||||||
|
|
||||||
class NMJ(Notification):
|
class NMJ(Notification):
|
||||||
|
|
||||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(NMJ, self).__init__()
|
super(NMJ, self).__init__()
|
||||||
|
|
||||||
@@ -75,8 +73,7 @@ class NMJ(Notification):
|
|||||||
'mount': mount,
|
'mount': mount,
|
||||||
})
|
})
|
||||||
|
|
||||||
def notify(self, message = '', data = {}, type = None):
|
def notify(self, message = '', data = {}):
|
||||||
if self.dontNotify(type): return
|
|
||||||
|
|
||||||
host = self.conf('host')
|
host = self.conf('host')
|
||||||
mount = self.conf('mount')
|
mount = self.conf('mount')
|
||||||
|
|||||||
@@ -16,13 +16,10 @@ class Notifo(Notification):
|
|||||||
|
|
||||||
url = 'https://api.notifo.com/v1/send_notification'
|
url = 'https://api.notifo.com/v1/send_notification'
|
||||||
|
|
||||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
|
||||||
|
|
||||||
def conf(self, attr):
|
def conf(self, attr):
|
||||||
return Env.setting(attr, 'notifo')
|
return Env.setting(attr, 'notifo')
|
||||||
|
|
||||||
def notify(self, message = '', data = {}, type = None):
|
def notify(self, message = '', data = {}):
|
||||||
if self.dontNotify(type): return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = urllib.urlencode({
|
data = urllib.urlencode({
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ log = CPLog(__name__)
|
|||||||
|
|
||||||
class NotifyMyAndroid(Notification):
|
class NotifyMyAndroid(Notification):
|
||||||
|
|
||||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
def notify(self, message = '', data = {}):
|
||||||
|
|
||||||
def notify(self, message = '', data = {}, type = None):
|
|
||||||
if self.dontNotify(type): return
|
|
||||||
|
|
||||||
nma = pynma.PyNMA()
|
nma = pynma.PyNMA()
|
||||||
keys = self.conf('api_key').split(',')
|
keys = self.conf('api_key').split(',')
|
||||||
|
|||||||
@@ -10,10 +10,7 @@ log = CPLog(__name__)
|
|||||||
|
|
||||||
class Plex(Notification):
|
class Plex(Notification):
|
||||||
|
|
||||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
def notify(self, message = '', data = {}):
|
||||||
|
|
||||||
def notify(self, message = '', data = {}, type = None):
|
|
||||||
if self.dontNotify(type): return
|
|
||||||
|
|
||||||
log.info('Sending notification to Plex')
|
log.info('Sending notification to Plex')
|
||||||
hosts = [x.strip() for x in self.conf('host').split(",")]
|
hosts = [x.strip() for x in self.conf('host').split(",")]
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ log = CPLog(__name__)
|
|||||||
|
|
||||||
class Prowl(Notification):
|
class Prowl(Notification):
|
||||||
|
|
||||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
def notify(self, message = '', data = {}):
|
||||||
|
|
||||||
def notify(self, message = '', data = {}, type = None):
|
|
||||||
if self.dontNotify(type): return
|
|
||||||
|
|
||||||
http_handler = HTTPSConnection('api.prowlapp.com')
|
http_handler = HTTPSConnection('api.prowlapp.com')
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ log = CPLog(__name__)
|
|||||||
|
|
||||||
class Twitter(Notification):
|
class Twitter(Notification):
|
||||||
|
|
||||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
|
||||||
|
|
||||||
consumer_key = "3POVsO3KW90LKZXyzPOjQ"
|
consumer_key = "3POVsO3KW90LKZXyzPOjQ"
|
||||||
consumer_secret = "Qprb94hx9ucXvD4Wvg2Ctsk4PDK7CcQAKgCELXoyIjE"
|
consumer_secret = "Qprb94hx9ucXvD4Wvg2Ctsk4PDK7CcQAKgCELXoyIjE"
|
||||||
|
|
||||||
@@ -21,8 +19,7 @@ class Twitter(Notification):
|
|||||||
'authorize': 'https://api.twitter.com/oauth/authorize',
|
'authorize': 'https://api.twitter.com/oauth/authorize',
|
||||||
}
|
}
|
||||||
|
|
||||||
def notify(self, message = '', data = {}, type = None):
|
def notify(self, message = '', data = {}):
|
||||||
if self.dontNotify(type): return
|
|
||||||
|
|
||||||
api = Api(self.consumer_key, self.consumer_secret, self.conf('username'), self.conf('password'))
|
api = Api(self.consumer_key, self.consumer_secret, self.conf('username'), self.conf('password'))
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ log = CPLog(__name__)
|
|||||||
|
|
||||||
class XBMC(Notification):
|
class XBMC(Notification):
|
||||||
|
|
||||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
def notify(self, message = '', data = {}):
|
||||||
|
|
||||||
def notify(self, message = '', data = {}, type = None):
|
|
||||||
if self.dontNotify(type): return
|
|
||||||
|
|
||||||
for host in [x.strip() for x in self.conf('host').split(",")]:
|
for host in [x.strip() for x in self.conf('host').split(",")]:
|
||||||
self.send({'command': 'ExecBuiltIn', 'parameter': 'Notification(CouchPotato, %s)' % message}, host)
|
self.send({'command': 'ExecBuiltIn', 'parameter': 'Notification(CouchPotato, %s)' % message}, host)
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ class Renamer(Plugin):
|
|||||||
|
|
||||||
# Notify on download
|
# Notify on download
|
||||||
download_message = 'Download of %s (%s) successful.' % (group['library']['titles'][0]['title'], replacements['quality'])
|
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
|
# Before renaming, remove the lower quality files
|
||||||
db = get_session()
|
db = get_session()
|
||||||
@@ -184,7 +184,7 @@ class Renamer(Plugin):
|
|||||||
|
|
||||||
# Notify on rename fail
|
# 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)
|
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
|
break
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class Searcher(Plugin):
|
|||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
log.info('Downloading of %s successful.' % nzb.get('name'))
|
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
|
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))
|
log.info('Better quality (%s) already available or snatched for %s' % (type['quality']['label'], default_title))
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# Break if CP wants to shut down
|
||||||
|
if self.shuttingDown():
|
||||||
|
break
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user