From 84e7bbfd7b11af166dba12f4e5908a3af818f385 Mon Sep 17 00:00:00 2001 From: Harris Borawski Date: Sun, 13 Nov 2016 18:49:12 -0800 Subject: [PATCH] Add notifiter for Join by joaoapps --- couchpotato/core/notifications/join.py | 84 ++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 couchpotato/core/notifications/join.py diff --git a/couchpotato/core/notifications/join.py b/couchpotato/core/notifications/join.py new file mode 100644 index 0000000..06bf4e5 --- /dev/null +++ b/couchpotato/core/notifications/join.py @@ -0,0 +1,84 @@ +from couchpotato.core.helpers.encoding import toUnicode +from couchpotato.core.helpers.encoding import tryUrlencode +from couchpotato.core.helpers.variable import splitString +from couchpotato.core.logger import CPLog +from couchpotato.core.notifications.base import Notification + + +log = CPLog(__name__) + +autoload = 'Join' + + +class Join(Notification): + + # URL for request + url = 'https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?title=%s&text=%s&deviceId=%s&icon=%s' + + # URL for notification icon + icon = tryUrlencode('https://raw.githubusercontent.com/CouchPotato/CouchPotatoServer/master/couchpotato/static/images/icons/android.png') + + def notify(self, message = '', data = None, listener = None): + if not data: data = {} + + # default for devices + device_default = [None] + + apikey = self.conf('apikey') + if apikey is not None: + # Add apikey to request url + self.url = self.url + '&apikey=' + apikey + # If api key is present, default to sending to all devices + device_default = ['group.all'] + + devices = self.getDevices() or device_default + successful = 0 + for device in devices: + response = self.urlopen(self.url % (self.default_title, tryUrlencode(toUnicode(message)), device, self.icon)) + + if response: + successful += 1 + else: + log.error('Unable to push notification to Join device with ID %s' % device) + + return successful == len(devices) + + def getDevices(self): + return splitString(self.conf('devices')) + + +config = [{ + 'name': 'join', + 'groups': [ + { + 'tab': 'notifications', + 'list': 'notification_providers', + 'name': 'join', + 'options': [ + { + 'name': 'enabled', + 'default': 0, + 'type': 'enabler', + }, + { + 'name': 'devices', + 'default': '', + 'description': 'IDs of devices to notify, or group to send to if API key is specified (ex: group.all)' + }, + { + 'name': 'apikey', + 'default': '', + 'advanced': True, + 'description': 'API Key for sending to all devices, or group' + }, + { + 'name': 'on_snatch', + 'default': 0, + 'type': 'bool', + 'advanced': True, + 'description': 'Also send message when movie is snatched.', + }, + ], + } + ], +}]