51 changed files with 1600 additions and 1656 deletions
@ -1,34 +0,0 @@ |
|||
from .main import Boxcar |
|||
|
|||
|
|||
def start(): |
|||
return Boxcar() |
|||
|
|||
config = [{ |
|||
'name': 'boxcar', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'notifications', |
|||
'list': 'notification_providers', |
|||
'name': 'boxcar', |
|||
'options': [ |
|||
{ |
|||
'name': 'enabled', |
|||
'default': 0, |
|||
'type': 'enabler', |
|||
}, |
|||
{ |
|||
'name': 'email', |
|||
'description': 'Your Boxcar registration emailaddress.' |
|||
}, |
|||
{ |
|||
'name': 'on_snatch', |
|||
'default': 0, |
|||
'type': 'bool', |
|||
'advanced': True, |
|||
'description': 'Also send message when movie is snatched.', |
|||
}, |
|||
], |
|||
} |
|||
], |
|||
}] |
@ -1,34 +0,0 @@ |
|||
from .main import Boxcar2 |
|||
|
|||
|
|||
def start(): |
|||
return Boxcar2() |
|||
|
|||
config = [{ |
|||
'name': 'boxcar2', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'notifications', |
|||
'list': 'notification_providers', |
|||
'name': 'boxcar2', |
|||
'options': [ |
|||
{ |
|||
'name': 'enabled', |
|||
'default': 0, |
|||
'type': 'enabler', |
|||
}, |
|||
{ |
|||
'name': 'token', |
|||
'description': ('Your Boxcar access token.', 'Can be found in the app under settings') |
|||
}, |
|||
{ |
|||
'name': 'on_snatch', |
|||
'default': 0, |
|||
'type': 'bool', |
|||
'advanced': True, |
|||
'description': 'Also send message when movie is snatched.', |
|||
}, |
|||
], |
|||
} |
|||
], |
|||
}] |
@ -1,68 +0,0 @@ |
|||
from .main import Email |
|||
|
|||
|
|||
def start(): |
|||
return Email() |
|||
|
|||
config = [{ |
|||
'name': 'email', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'notifications', |
|||
'list': 'notification_providers', |
|||
'name': 'email', |
|||
'options': [ |
|||
{ |
|||
'name': 'enabled', |
|||
'default': 0, |
|||
'type': 'enabler', |
|||
}, |
|||
{ |
|||
'name': 'from', |
|||
'label': 'Send e-mail from', |
|||
}, |
|||
{ |
|||
'name': 'to', |
|||
'label': 'Send e-mail to', |
|||
}, |
|||
{ |
|||
'name': 'smtp_server', |
|||
'label': 'SMTP server', |
|||
}, |
|||
{ 'name': 'smtp_port', |
|||
'label': 'SMTP server port', |
|||
'default': '25', |
|||
'type': 'int', |
|||
}, |
|||
{ |
|||
'name': 'ssl', |
|||
'label': 'Enable SSL', |
|||
'default': 0, |
|||
'type': 'bool', |
|||
}, |
|||
{ |
|||
'name': 'starttls', |
|||
'label': 'Enable StartTLS', |
|||
'default': 0, |
|||
'type': 'bool', |
|||
}, |
|||
{ |
|||
'name': 'smtp_user', |
|||
'label': 'SMTP user', |
|||
}, |
|||
{ |
|||
'name': 'smtp_pass', |
|||
'label': 'SMTP password', |
|||
'type': 'password', |
|||
}, |
|||
{ |
|||
'name': 'on_snatch', |
|||
'default': 0, |
|||
'type': 'bool', |
|||
'advanced': True, |
|||
'description': 'Also send message when movie is snatched.', |
|||
}, |
|||
], |
|||
} |
|||
], |
|||
}] |
@ -1,46 +0,0 @@ |
|||
from .main import Growl |
|||
|
|||
|
|||
def start(): |
|||
return Growl() |
|||
|
|||
config = [{ |
|||
'name': 'growl', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'notifications', |
|||
'list': 'notification_providers', |
|||
'name': 'growl', |
|||
'description': 'Version 1.4+', |
|||
'options': [ |
|||
{ |
|||
'name': 'enabled', |
|||
'default': 0, |
|||
'type': 'enabler', |
|||
}, |
|||
{ |
|||
'name': 'on_snatch', |
|||
'default': False, |
|||
'type': 'bool', |
|||
'advanced': True, |
|||
'description': 'Also send message when movie is snatched.', |
|||
}, |
|||
{ |
|||
'name': 'hostname', |
|||
'description': 'Notify growl over network. Needs restart.', |
|||
'advanced': True, |
|||
}, |
|||
{ |
|||
'name': 'port', |
|||
'type': 'int', |
|||
'advanced': True, |
|||
}, |
|||
{ |
|||
'name': 'password', |
|||
'type': 'password', |
|||
'advanced': True, |
|||
}, |
|||
], |
|||
} |
|||
], |
|||
}] |
@ -1,34 +0,0 @@ |
|||
from .main import NMJ |
|||
|
|||
|
|||
def start(): |
|||
return NMJ() |
|||
|
|||
config = [{ |
|||
'name': 'nmj', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'notifications', |
|||
'list': 'notification_providers', |
|||
'name': 'nmj', |
|||
'label': 'NMJ', |
|||
'options': [ |
|||
{ |
|||
'name': 'enabled', |
|||
'default': 0, |
|||
'type': 'enabler', |
|||
}, |
|||
{ |
|||
'name': 'host', |
|||
'default': 'localhost', |
|||
}, |
|||
{ |
|||
'name': 'database', |
|||
}, |
|||
{ |
|||
'name': 'mount', |
|||
}, |
|||
], |
|||
} |
|||
], |
|||
}] |
@ -1,8 +1,39 @@ |
|||
from .main import NotifyMyAndroid |
|||
from couchpotato.core.helpers.variable import splitString |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.notifications.base import Notification |
|||
import pynma |
|||
import six |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
|
|||
class NotifyMyAndroid(Notification): |
|||
|
|||
def notify(self, message = '', data = None, listener = None): |
|||
if not data: data = {} |
|||
|
|||
nma = pynma.PyNMA() |
|||
keys = splitString(self.conf('api_key')) |
|||
nma.addkey(keys) |
|||
nma.developerkey(self.conf('dev_key')) |
|||
|
|||
response = nma.push( |
|||
application = self.default_title, |
|||
event = message.split(' ')[0], |
|||
description = message, |
|||
priority = self.conf('priority'), |
|||
batch_mode = len(keys) > 1 |
|||
) |
|||
|
|||
successful = 0 |
|||
for key in keys: |
|||
if not response[str(key)]['code'] == six.u('200'): |
|||
log.error('Could not send notification to NotifyMyAndroid (%s). %s', (key, response[key]['message'])) |
|||
else: |
|||
successful += 1 |
|||
|
|||
return successful == len(keys) |
|||
|
|||
def start(): |
|||
return NotifyMyAndroid() |
|||
|
|||
config = [{ |
|||
'name': 'notifymyandroid', |
@ -1,35 +0,0 @@ |
|||
from couchpotato.core.helpers.variable import splitString |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.notifications.base import Notification |
|||
import pynma |
|||
import six |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
|
|||
class NotifyMyAndroid(Notification): |
|||
|
|||
def notify(self, message = '', data = None, listener = None): |
|||
if not data: data = {} |
|||
|
|||
nma = pynma.PyNMA() |
|||
keys = splitString(self.conf('api_key')) |
|||
nma.addkey(keys) |
|||
nma.developerkey(self.conf('dev_key')) |
|||
|
|||
response = nma.push( |
|||
application = self.default_title, |
|||
event = message.split(' ')[0], |
|||
description = message, |
|||
priority = self.conf('priority'), |
|||
batch_mode = len(keys) > 1 |
|||
) |
|||
|
|||
successful = 0 |
|||
for key in keys: |
|||
if not response[str(key)]['code'] == six.u('200'): |
|||
log.error('Could not send notification to NotifyMyAndroid (%s). %s', (key, response[key]['message'])) |
|||
else: |
|||
successful += 1 |
|||
|
|||
return successful == len(keys) |
@ -1,8 +1,29 @@ |
|||
from .main import NotifyMyWP |
|||
from couchpotato.core.helpers.variable import splitString |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.notifications.base import Notification |
|||
from pynmwp import PyNMWP |
|||
import six |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
|
|||
class NotifyMyWP(Notification): |
|||
|
|||
def notify(self, message = '', data = None, listener = None): |
|||
if not data: data = {} |
|||
|
|||
keys = splitString(self.conf('api_key')) |
|||
p = PyNMWP(keys, self.conf('dev_key')) |
|||
|
|||
response = p.push(application = self.default_title, event = message, description = message, priority = self.conf('priority'), batch_mode = len(keys) > 1) |
|||
|
|||
for key in keys: |
|||
if not response[key]['Code'] == six.u('200'): |
|||
log.error('Could not send notification to NotifyMyWindowsPhone (%s). %s', (key, response[key]['message'])) |
|||
return False |
|||
|
|||
return response |
|||
|
|||
def start(): |
|||
return NotifyMyWP() |
|||
|
|||
config = [{ |
|||
'name': 'notifymywp', |
@ -1,25 +0,0 @@ |
|||
from couchpotato.core.helpers.variable import splitString |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.notifications.base import Notification |
|||
from pynmwp import PyNMWP |
|||
import six |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
|
|||
class NotifyMyWP(Notification): |
|||
|
|||
def notify(self, message = '', data = None, listener = None): |
|||
if not data: data = {} |
|||
|
|||
keys = splitString(self.conf('api_key')) |
|||
p = PyNMWP(keys, self.conf('dev_key')) |
|||
|
|||
response = p.push(application = self.default_title, event = message, description = message, priority = self.conf('priority'), batch_mode = len(keys) > 1) |
|||
|
|||
for key in keys: |
|||
if not response[key]['Code'] == six.u('200'): |
|||
log.error('Could not send notification to NotifyMyWindowsPhone (%s). %s', (key, response[key]['message'])) |
|||
return False |
|||
|
|||
return response |
@ -1,8 +1,39 @@ |
|||
from .main import Prowl |
|||
from couchpotato.core.helpers.encoding import toUnicode |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.notifications.base import Notification |
|||
import traceback |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
|
|||
class Prowl(Notification): |
|||
|
|||
urls = { |
|||
'api': 'https://api.prowlapp.com/publicapi/add' |
|||
} |
|||
|
|||
def notify(self, message = '', data = None, listener = None): |
|||
if not data: data = {} |
|||
|
|||
data = { |
|||
'apikey': self.conf('api_key'), |
|||
'application': self.default_title, |
|||
'description': toUnicode(message), |
|||
'priority': self.conf('priority'), |
|||
} |
|||
headers = { |
|||
'Content-type': 'application/x-www-form-urlencoded' |
|||
} |
|||
|
|||
try: |
|||
self.urlopen(self.urls['api'], headers = headers, data = data, show_error = False) |
|||
log.info('Prowl notifications sent.') |
|||
return True |
|||
except: |
|||
log.error('Prowl failed: %s', traceback.format_exc()) |
|||
|
|||
return False |
|||
|
|||
def start(): |
|||
return Prowl() |
|||
|
|||
config = [{ |
|||
'name': 'prowl', |
@ -1,35 +0,0 @@ |
|||
from couchpotato.core.helpers.encoding import toUnicode |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.notifications.base import Notification |
|||
import traceback |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
|
|||
class Prowl(Notification): |
|||
|
|||
urls = { |
|||
'api': 'https://api.prowlapp.com/publicapi/add' |
|||
} |
|||
|
|||
def notify(self, message = '', data = None, listener = None): |
|||
if not data: data = {} |
|||
|
|||
data = { |
|||
'apikey': self.conf('api_key'), |
|||
'application': self.default_title, |
|||
'description': toUnicode(message), |
|||
'priority': self.conf('priority'), |
|||
} |
|||
headers = { |
|||
'Content-type': 'application/x-www-form-urlencoded' |
|||
} |
|||
|
|||
try: |
|||
self.urlopen(self.urls['api'], headers = headers, data = data, show_error = False) |
|||
log.info('Prowl notifications sent.') |
|||
return True |
|||
except: |
|||
log.error('Prowl failed: %s', traceback.format_exc()) |
|||
|
|||
return False |
@ -1,8 +1,42 @@ |
|||
from .main import Pushalot |
|||
from couchpotato.core.helpers.encoding import toUnicode |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.notifications.base import Notification |
|||
import traceback |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
|
|||
class Pushalot(Notification): |
|||
|
|||
urls = { |
|||
'api': 'https://pushalot.com/api/sendmessage' |
|||
} |
|||
|
|||
def notify(self, message = '', data = None, listener = None): |
|||
if not data: data = {} |
|||
|
|||
data = { |
|||
'AuthorizationToken': self.conf('auth_token'), |
|||
'Title': self.default_title, |
|||
'Body': toUnicode(message), |
|||
'IsImportant': self.conf('important'), |
|||
'IsSilent': self.conf('silent'), |
|||
'Image': toUnicode(self.getNotificationImage('medium') + '?1'), |
|||
'Source': toUnicode(self.default_title) |
|||
} |
|||
|
|||
headers = { |
|||
'Content-type': 'application/x-www-form-urlencoded' |
|||
} |
|||
|
|||
try: |
|||
self.urlopen(self.urls['api'], headers = headers, data = data, show_error = False) |
|||
return True |
|||
except: |
|||
log.error('PushAlot failed: %s', traceback.format_exc()) |
|||
|
|||
return False |
|||
|
|||
def start(): |
|||
return Pushalot() |
|||
|
|||
config = [{ |
|||
'name': 'pushalot', |
@ -1,38 +0,0 @@ |
|||
from couchpotato.core.helpers.encoding import toUnicode |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.notifications.base import Notification |
|||
import traceback |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
|
|||
class Pushalot(Notification): |
|||
|
|||
urls = { |
|||
'api': 'https://pushalot.com/api/sendmessage' |
|||
} |
|||
|
|||
def notify(self, message = '', data = None, listener = None): |
|||
if not data: data = {} |
|||
|
|||
data = { |
|||
'AuthorizationToken': self.conf('auth_token'), |
|||
'Title': self.default_title, |
|||
'Body': toUnicode(message), |
|||
'IsImportant': self.conf('important'), |
|||
'IsSilent': self.conf('silent'), |
|||
'Image': toUnicode(self.getNotificationImage('medium') + '?1'), |
|||
'Source': toUnicode(self.default_title) |
|||
} |
|||
|
|||
headers = { |
|||
'Content-type': 'application/x-www-form-urlencoded' |
|||
} |
|||
|
|||
try: |
|||
self.urlopen(self.urls['api'], headers = headers, data = data, show_error = False) |
|||
return True |
|||
except: |
|||
log.error('PushAlot failed: %s', traceback.format_exc()) |
|||
|
|||
return False |
@ -1,40 +0,0 @@ |
|||
from .main import Pushbullet |
|||
|
|||
|
|||
def start(): |
|||
return Pushbullet() |
|||
|
|||
config = [{ |
|||
'name': 'pushbullet', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'notifications', |
|||
'list': 'notification_providers', |
|||
'name': 'pushbullet', |
|||
'options': [ |
|||
{ |
|||
'name': 'enabled', |
|||
'default': 0, |
|||
'type': 'enabler', |
|||
}, |
|||
{ |
|||
'name': 'api_key', |
|||
'label': 'User API Key' |
|||
}, |
|||
{ |
|||
'name': 'devices', |
|||
'default': '', |
|||
'advanced': True, |
|||
'description': 'IDs of devices to send notifications to, empty = all devices' |
|||
}, |
|||
{ |
|||
'name': 'on_snatch', |
|||
'default': 0, |
|||
'type': 'bool', |
|||
'advanced': True, |
|||
'description': 'Also send message when movie is snatched.', |
|||
}, |
|||
], |
|||
} |
|||
], |
|||
}] |
@ -1,40 +0,0 @@ |
|||
from .main import Pushover |
|||
|
|||
|
|||
def start(): |
|||
return Pushover() |
|||
|
|||
config = [{ |
|||
'name': 'pushover', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'notifications', |
|||
'list': 'notification_providers', |
|||
'name': 'pushover', |
|||
'options': [ |
|||
{ |
|||
'name': 'enabled', |
|||
'default': 0, |
|||
'type': 'enabler', |
|||
}, |
|||
{ |
|||
'name': 'user_key', |
|||
'description': 'Register on pushover.net to get one.' |
|||
}, |
|||
{ |
|||
'name': 'priority', |
|||
'default': 0, |
|||
'type': 'dropdown', |
|||
'values': [('Normal', 0), ('High', 1)], |
|||
}, |
|||
{ |
|||
'name': 'on_snatch', |
|||
'default': 0, |
|||
'type': 'bool', |
|||
'advanced': True, |
|||
'description': 'Also send message when movie is snatched.', |
|||
}, |
|||
], |
|||
} |
|||
], |
|||
}] |
@ -1,24 +0,0 @@ |
|||
from .main import Synoindex |
|||
|
|||
|
|||
def start(): |
|||
return Synoindex() |
|||
|
|||
config = [{ |
|||
'name': 'synoindex', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'notifications', |
|||
'list': 'notification_providers', |
|||
'name': 'synoindex', |
|||
'description': 'Automaticly adds index to Synology Media Server.', |
|||
'options': [ |
|||
{ |
|||
'name': 'enabled', |
|||
'default': 0, |
|||
'type': 'enabler', |
|||
} |
|||
], |
|||
} |
|||
], |
|||
}] |
@ -1,34 +0,0 @@ |
|||
from .main import Toasty |
|||
|
|||
|
|||
def start(): |
|||
return Toasty() |
|||
|
|||
config = [{ |
|||
'name': 'toasty', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'notifications', |
|||
'list': 'notification_providers', |
|||
'name': 'toasty', |
|||
'options': [ |
|||
{ |
|||
'name': 'enabled', |
|||
'default': 0, |
|||
'type': 'enabler', |
|||
}, |
|||
{ |
|||
'name': 'api_key', |
|||
'label': 'Device ID', |
|||
}, |
|||
{ |
|||
'name': 'on_snatch', |
|||
'default': 0, |
|||
'type': 'bool', |
|||
'advanced': True, |
|||
'description': 'Also send message when movie is snatched.', |
|||
}, |
|||
], |
|||
} |
|||
], |
|||
}] |
@ -1,31 +0,0 @@ |
|||
from .main import Trakt |
|||
|
|||
|
|||
def start(): |
|||
return Trakt() |
|||
|
|||
config = [{ |
|||
'name': 'trakt', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'notifications', |
|||
'list': 'notification_providers', |
|||
'name': 'trakt', |
|||
'label': 'Trakt', |
|||
'description': 'add movies to your collection once downloaded. Fill in your username and password in the <a href="../automation/">Automation Trakt settings</a>', |
|||
'options': [ |
|||
{ |
|||
'name': 'notification_enabled', |
|||
'default': False, |
|||
'type': 'enabler', |
|||
}, |
|||
{ |
|||
'name': 'remove_watchlist_enabled', |
|||
'label': 'Remove from watchlist', |
|||
'default': False, |
|||
'type': 'bool', |
|||
}, |
|||
], |
|||
} |
|||
], |
|||
}] |
@ -1,68 +0,0 @@ |
|||
from .main import XBMC |
|||
|
|||
|
|||
def start(): |
|||
return XBMC() |
|||
|
|||
config = [{ |
|||
'name': 'xbmc', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'notifications', |
|||
'list': 'notification_providers', |
|||
'name': 'xbmc', |
|||
'label': 'XBMC', |
|||
'description': 'v11 (Eden) and v12 (Frodo)', |
|||
'options': [ |
|||
{ |
|||
'name': 'enabled', |
|||
'default': 0, |
|||
'type': 'enabler', |
|||
}, |
|||
{ |
|||
'name': 'host', |
|||
'default': 'localhost:8080', |
|||
}, |
|||
{ |
|||
'name': 'username', |
|||
'default': 'xbmc', |
|||
}, |
|||
{ |
|||
'name': 'password', |
|||
'default': '', |
|||
'type': 'password', |
|||
}, |
|||
{ |
|||
'name': 'only_first', |
|||
'default': 0, |
|||
'type': 'bool', |
|||
'advanced': True, |
|||
'description': 'Only update the first host when movie snatched, useful for synced XBMC', |
|||
}, |
|||
{ |
|||
'name': 'remote_dir_scan', |
|||
'label': 'Remote Folder Scan', |
|||
'default': 0, |
|||
'type': 'bool', |
|||
'advanced': True, |
|||
'description': 'Only scan new movie folder at remote XBMC servers. Works if movie location is the same.', |
|||
}, |
|||
{ |
|||
'name': 'force_full_scan', |
|||
'label': 'Always do a full scan', |
|||
'default': 0, |
|||
'type': 'bool', |
|||
'advanced': True, |
|||
'description': 'Do a full scan instead of only the new movie. Useful if the XBMC path is different from the path CPS uses.', |
|||
}, |
|||
{ |
|||
'name': 'on_snatch', |
|||
'default': 0, |
|||
'type': 'bool', |
|||
'advanced': True, |
|||
'description': 'Also send message when movie is snatched.', |
|||
}, |
|||
], |
|||
} |
|||
], |
|||
}] |
@ -1,8 +1,49 @@ |
|||
from .main import Xmpp |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.notifications.base import Notification |
|||
from time import sleep |
|||
import traceback |
|||
import xmpp |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
autoload = 'Xmpp' |
|||
|
|||
|
|||
class Xmpp(Notification): |
|||
|
|||
def notify(self, message = '', data = None, listener = None): |
|||
if not data: data = {} |
|||
|
|||
try: |
|||
jid = xmpp.protocol.JID(self.conf('username')) |
|||
client = xmpp.Client(jid.getDomain(), debug = []) |
|||
|
|||
# Connect |
|||
if not client.connect(server = (self.conf('hostname'), self.conf('port'))): |
|||
log.error('XMPP failed: Connection to server failed.') |
|||
return False |
|||
|
|||
# Authenticate |
|||
if not client.auth(jid.getNode(), self.conf('password'), resource = jid.getResource()): |
|||
log.error('XMPP failed: Failed to authenticate.') |
|||
return False |
|||
|
|||
# Send message |
|||
client.send(xmpp.protocol.Message(to = self.conf('to'), body = message, typ = 'chat')) |
|||
|
|||
# Disconnect |
|||
# some older servers will not send the message if you disconnect immediately after sending |
|||
sleep(1) |
|||
client.disconnect() |
|||
|
|||
log.info('XMPP notifications sent.') |
|||
return True |
|||
|
|||
except: |
|||
log.error('XMPP failed: %s', traceback.format_exc()) |
|||
|
|||
return False |
|||
|
|||
def start(): |
|||
return Xmpp() |
|||
|
|||
config = [{ |
|||
'name': 'xmpp', |
@ -1,43 +0,0 @@ |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.notifications.base import Notification |
|||
from time import sleep |
|||
import traceback |
|||
import xmpp |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
|
|||
class Xmpp(Notification): |
|||
|
|||
def notify(self, message = '', data = None, listener = None): |
|||
if not data: data = {} |
|||
|
|||
try: |
|||
jid = xmpp.protocol.JID(self.conf('username')) |
|||
client = xmpp.Client(jid.getDomain(), debug = []) |
|||
|
|||
# Connect |
|||
if not client.connect(server = (self.conf('hostname'), self.conf('port'))): |
|||
log.error('XMPP failed: Connection to server failed.') |
|||
return False |
|||
|
|||
# Authenticate |
|||
if not client.auth(jid.getNode(), self.conf('password'), resource = jid.getResource()): |
|||
log.error('XMPP failed: Failed to authenticate.') |
|||
return False |
|||
|
|||
# Send message |
|||
client.send(xmpp.protocol.Message(to = self.conf('to'), body = message, typ = 'chat')) |
|||
|
|||
# Disconnect |
|||
# some older servers will not send the message if you disconnect immediately after sending |
|||
sleep(1) |
|||
client.disconnect() |
|||
|
|||
log.info('XMPP notifications sent.') |
|||
return True |
|||
|
|||
except: |
|||
log.error('XMPP failed: %s', traceback.format_exc()) |
|||
|
|||
return False |
Loading…
Reference in new issue