diff --git a/data/interfaces/default/config_notifications.tmpl b/data/interfaces/default/config_notifications.tmpl index 75f00a7aa0aa73f29ffc1fcbed6b1bfe1369864f..a4e4d25c9bc1eb39f5f7985666de26898b94f323 100755 --- a/data/interfaces/default/config_notifications.tmpl +++ b/data/interfaces/default/config_notifications.tmpl @@ -1078,7 +1078,7 @@ </div> <div class="field-pair"> <label class="nocheck clearfix"> - <span class="component-title">Pushbullet Devices</span> + <span class="component-title">Pushbullet Devices and Channels</span> <select name="pushbullet_device_list" id="pushbullet_device_list"></select> <input type="hidden" id="pushbullet_device" value="$sickbeard.PUSHBULLET_DEVICE"> <input type="button" class="btn" value="Update device list" id="getPushbulletDevices" /> diff --git a/data/js/configNotifications.js b/data/js/configNotifications.js index 2e207b088798d61a0dbc2ef8cf28878ca8abbe08..198a7ef4c98cecf1ae6abb146f31e1b80f7cd9cc 100644 --- a/data/js/configNotifications.js +++ b/data/js/configNotifications.js @@ -246,18 +246,37 @@ $(document).ready(function () { $("#pushbullet_api").focus(); return false; } - + $("#pushbullet_device_list").html(''); var current_pushbullet_device = $("#pushbullet_device").val(); $.get(sbRoot + "/home/getPushbulletDevices", {'api': pushbullet_api}, function (data) { var devices = jQuery.parseJSON(data).devices; - $("#pushbullet_device_list").html(''); + for (var i = 0; i < devices.length; i++) { if(devices[i].active == true && devices[i].pushable == true){ - if(current_pushbullet_device == devices[i].iden) { - $("#pushbullet_device_list").append('<option value="'+devices[i].iden+'" selected>' + devices[i].nickname + '</option>') + if(current_pushbullet_device == 'device:'+devices[i].iden) { + $("#pushbullet_device_list").append('<option value="device:'+devices[i].iden+'" selected>' + devices[i].nickname + '</option>') + } else { + $("#pushbullet_device_list").append('<option value="device:'+devices[i].iden+'">' + devices[i].nickname + '</option>') + } + } + } + if(msg) { + $('#testPushbullet-result').html(msg); + } + } + ); + + $.get(sbRoot + "/home/getPushbulletChannels", {'api': pushbullet_api}, + function (data) { + var channels = jQuery.parseJSON(data).channels; + + for (var i = 0; i < channels.length; i++) { + if(channels[i].active == true){ + if(current_pushbullet_device == 'channel:'+channels[i].tag) { + $("#pushbullet_device_list").append('<option value="channel:'+channels[i].tag+'" selected>' + channels[i].name + '</option>') } else { - $("#pushbullet_device_list").append('<option value="'+devices[i].iden+'">' + devices[i].nickname + '</option>') + $("#pushbullet_device_list").append('<option value="channel:'+channels[i].tag+'">' + channels[i].name + '</option>') } } } diff --git a/sickbeard/notifiers/pushbullet.py b/sickbeard/notifiers/pushbullet.py index 64801afd861fa16f2a6774a3325cadf1fb99f4e3..0d890f737e729f1c1b9bc78b4963ce723b5ceb10 100644 --- a/sickbeard/notifiers/pushbullet.py +++ b/sickbeard/notifiers/pushbullet.py @@ -29,18 +29,21 @@ from sickbeard import logger, common class PushbulletNotifier: def test_notify(self, pushbullet_api): - return self._sendPushbullet(pushbullet_api, event="Test", message="Testing Pushbullet settings from Sick Beard", method="POST", notificationType="note", force=True) + return self._sendPushbullet(pushbullet_api, message="Test", event="Testing Pushbullet settings from Sick Beard", method="POST", notificationType="note", force=True) def get_devices(self, pushbullet_api): return self._sendPushbullet(pushbullet_api, method="GET", force=True) + def get_channels(self, pushbullet_api): + return self._sendPushbullet(pushbullet_api, method="GET", force=True, event="getChannels") + def notify_snatch(self, ep_name): if sickbeard.PUSHBULLET_NOTIFY_ONSNATCH: - self._sendPushbullet(pushbullet_api=None, event=common.notifyStrings[common.NOTIFY_SNATCH], message=ep_name, notificationType="note", method="POST") + self._sendPushbullet(pushbullet_api=None, message=common.notifyStrings[common.NOTIFY_SNATCH], event="Snatched ->"+ep_name, notificationType="note", method="POST") def notify_download(self, ep_name): if sickbeard.PUSHBULLET_NOTIFY_ONDOWNLOAD: - self._sendPushbullet(pushbullet_api=None, event=common.notifyStrings[common.NOTIFY_DOWNLOAD], message=ep_name, notificationType="note", method="POST") + self._sendPushbullet(pushbullet_api=None, message=common.notifyStrings[common.NOTIFY_DOWNLOAD], event="DL ->"+ep_name, notificationType="note", method="POST") def notify_subtitle_download(self, ep_name, lang): if sickbeard.PUSHBULLET_NOTIFY_ONSUBTITLEDOWNLOAD: @@ -55,12 +58,15 @@ class PushbulletNotifier: pushbullet_api = sickbeard.PUSHBULLET_API if pushbullet_device == None: pushbullet_device = sickbeard.PUSHBULLET_DEVICE - + if method == 'POST': uri = '/v2/pushes' - else: + else: uri = '/v2/devices' + if event == 'getChannels': + uri = '/v2/channels' + logger.log(u"Pushbullet event: " + str(event), logger.DEBUG) logger.log(u"Pushbullet message: " + str(message), logger.DEBUG) logger.log(u"Pushbullet api: " + str(pushbullet_api), logger.DEBUG) @@ -80,11 +86,20 @@ class PushbulletNotifier: else: testMessage = False try: - data = { - 'title': event.encode('utf-8'), - 'body': message.encode('utf-8'), - 'device_iden': pushbullet_device, - 'type': notificationType} + device = pushbullet_device.split(':'); + if device[0] == 'device': + data = { + 'title': event.encode('utf-8'), + 'body': message.encode('utf-8'), + 'device_iden': device[1], + 'type': notificationType} + else: + data = { + 'title': event.encode('utf-8'), + 'body': message.encode('utf-8'), + 'channel_tag': device[1], + 'type': notificationType} + data = json.dumps(data) http_handler.request(method, uri, body=data, headers={'Content-Type': 'application/json', 'Authorization': 'Bearer %s' % pushbullet_api}) diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 2a6a9e2982163a3cb70ee145fe3d6b4fd9ced908..33a47629fc69fe840f22b2abbe13a528c5ac4707 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -1540,7 +1540,7 @@ class ConfigNotifications: pytivo_host=None, pytivo_share_name=None, pytivo_tivo_name=None, use_nma=None, nma_notify_onsnatch=None, nma_notify_ondownload=None, nma_notify_onsubtitledownload=None, nma_api=None, nma_priority=0, use_pushalot=None, pushalot_notify_onsnatch=None, pushalot_notify_ondownload=None, pushalot_notify_onsubtitledownload=None, pushalot_authorizationtoken=None, - use_pushbullet=None, pushbullet_notify_onsnatch=None, pushbullet_notify_ondownload=None, pushbullet_notify_onsubtitledownload=None, pushbullet_api=None, pushbullet_device=None, pushbullet_device_list=None, + use_pushbullet=None, pushbullet_notify_onsnatch=None, pushbullet_notify_ondownload=None, pushbullet_notify_onsubtitledownload=None, pushbullet_api=None, pushbullet_device=None, pushbullet_device_list=None, pushbullet_channel_list=None, use_mail=None, mail_username=None, mail_password=None, mail_server=None, mail_ssl=None, mail_from=None, mail_to=None, mail_notify_onsnatch=None ): @@ -2008,6 +2008,7 @@ class ConfigNotifications: sickbeard.PUSHBULLET_NOTIFY_ONSUBTITLEDOWNLOAD = pushbullet_notify_onsubtitledownload sickbeard.PUSHBULLET_API = pushbullet_api sickbeard.PUSHBULLET_DEVICE = pushbullet_device_list + sickbeard.PUSHBULLET_CHANNEL = pushbullet_channel_list sickbeard.save_config() @@ -2908,6 +2909,18 @@ class Home: else: return "Error sending Pushbullet notification" + @cherrypy.expose + + #get channels + def getPushbulletChannels(self, api=None): + cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store" + + result = notifiers.pushbullet_notifier.get_channels(api) + if result: + return result + else: + return "Error sending Pushbullet notification" + @cherrypy.expose def shutdown(self, pid=None):