Skip to content

Commit

Permalink
Merge branch 'PR-832_update_notifiers3' into development
Browse files Browse the repository at this point in the history
* PR-832_update_notifiers3: closes gh-832
  Update notifiers pass 3
  • Loading branch information
Patrick Vos committed May 20, 2014
2 parents f13fef7 + 5e152cf commit 0d7110b
Show file tree
Hide file tree
Showing 21 changed files with 318 additions and 200 deletions.
48 changes: 36 additions & 12 deletions data/interfaces/default/config_notifications.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


<br />
<h2>Home Theater</h2>
<h2>Home Theater / NAS</h2>
<br />


Expand Down Expand Up @@ -366,17 +366,18 @@

<div class="component-group clearfix">
<div class="component-group-desc">
<img class="notifier-icon" src="$sbRoot/images/notifiers/synoindex.png" alt="" title="Synology Indexer" />
<h3><a href="http://synology.com/" rel="noreferrer" onclick="window.open('${sickbeard.ANON_REDIRECT}' + this.href, '_blank'); return false;">Synology Indexer</a></h3>
<img class="notifier-icon" src="$sbRoot/images/notifiers/synoindex.png" alt="" title="Synology" />
<h3><a href="http://synology.com/" rel="noreferrer" onclick="window.open('${sickbeard.ANON_REDIRECT}' + this.href, '_blank'); return false;">Synology</a></h3>
<p>The Synology DiskStation NAS.</p>
<p>Synology Indexer is the daemon running on the Synology NAS to build its media database.</p>
<p>Synology Notifier is the notification system of Synology DSM.</p>
</div>

<fieldset class="component-group-list">
<div class="field-pair">
<input type="checkbox" class="enabler" name="use_synoindex" id="use_synoindex" #if $sickbeard.USE_SYNOINDEX then "checked=\"checked\"" else ""# />
<label class="clearfix" for="use_synoindex">
<span class="component-title">Enable</span>
<span class="component-desc">Should Sick Beard send notifications to the synoindex daemon?<br /><br />
<span class="component-desc">Should Sick Beard send Synology commands?<br /><br />
</span>
</label>
<label class="nocheck clearfix" for="use_synoindex">
Expand All @@ -386,8 +387,31 @@
</div>

<div id="content_use_synoindex">
<div class="field-pair">
<input type="checkbox" name="synoindex_notify_onsnatch" id="synoindex_notify_onsnatch" #if $sickbeard.SYNOINDEX_NOTIFY_ONSNATCH then "checked=\"checked\"" else ""# />
<label class="clearfix" for="synoindex_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="synoindex_notify_ondownload" id="synoindex_notify_ondownload" #if $sickbeard.SYNOINDEX_NOTIFY_ONDOWNLOAD then "checked=\"checked\"" else ""# />
<label class="clearfix" for="synoindex_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">
<input type="checkbox" name="synoindex_update_library" id="synoindex_update_library" #if $sickbeard.SYNOINDEX_UPDATE_LIBRARY then "checked=\"checked\"" else ""# />
<label class="clearfix" for="synoindex_update_library">
<span class="component-title">Update Library</span>
<span class="component-desc">Update Synology library when we finish a download?</span>
</label>
</div>
<div class="testNotification" id="testSynoNotify-result">Click below to test.</div>
<input type="button" class="btn" value="Test Notice (SynoDSMnotify)" id="testSynoNotify" />
<input type="submit" class="btn config_submitter" value="Save Changes" />
</div><!-- /content_use_pytivo //-->
</div><!-- /content_use_synoindex //-->

</fieldset>
</div><!-- /synoindex component-group //-->
Expand All @@ -397,14 +421,14 @@
<div class="component-group-desc">
<img class="notifier-icon" src="$sbRoot/images/notifiers/pytivo.png" alt="" title="pyTivo" />
<h3><a href="http://pytivo.sourceforge.net/wiki/index.php/PyTivo" rel="noreferrer" onclick="window.open('${sickbeard.ANON_REDIRECT}' + this.href, '_blank'); return false;">pyTivo</a></h3>
<p>pyTivo is both an HMO and GoBack server. This notifier will load the completed downloads to your Tivo.</p>
<p>pyTivo is both an HMO and GoBack server. This notifier will load the completed downloads to your Tivo.</p>
</div>
<fieldset class="component-group-list">
<div class="field-pair">
<input type="checkbox" class="enabler" name="use_pytivo" id="use_pytivo" #if $sickbeard.USE_PYTIVO then "checked=\"checked\"" else ""# />
<label class="clearfix" for="use_pytivo">
<span class="component-title">Enable</span>
<span class="component-desc">Should Sick Beard send notifications to pyTivo?<br /><br /></span>
<span class="component-desc">Should Sick Beard update commands to pyTivo?<br /><br /></span>
</label>
<label class="nocheck clearfix" for="use_pytivo">
<span class="component-title">&nbsp;</span>
Expand Down Expand Up @@ -637,7 +661,7 @@
<input type="checkbox" class="enabler" name="use_pushover" id="use_pushover" #if $sickbeard.USE_PUSHOVER then "checked=\"checked\"" else ""# />
<label class="clearfix" for="use_pushover">
<span class="component-title">Enable</span>
<span class="component-desc">Should Sick Beard send notifications through Pushover?</span>
<span class="component-desc">Should Sick Beard send Pushover notifications?</span>
</label>
</div>

Expand Down Expand Up @@ -678,14 +702,14 @@
<div class="component-group-desc">
<img class="notifier-icon" src="$sbRoot/images/notifiers/boxcar.png" alt="" title="Boxcar" />
<h3><a href="http://boxcar.io/" rel="noreferrer" onclick="window.open('${sickbeard.ANON_REDIRECT}' + this.href, '_blank'); return false;">Boxcar</a></h3>
<p>Read your messages where and when you want them! A subscription will be sent if needed.</p>
<p>Universal push notification for iOS. Read your messages where and when you want them! A subscription will be sent if needed.</p>
</div>
<fieldset class="component-group-list">
<div class="field-pair">
<input type="checkbox" class="enabler" name="use_boxcar" id="use_boxcar" #if $sickbeard.USE_BOXCAR then "checked=\"checked\"" else ""# />
<label class="clearfix" for="use_boxcar">
<span class="component-title">Enable</span>
<span class="component-desc">Should Sick Beard send notifications through Boxcar?</span>
<span class="component-desc">Should Sick Beard send Boxcar notifications?</span>
</label>
</div>

Expand Down Expand Up @@ -792,7 +816,7 @@
</div><br />

<br />
<h2>Online</h2>
<h2>Social</h2>
<br />


Expand Down
11 changes: 11 additions & 0 deletions data/js/configNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,15 @@ $(document).ready(function () {
$("#testNMA").attr("disabled", false);
});
});

$("#testSynoNotify").click(function () {
$(this).attr("disabled", true);
$("#testSynoNotify-result").html(loading);
$.get(sbRoot + "/home/testSynoNotify")
.done(function (data) {
$("#testSynoNotify-result").html(data);
$("#testSynoNotify").attr("disabled", false);
});
});

});
14 changes: 12 additions & 2 deletions sickbeard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
CONFIG_FILE = None

# this is the version of the config we EXPECT to find
CONFIG_VERSION = 5
CONFIG_VERSION = 6

PROG_DIR = '.'
MY_FULLNAME = None
Expand Down Expand Up @@ -267,6 +267,9 @@
NMJ_MOUNT = None

USE_SYNOINDEX = False
SYNOINDEX_NOTIFY_ONSNATCH = False
SYNOINDEX_NOTIFY_ONDOWNLOAD = False
SYNOINDEX_UPDATE_LIBRARY = False

USE_NMJv2 = False
NMJv2_HOST = None
Expand Down Expand Up @@ -341,7 +344,8 @@ def initialize(consoleLogging=True):
EXTRA_SCRIPTS, USE_TWITTER, TWITTER_USERNAME, TWITTER_PASSWORD, TWITTER_PREFIX, \
USE_BOXCAR, BOXCAR_USERNAME, BOXCAR_PASSWORD, BOXCAR_NOTIFY_ONDOWNLOAD, BOXCAR_NOTIFY_ONSNATCH, \
USE_PUSHOVER, PUSHOVER_USERKEY, PUSHOVER_NOTIFY_ONDOWNLOAD, PUSHOVER_NOTIFY_ONSNATCH, \
USE_LIBNOTIFY, LIBNOTIFY_NOTIFY_ONSNATCH, LIBNOTIFY_NOTIFY_ONDOWNLOAD, USE_NMJ, NMJ_HOST, NMJ_DATABASE, NMJ_MOUNT, USE_NMJv2, NMJv2_HOST, NMJv2_DATABASE, NMJv2_DBLOC, USE_SYNOINDEX, \
USE_LIBNOTIFY, LIBNOTIFY_NOTIFY_ONSNATCH, LIBNOTIFY_NOTIFY_ONDOWNLOAD, USE_NMJ, NMJ_HOST, NMJ_DATABASE, NMJ_MOUNT, USE_NMJv2, NMJv2_HOST, NMJv2_DATABASE, NMJv2_DBLOC, \
USE_SYNOINDEX, SYNOINDEX_NOTIFY_ONSNATCH, SYNOINDEX_NOTIFY_ONDOWNLOAD, SYNOINDEX_UPDATE_LIBRARY, \
USE_LISTVIEW, METADATA_XBMC, METADATA_XBMC_12PLUS, METADATA_MEDIABROWSER, METADATA_MEDE8ER, METADATA_PS3, metadata_provider_dict, \
GIT_PATH, MOVE_ASSOCIATED_FILES, \
COMING_EPS_LAYOUT, COMING_EPS_SORT, COMING_EPS_DISPLAY_PAUSED, METADATA_WDTV, METADATA_TIVO, IGNORE_WORDS, CREATE_MISSING_SHOW_DIRS, \
Expand Down Expand Up @@ -602,6 +606,9 @@ def initialize(consoleLogging=True):

CheckSection(CFG, 'Synology')
USE_SYNOINDEX = bool(check_setting_int(CFG, 'Synology', 'use_synoindex', 0))
SYNOINDEX_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Synology', 'synoindex_notify_onsnatch', 0))
SYNOINDEX_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Synology', 'synoindex_notify_ondownload', 0))
SYNOINDEX_UPDATE_LIBRARY = bool(check_setting_int(CFG, 'Synology', 'synoindex_update_library', 0))

CheckSection(CFG, 'Trakt')
USE_TRAKT = bool(check_setting_int(CFG, 'Trakt', 'use_trakt', 0))
Expand Down Expand Up @@ -1125,6 +1132,9 @@ def save_config():

new_config['Synology'] = {}
new_config['Synology']['use_synoindex'] = int(USE_SYNOINDEX)
new_config['Synology']['synoindex_notify_onsnatch'] = int(SYNOINDEX_NOTIFY_ONSNATCH)
new_config['Synology']['synoindex_notify_ondownload'] = int(SYNOINDEX_NOTIFY_ONDOWNLOAD)
new_config['Synology']['synoindex_update_library'] = int(SYNOINDEX_UPDATE_LIBRARY)

new_config['NMJv2'] = {}
new_config['NMJv2']['use_nmjv2'] = int(USE_NMJv2)
Expand Down
7 changes: 7 additions & 0 deletions sickbeard/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,10 @@ def _migrate_metadata(metadata, metadata_name, use_banner):
sickbeard.METADATA_WDTV = _migrate_metadata(metadata_wdtv, 'WDTV', use_banner)
sickbeard.METADATA_TIVO = _migrate_metadata(metadata_tivo, 'TIVO', use_banner)
sickbeard.METADATA_MEDE8ER = _migrate_metadata(metadata_mede8er, 'Mede8er', use_banner)

# Migration v6: Synology notifier update
def _migrate_v6(self):
""" Updates Synology notifier to reflect that their now is an update library option instead misusing the enable option """

# clone use_synoindex to update_library since this now has notification options
sickbeard.SYNOINDEX_UPDATE_LIBRARY = bool(check_setting_int(self.config_obj, 'Synology', 'use_synoindex', 0))
25 changes: 18 additions & 7 deletions sickbeard/notifiers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
import trakt

from sickbeard.common import *
from sickbeard import logger
from sickbeard.exceptions import ex

# home theater
# home theater/nas
xbmc_notifier = xbmc.XBMCNotifier()
plex_notifier = plex.PLEXNotifier()
nmj_notifier = nmj.NMJNotifier()
synoindex_notifier = synoindex.synoIndexNotifier()
nmjv2_notifier = nmjv2.NMJv2Notifier()
synoindex_notifier = synoindex.synoIndexNotifier()
pytivo_notifier = pytivo.pyTivoNotifier()
# devices
growl_notifier = growl.GrowlNotifier()
Expand All @@ -51,12 +53,12 @@
pushover_notifier = pushover.PushoverNotifier()
boxcar_notifier = boxcar.BoxcarNotifier()
nma_notifier = nma.NMA_Notifier()
# online
# social
twitter_notifier = tweet.TwitterNotifier()
trakt_notifier = trakt.TraktNotifier()

notifiers = [
libnotify_notifier, # Libnotify notifier goes first because it doesn't involve blocking on network activity.
libnotify_notifier, # Libnotify notifier goes first because it doesn't involve blocking on network activity.
xbmc_notifier,
plex_notifier,
nmj_notifier,
Expand All @@ -75,14 +77,23 @@

def notify_download(ep_name):
for n in notifiers:
n.notify_download(ep_name)
try:
n.notify_download(ep_name)
except Exception, e:
logger.log(n.__class__.__name__ + ": " + ex(e), logger.ERROR)


def notify_snatch(ep_name):
for n in notifiers:
n.notify_snatch(ep_name)
try:
n.notify_snatch(ep_name)
except Exception, e:
logger.log(n.__class__.__name__ + ": " + ex(e), logger.ERROR)


def update_library(ep_obj):
for n in notifiers:
n.update_library(ep_obj)
try:
n.update_library(ep_obj=ep_obj)
except Exception, e:
logger.log(n.__class__.__name__ + ": " + ex(e), logger.ERROR)
18 changes: 8 additions & 10 deletions sickbeard/notifiers/boxcar.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,17 @@ def _sendBoxcar(self, msg, title, email, subscribe=False):

# send the request to boxcar
try:
# TODO: Use our getURL from helper?
req = urllib2.Request(curUrl)
handle = urllib2.urlopen(req, data)
handle.close()

except urllib2.URLError, e:
# 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"BOXCAR: Boxcar notification failed." + ex(e), logger.ERROR)
logger.log(u"BOXCAR: Notification failed." + ex(e), logger.ERROR)
return False
else:
logger.log(u"BOXCAR: Boxcar notification failed. Error code: " + str(e.code), logger.WARNING)
logger.log(u"BOXCAR: Notification failed. Error code: " + str(e.code), logger.ERROR)

# HTTP status 404 if the provided email address isn't a Boxcar user.
if e.code == 404:
Expand Down Expand Up @@ -103,10 +102,10 @@ def _sendBoxcar(self, msg, title, email, subscribe=False):

# If you receive an HTTP status code of 400, it is because you failed to send the proper parameters
elif e.code == 400:
logger.log(u"BOXCAR: Wrong data send to boxcar.", logger.ERROR)
logger.log(u"BOXCAR: Wrong data sent to boxcar.", logger.ERROR)
return False

logger.log(u"BOXCAR: Boxcar notification successful.", logger.DEBUG)
logger.log(u"BOXCAR: Notification successful.", logger.MESSAGE)
return True

def _notify(self, title, message, username=None, force=False):
Expand All @@ -129,8 +128,7 @@ def _notify(self, title, message, username=None, force=False):

logger.log(u"BOXCAR: Sending notification for " + message, logger.DEBUG)

self._sendBoxcar(message, title, username)
return True
return self._sendBoxcar(message, title, username)

##############################################################################
# Public functions
Expand All @@ -144,10 +142,10 @@ def notify_download(self, ep_name):
if sickbeard.BOXCAR_NOTIFY_ONDOWNLOAD:
self._notify(notifyStrings[NOTIFY_DOWNLOAD], ep_name)

def test_notify(self, email, title="Test"):
return self._sendBoxcar("This is a test notification from SickBeard", title, email)
def test_notify(self, boxcar_username):
return self._notify("This is a test notification from Sick Beard", "Test", boxcar_username, force=True)

def update_library(self, showName=None):
def update_library(self, ep_obj=None):
pass

notifier = BoxcarNotifier
8 changes: 4 additions & 4 deletions sickbeard/notifiers/growl.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def _notify(self, title="Sick Beard Notification", message=None, name=None, host
print pc
opts['host'] = pc[0]
opts['port'] = pc[1]
logger.log(u"GROWL: Sending message '" + message + "' to " + opts['host'] + ":" + str(opts['port']))
logger.log(u"GROWL: Sending message '" + message + "' to " + opts['host'] + ":" + str(opts['port']), logger.DEBUG)
try:
return self._send_growl(opts, message)
except Exception, e:
logger.log(u"GROWL: Unable to send growl to " + opts['host'] + ":" + str(opts['port']) + " - " + ex(e))
logger.log(u"GROWL: Unable to send growl to " + opts['host'] + ":" + str(opts['port']) + " - " + ex(e), logger.WARNING)
return False

def _sendRegistration(self, host=None, password=None, name="Sick Beard Notification"):
Expand Down Expand Up @@ -161,7 +161,7 @@ def _sendRegistration(self, host=None, password=None, name="Sick Beard Notificat
try:
return self._send(opts['host'], opts['port'], register.encode(), opts['debug'])
except Exception, e:
logger.log(u"GROWL: Unable to send growl to " + opts['host'] + ":" + str(opts['port']) + " - " + ex(e))
logger.log(u"GROWL: Unable to send growl to " + opts['host'] + ":" + str(opts['port']) + " - " + ex(e), logger.WARNING)
return False

##############################################################################
Expand All @@ -183,7 +183,7 @@ def test_notify(self, host, password):
else:
return result

def update_library(self, showName=None):
def update_library(self, ep_obj=None):
pass

notifier = GrowlNotifier
8 changes: 4 additions & 4 deletions sickbeard/notifiers/libnotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ def init_pynotify(self):
try:
import pynotify
except ImportError:
logger.log(u"LIBNOTIFY: Unable to import pynotify. libnotify notifications won't work.")
logger.log(u"LIBNOTIFY: Unable to import pynotify. libnotify notifications won't work.", logger.ERROR)
return False
try:
import gobject
except ImportError:
logger.log(u"LIBNOTIFY: Unable to import gobject. We can't catch a GError in display.")
logger.log(u"LIBNOTIFY: Unable to import gobject. We can't catch a GError in display.", logger.ERROR)
return False
if not pynotify.init('Sick Beard'):
logger.log(u"LIBNOTIFY: Initialization of pynotify failed. libnotify notifications won't work.")
logger.log(u"LIBNOTIFY: Initialization of pynotify failed. libnotify notifications won't work.", logger.ERROR)
return False
self.pynotify = pynotify
self.gobject = gobject
Expand Down Expand Up @@ -119,7 +119,7 @@ def notify_download(self, ep_name):
def test_notify(self):
return self._notify("Test notification", "This is a test notification from Sick Beard", force=True)

def update_library(self, showName=None):
def update_library(self, ep_obj=None):
pass

notifier = LibnotifyNotifier
Loading

0 comments on commit 0d7110b

Please sign in to comment.