From 7d56097d019930885472bb7e6c724d53a851ec32 Mon Sep 17 00:00:00 2001 From: mdlesk Date: Sun, 5 Apr 2015 17:52:39 -0400 Subject: [PATCH] Added MDLESK Notifications for Windows Phone --- data/interfaces/default/config.html | 62 +++++++++++++++++++++++++++++ headphones/config.py | 6 +++ headphones/notifiers.py | 47 ++++++++++++++++++++++ headphones/webserve.py | 21 +++++++++- 4 files changed, 134 insertions(+), 2 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 3b72169d9..6c6200c39 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -1104,6 +1104,40 @@

MPC

+
+

MDLESK

+
+ + +
+
+
+ + + Usually http://mdlesk.com/Api.svc +
+
+ + +
+
+ + +
+
+ + + Usually Headphones +
+
+ +
+
+ +
+
+
+
@@ -1866,6 +1900,26 @@

MPC

} }); + if ($("#mdlesk").is(":checked")) + { + $("#mdleskoptions").show(); + } + else + { + $("#mdleskoptions").hide(); + } + + $("#mdlesk").click(function(){ + if ($("#mdlesk").is(":checked")) + { + $("#mdleskoptions").slideDown(); + } + else + { + $("#mdleskoptions").slideUp(); + } + }); + if ($("#songkick").is(":checked")) { $("#songkickoptions").show(); @@ -2094,6 +2148,14 @@

MPC

$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut(); }); + $('#testMDLESK').click(function () { + $.get( "/testMdlesk", function( data ) { + $( "#ajaxMsg" ).html( "
" + data + "
" ); + $('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut(); + alert( "Test Notification Sent" ); + }); + }); + $('#osxnotifyregister').click(function () { var osx_notify_app = $("#osx_notify_reg").val(); $.get("/osxnotifyregister", {'app': osx_notify_app}, function (data) { $('#ajaxMsg').html("
"+data+"
"); }); diff --git a/headphones/config.py b/headphones/config.py index 4071edd7e..ff7d4c418 100644 --- a/headphones/config.py +++ b/headphones/config.py @@ -114,6 +114,12 @@ def bool_int(value): 'LOSSLESS_BITRATE_TO': (int, 'General', 0), 'LOSSLESS_DESTINATION_DIR': (str, 'General', ''), 'MB_IGNORE_AGE': (int, 'General', 365), + 'MDLESK_APIKEY': (str, 'MDLESK', ''), + 'MDLESK_ENABLED': (int, 'MDLESK', 0), + 'MDLESK_ONSNATCH': (int, 'MDLESK', 0), + 'MDLESK_SERVER': (str, 'MDLESK', ''), + 'MDLESK_SOURCE': (str, 'MDLESK', ''), + 'MDLESK_USERNAME': (str, 'MDLESK', ''), 'MININOVA': (int, 'Mininova', 0), 'MININOVA_RATIO': (str, 'Mininova', ''), 'MIRROR': (str, 'General', 'musicbrainz.org'), diff --git a/headphones/notifiers.py b/headphones/notifiers.py index e8503b531..0c6b03729 100644 --- a/headphones/notifiers.py +++ b/headphones/notifiers.py @@ -827,3 +827,50 @@ def notify(self, albumpaths): # Invoke request request.request_response(self.host + "musicFolderSettings.view?scanNow", auth=(self.username, self.password)) + +class MDLESK(object): + """ + MDLESK Notifications + """ + + def __init__(self): + self.enabled = headphones.CONFIG.MDLESK_ENABLED + self.server = headphones.CONFIG.MDLESK_SERVER + self.username = headphones.CONFIG.MDLESK_USERNAME + self.source = headphones.CONFIG.MDLESK_SOURCE + self.apikey = headphones.CONFIG.MDLESK_APIKEY + + def conf(self, options): + return cherrypy.config['config'].get('MDLESK', options) + + def notify(self, message, event): + if not self.enabled: + return + + requestParameters = '' + requestParameters = requestParameters + '?' + requestParameters = requestParameters + 'Username=%s' % urllib.quote_plus(self.username) + requestParameters = requestParameters + '&ApiKey=%s' % urllib.quote_plus(self.apikey) + requestParameters = requestParameters + '&Action=SendNotification' + requestParameters = requestParameters + '&Source=%s' % urllib.quote_plus(self.source) + requestParameters = requestParameters + '&Message=%s' % urllib.quote_plus(message) + requestUrl = self.server + requestParameters + + try: + req = urllib2.Request(requestUrl) + handle = urllib2.urlopen(req) + handle.close() + except urllib2.URLError, e: + logger.warning(u'MDLESK notification failed') + return + + logger.info(u"MDLESK notification sent.") + + def updateLibrary(self): + #For uniformity reasons not removed + return + + def test(self): + self.enabled = True + self.notify('Test Message', 'Test Message') + return True \ No newline at end of file diff --git a/headphones/webserve.py b/headphones/webserve.py index b3b67cac5..1bf8a06fc 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1151,7 +1151,13 @@ def config(self): "cache_sizemb": headphones.CONFIG.CACHE_SIZEMB, "file_permissions": headphones.CONFIG.FILE_PERMISSIONS, "folder_permissions": headphones.CONFIG.FOLDER_PERMISSIONS, - "mpc_enabled": checked(headphones.CONFIG.MPC_ENABLED) + "mpc_enabled": checked(headphones.CONFIG.MPC_ENABLED), + "mdlesk_enabled": checked(headphones.CONFIG.MDLESK_ENABLED), + "mdlesk_onsnatch": checked(headphones.CONFIG.MDLESK_ONSNATCH), + "mdlesk_server": headphones.CONFIG.MDLESK_SERVER, + "mdlesk_apikey": headphones.CONFIG.MDLESK_APIKEY, + "mdlesk_source": headphones.CONFIG.MDLESK_SOURCE, + "mdlesk_username": headphones.CONFIG.MDLESK_USERNAME } # Need to convert EXTRAS to a dictionary we can pass to the config: @@ -1196,7 +1202,7 @@ def configUpdate(self, **kwargs): "nma_enabled", "nma_onsnatch", "pushalot_enabled", "pushalot_onsnatch", "synoindex_enabled", "pushover_enabled", "pushover_onsnatch", "pushbullet_enabled", "pushbullet_onsnatch", "subsonic_enabled", "twitter_enabled", "twitter_onsnatch", "osx_notify_enabled", "osx_notify_onsnatch", "boxcar_enabled", "boxcar_onsnatch", "songkick_enabled", "songkick_filter_enabled", - "mpc_enabled" + "mpc_enabled","mdlesk_enabled","mdlesk_onsnatch" ] for checked_config in checked_configs: if checked_config not in kwargs: @@ -1383,6 +1389,17 @@ def testTwitter(self): else: return "Error sending tweet" + @cherrypy.expose + def testMdlesk(self): + cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store" + mdlesk = notifiers.MDLESK() + result = mdlesk.test() + if result: + return "Test Notification Sent" + else: + return "Error sending notification" + + @cherrypy.expose def osxnotifyregister(self, app): cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"