Skip to content
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
Binary file added data/images/notifiers/mdlesk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions data/interfaces/default/config_notifications.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,86 @@

</fieldset>
</div><!-- /pushbullet component-group //-->







<div class="component-group clearfix">
<div class="component-group-desc">
<img class="notifier-icon" src="$sbRoot/images/notifiers/mdlesk.png" alt="" title="MDLESK" />
<h3><a href="http://www.mdlesk.com/" rel="noreferrer" onclick="window.open('${sickbeard.ANON_REDIRECT}' + this.href, '_blank'); return false;">MDLESK</a></h3>
<p>MDLESK allows you to send push notifications to Windows 8 Systems, Windows Phone devices, and other supported devices</p>
</div>
<fieldset class="component-group-list">
<div class="field-pair">
<input type="checkbox" class="enabler" name="use_mdlesk" id="use_mdlesk" #if $sickbeard.USE_MDLESK then "checked=\"checked\"" else ""# />
<label class="clearfix" for="use_mdlesk">
<span class="component-title">Enable</span>
<span class="component-desc">Should Sick Beard send MDLESK notifications?</span>
</label>
</div>

<div id="content_use_mdlesk">
<div class="field-pair">
<input type="checkbox" name="mdlesk_notify_onsnatch" id="mdlesk_notify_onsnatch" #if $sickbeard.MDLESK_NOTIFY_ONSNATCH then "checked=\"checked\"" else ""# />
<label class="clearfix" for="mdlesk_notify_onsnatch">
<span class="component-title">Notify on Snatch</span>
<span class="component-desc">Send notification when we start a download?</span>
</label>
</div>
<div class="field-pair">
<input type="checkbox" name="mdlesk_notify_ondownload" id="mdlesk_notify_ondownload" #if $sickbeard.MDLESK_NOTIFY_ONDOWNLOAD then "checked=\"checked\"" else ""# />
<label class="clearfix" for="mdlesk_notify_ondownload">
<span class="component-title">Notify on Download</span>
<span class="component-desc">Send notification when we finish a download?</span>
</label>
</div>
<div class="field-pair">
<label class="nocheck clearfix">
<span class="component-title">Server</span>
<input type="text" name="mdlesk_server" id="mdlesk_server" value="$sickbeard.MDLESK_SERVER" size="35" />
</label>
<label class="nocheck clearfix">
<span class="component-title">&nbsp;</span>
<span class="component-desc">The default hosted server is http://mdlesk.com/Api.aspx</span>
</label>
</div>
<div class="field-pair">
<label class="nocheck clearfix">
<span class="component-title">Username</span>
<input type="text" name="mdlesk_username" id="mdlesk_username" value="$sickbeard.MDLESK_USERNAME" size="35" />
</label>
</div>
<div class="field-pair">
<label class="nocheck clearfix">
<span class="component-title">API Key</span>
<input type="text" name="mdlesk_apikey" id="mdlesk_apikey" value="$sickbeard.MDLESK_APIKEY" size="35" />
</label>
<label class="nocheck clearfix">
<span class="component-title">&nbsp;</span>
<span class="component-desc">Get your API Key by visiting the hosted server and logging into your account.</span>
</label>
</div>
<div class="field-pair">
<label class="nocheck clearfix">
<span class="component-title">Source System</span>
<input type="text" name="mdlesk_source" id="mdlesk_source" value="$sickbeard.MDLESK_SOURCE" size="35" />
</label>
<label class="nocheck clearfix">
<span class="component-title">&nbsp;</span>
<span class="component-desc">Usually Sick Beard</span>
</label>
</div>
<div class="testNotification" id="testMdlesk-result">Click below to test.</div>
<input type="button" class="btn" value="Test MDLESK" id="testMdlesk" />
<input type="submit" class="btn config_submitter" value="Save Changes" />
</div><!-- /content_use_pushbullet //-->

</fieldset>
</div><!-- /mdlesk component-group //-->

<div class="component-group-save">
<input type="submit" class="btn config_submitter" value="Save Changes" />
Expand Down
18 changes: 18 additions & 0 deletions data/js/configNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,24 @@ $(document).ready(function () {
});
});

$("#testMdlesk").click(function () {
var mdlesk_server = $.trim($("#mdlesk_server").val());
var mdlesk_username = $("#mdlesk_username").val();
var mdlesk_apikey = $("#mdlesk_apikey").val();
var mdlesk_source = $("#mdlesk_source").val();
if (!mdlesk_server || !mdlesk_username || !mdlesk_apikey) {
$("#testMdlesk-result").html("Please fill out the necessary fields above.");
return;
}
$(this).prop("disabled", true);
$("#testMdlesk-result").html(loading);
$.get(sbRoot + "/home/testMdlesk", {'server': mdlesk_server, 'username': mdlesk_username, 'apikey':mdlesk_apikey, 'source': mdlesk_source})
.done(function (data) {
$("#testMdlesk-result").html(data);
$("#testMdlesk").prop("disabled", false);
});
});

$("#testPushbullet").click(function () {
var pushbullet_access_token = $.trim($("#pushbullet_access_token").val());
var pushbullet_device_iden = $("#pushbullet_device_iden").val();
Expand Down
29 changes: 28 additions & 1 deletion sickbeard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@
PUSHBULLET_ACCESS_TOKEN = None
PUSHBULLET_DEVICE_IDEN = None

USE_MDLESK = False
MDLESK_NOTIFY_ONSNATCH = False
MDLESK_NOTIFY_ONDOWNLOAD = False
MDLESK_SERVER = None
MDLESK_USERNAME = None
MDLESK_APIKEY = None
MDLESK_SOURCE = None

COMING_EPS_LAYOUT = None
COMING_EPS_DISPLAY_PAUSED = None
COMING_EPS_SORT = None
Expand Down Expand Up @@ -368,7 +376,8 @@ def initialize(consoleLogging=True):
USE_LISTVIEW, METADATA_XBMC, METADATA_XBMC_12PLUS, METADATA_MEDIABROWSER, METADATA_MEDE8ER, METADATA_PS3, metadata_provider_dict, \
GIT_PATH, MOVE_ASSOCIATED_FILES, FILTER_ASSOCIATED_FILES, \
COMING_EPS_LAYOUT, COMING_EPS_SORT, COMING_EPS_DISPLAY_PAUSED, METADATA_WDTV, METADATA_TIVO, IGNORE_WORDS, CREATE_MISSING_SHOW_DIRS, \
ADD_SHOWS_WO_DIR, ANON_REDIRECT, DISPLAY_ALL_SEASONS
ADD_SHOWS_WO_DIR, ANON_REDIRECT, DISPLAY_ALL_SEASONS, \
USE_MDLESK, MDLESK_NOTIFY_ONSNATCH, MDLESK_NOTIFY_ONDOWNLOAD, MDLESK_SERVER, MDLESK_USERNAME, MDLESK_APIKEY, MDLESK_SOURCE

if __INITIALIZED__:
return False
Expand Down Expand Up @@ -672,6 +681,15 @@ def initialize(consoleLogging=True):
PUSHBULLET_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Pushbullet', 'pushbullet_notify_ondownload', 0))
PUSHBULLET_ACCESS_TOKEN = check_setting_str(CFG, 'Pushbullet', 'pushbullet_access_token', '')
PUSHBULLET_DEVICE_IDEN = check_setting_str(CFG, 'Pushbullet', 'pushbullet_device_iden', '')

CheckSection(CFG, 'Mdlesk')
USE_MDLESK = bool(check_setting_int(CFG, 'Mdlesk', 'use_mdlesk', 0))
MDLESK_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Mdlesk', 'mdlesk_notify_onsnatch', 0))
MDLESK_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Mdlesk', 'mdlesk_notify_ondownload', 0))
MDLESK_SERVER = check_setting_str(CFG, 'Mdlesk', 'mdlesk_server', '')
MDLESK_USERNAME = check_setting_str(CFG, 'Mdlesk', 'mdlesk_username', '')
MDLESK_APIKEY = check_setting_str(CFG, 'Mdlesk', 'mdlesk_apikey', '')
MDLESK_SOURCE = check_setting_str(CFG, 'Mdlesk', 'mdlesk_source', '')

if not os.path.isfile(CONFIG_FILE):
logger.log(u"Unable to find '" + CONFIG_FILE + "', all settings will be default!", logger.DEBUG)
Expand Down Expand Up @@ -1229,6 +1247,15 @@ def save_config():
new_config['GUI']['coming_eps_layout'] = COMING_EPS_LAYOUT
new_config['GUI']['coming_eps_display_paused'] = int(COMING_EPS_DISPLAY_PAUSED)
new_config['GUI']['coming_eps_sort'] = COMING_EPS_SORT

new_config['Mdlesk'] = {}
new_config['Mdlesk']['use_mdlesk'] = int(USE_MDLESK)
new_config['Mdlesk']['mdlesk_notify_onsnatch'] = int(MDLESK_NOTIFY_ONSNATCH)
new_config['Mdlesk']['mdlesk_notify_ondownload'] = int(MDLESK_NOTIFY_ONDOWNLOAD)
new_config['Mdlesk']['mdlesk_server'] = MDLESK_SERVER
new_config['Mdlesk']['mdlesk_username'] = MDLESK_USERNAME
new_config['Mdlesk']['mdlesk_apikey'] = MDLESK_APIKEY
new_config['Mdlesk']['mdlesk_source'] = MDLESK_SOURCE

new_config.write()

Expand Down
3 changes: 3 additions & 0 deletions sickbeard/notifiers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import nma
import pushalot
import pushbullet
import mdlesk

import tweet
import trakt
Expand All @@ -57,6 +58,7 @@
nma_notifier = nma.NMA_Notifier()
pushalot_notifier = pushalot.PushalotNotifier()
pushbullet_notifier = pushbullet.PushbulletNotifier()
mdlesk_notifier = mdlesk.MdleskNotifier()
# social
twitter_notifier = tweet.TwitterNotifier()
trakt_notifier = trakt.TraktNotifier()
Expand All @@ -76,6 +78,7 @@
nma_notifier,
pushalot_notifier,
pushbullet_notifier,
mdlesk_notifier,
twitter_notifier,
trakt_notifier,
]
Expand Down
105 changes: 105 additions & 0 deletions sickbeard/notifiers/mdlesk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Author: Michael Dlesk <michaeldlesk@gmail.com>
# URL: http://code.google.com/p/sickbeard/
#
# This file is part of Sick Beard.
#
# Sick Beard is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Sick Beard is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.

import urllib
import urllib2
import socket
import base64

import sickbeard

from sickbeard import logger
from sickbeard.common import notifyStrings, NOTIFY_SNATCH, NOTIFY_DOWNLOAD
from sickbeard.exceptions import ex


class MdleskNotifier:

def _sendMdlesk(self, title, body, server, username, apikey, source):
logger.log(u"Starting")
requestParameters = ''
requestParameters = requestParameters + '?'
requestParameters = requestParameters + 'Username=%s' % urllib.quote_plus(username)
requestParameters = requestParameters + '&ApiKey=%s' % urllib.quote_plus(apikey)
requestParameters = requestParameters + '&Action=SendNotification'
requestParameters = requestParameters + '&Source=%s' % urllib.quote_plus(source)
requestParameters = requestParameters + '&Message=%s' % urllib.quote_plus(body)

requestUrl = server + requestParameters

# send the request to pushbullet
try:
logger.log(u"MDLESK: URL: " + requestUrl , logger.MESSAGE)
req = urllib2.Request(requestUrl)
handle = urllib2.urlopen(req)
handle.close()
except socket.timeout:
return False
except urllib2.URLError, e:
# FIXME: Python 2.5 hack, it wrongly reports 201 as an error
if hasattr(e, 'code') and e.code == 201:
logger.log(u"MDLESK: Notification successful.", logger.MESSAGE)
return True

# if we get an error back that doesn't have an error code then who knows what's really happening
if not hasattr(e, 'code'):
logger.log(u"MDLESK: Notification failed." + ex(e), logger.ERROR)
else:
logger.log(u"MDLESK: Notification failed. Error code: " + str(e.code), logger.ERROR)
return False

logger.log(u"MDLESK: Notification successful.", logger.MESSAGE)
return True

def _notify(self, title, body, server=None, username=None, apikey=None, source=None, force=False):

if not sickbeard.USE_MDLESK and not force:
return False

if not server:
server = sickbeard.MDLESK_SERVER
if not username:
username = sickbeard.MDLESK_USERNAME
if not apikey:
apikey = sickbeard.MDLESK_APIKEY
if not source:
source = sickbeard.MDLESK_SOURCE

logger.log(u"MDLESK: Sending notification with details: source=\"%s\", title=\"%s\", body=\"%s\", server=\"%s\", username=\"%s\", api=\"%s\"" % (source, title, body, server, username, apikey), logger.DEBUG)

return self._sendMdlesk(title, body, server, username, apikey, source)

##############################################################################
# Public functions
##############################################################################

def notify_snatch(self, ep_name):
if sickbeard.MDLESK_NOTIFY_ONSNATCH:
self._notify(notifyStrings[NOTIFY_SNATCH], ep_name)

def notify_download(self, ep_name):
if sickbeard.MDLESK_NOTIFY_ONDOWNLOAD:
self._notify(notifyStrings[NOTIFY_DOWNLOAD], ep_name)

def test_notify(self, server, username, apikey, source):
return self._notify("Test", "This is a test notification from Sick Beard", server, username, apikey, source, force=True)

def update_library(self, ep_obj=None):
pass

notifier = MdleskNotifier
22 changes: 21 additions & 1 deletion sickbeard/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,8 @@ def saveNotifications(self,
pytivo_host=None, pytivo_share_name=None, pytivo_tivo_name=None,
use_nma=None, nma_notify_onsnatch=None, nma_notify_ondownload=None, nma_api=None, nma_priority=None,
use_pushalot=None, pushalot_notify_onsnatch=None, pushalot_notify_ondownload=None, pushalot_authorizationtoken=None, pushalot_silent=None, pushalot_important=None,
use_pushbullet=None, pushbullet_notify_onsnatch=None, pushbullet_notify_ondownload=None, pushbullet_access_token=None, pushbullet_device_iden=None, pushbullet_device_list=None
use_pushbullet=None, pushbullet_notify_onsnatch=None, pushbullet_notify_ondownload=None, pushbullet_access_token=None, pushbullet_device_iden=None, pushbullet_device_list=None,
use_mdlesk=None, mdlesk_notify_onsnatch=None, mdlesk_notify_ondownload=None, mdlesk_server=None, mdlesk_username=None, mdlesk_apikey=None, mdlesk_source=None
):

results = []
Expand Down Expand Up @@ -1243,6 +1244,14 @@ def saveNotifications(self,
sickbeard.PUSHBULLET_NOTIFY_ONDOWNLOAD = config.checkbox_to_value(pushbullet_notify_ondownload)
sickbeard.PUSHBULLET_ACCESS_TOKEN = pushbullet_access_token
sickbeard.PUSHBULLET_DEVICE_IDEN = pushbullet_device_iden

sickbeard.USE_MDLESK = config.checkbox_to_value(use_mdlesk)
sickbeard.PMDLESK_NOTIFY_ONSNATCH = config.checkbox_to_value(mdlesk_notify_onsnatch)
sickbeard.MDLESK_NOTIFY_ONDOWNLOAD = config.checkbox_to_value(mdlesk_notify_ondownload)
sickbeard.MDLESK_SERVER = mdlesk_server
sickbeard.MDLESK_USERNAME = mdlesk_username
sickbeard.MDLESK_APIKEY = mdlesk_apikey
sickbeard.MDLESK_SOURCE = mdlesk_source

# Online
sickbeard.USE_TWITTER = config.checkbox_to_value(use_twitter)
Expand Down Expand Up @@ -2132,6 +2141,17 @@ def testPushbullet(self, accessToken=None, device_iden=None):
else:
return "Error sending Pushbullet notification"

@cherrypy.expose
def testMdlesk(self, server=None, username=None, apikey=None, source=None):
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"

result = notifiers.mdlesk_notifier.test_notify(server,username,apikey,source)
if result:
return "MDLESK notification succeeded. Check your MDLESK clients to make sure it worked"
else:
return "Error sending MDLESK notification"


@cherrypy.expose
def getPushbulletDevices(self, accessToken=None):
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
Expand Down