Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MDLESK Notifications for Windows Phone #2177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions data/interfaces/default/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,40 @@ <h3>MPC</h3>
</div>
</fieldset>

<fieldset>
<h3>MDLESK</h3>
<div class="row checkbox">
<input type="checkbox" name="mdlesk_enabled" id="mdlesk" value="1" ${config['mdlesk_enabled']} />
<label>Enable MDLESK Notifications</label>
</div>
<div id="mdleskoptions">
<div class="row">
<label>Server</label>
<input type="text" name="mdlesk_server" value="${config['mdlesk_server']}" size="35">
<small>Usually http://mdlesk.com/Api.svc</small>
</div>
<div class="row">
<label>Username</label>
<input type="text" name="mdlesk_username" value="${config['mdlesk_username']}" size="35">
</div>
<div class="row">
<label>API Key</label>
<input type="text" name="mdlesk_apikey" value="${config['mdlesk_apikey']}" size="35">
</div>
<div class="row">
<label>Source</label>
<input type="text" name="mdlesk_source" value="${config['mdlesk_source']}" size="35">
<small>Usually Headphones</small>
</div>
<div class="row checkbox">
<input type="checkbox" name="mdlesk_onsnatch" value="1" ${config['mdlesk_onsnatch']} /><label>Notify on snatch?</label>
</div>
<div class="row">
<input type="button" value="Test MDLESK" id="testMDLESK" />
</div>
</div>
</fieldset>

<fieldset>
</td>
</tr>
Expand Down Expand Up @@ -1866,6 +1900,26 @@ <h3>MPC</h3>
}
});

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();
Expand Down Expand Up @@ -2094,6 +2148,14 @@ <h3>MPC</h3>
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut();
});

$('#testMDLESK').click(function () {
$.get( "/testMdlesk", function( data ) {
$( "#ajaxMsg" ).html( "<div class='msg'><span class='ui-icon ui-icon-check'></span>" + data + "</div>" );
$('#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("<div class='msg'><span class='ui-icon ui-icon-check'></span>"+data+"</div>"); });
Expand Down
6 changes: 6 additions & 0 deletions headphones/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
47 changes: 47 additions & 0 deletions headphones/notifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 19 additions & 2 deletions headphones/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down