2014-03-10 05:18:05 +00:00
|
|
|
import sickbeard
|
|
|
|
|
|
|
|
from sickbeard import logger, common
|
|
|
|
from lib.pynma import pynma
|
|
|
|
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
class NMA_Notifier:
|
|
|
|
def test_notify(self, nma_api, nma_priority):
|
2014-11-12 16:43:14 +00:00
|
|
|
return self._sendNMA(nma_api, nma_priority, event="Test", message="Testing NMA settings from SickGear",
|
2014-03-25 05:57:24 +00:00
|
|
|
force=True)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def notify_snatch(self, ep_name):
|
|
|
|
if sickbeard.NMA_NOTIFY_ONSNATCH:
|
2014-03-25 05:57:24 +00:00
|
|
|
self._sendNMA(nma_api=None, nma_priority=None, event=common.notifyStrings[common.NOTIFY_SNATCH],
|
|
|
|
message=ep_name)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def notify_download(self, ep_name):
|
|
|
|
if sickbeard.NMA_NOTIFY_ONDOWNLOAD:
|
2014-03-25 05:57:24 +00:00
|
|
|
self._sendNMA(nma_api=None, nma_priority=None, event=common.notifyStrings[common.NOTIFY_DOWNLOAD],
|
|
|
|
message=ep_name)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def notify_subtitle_download(self, ep_name, lang):
|
|
|
|
if sickbeard.NMA_NOTIFY_ONSUBTITLEDOWNLOAD:
|
2014-03-25 05:57:24 +00:00
|
|
|
self._sendNMA(nma_api=None, nma_priority=None, event=common.notifyStrings[common.NOTIFY_SUBTITLE_DOWNLOAD],
|
|
|
|
message=ep_name + ": " + lang)
|
2014-07-03 06:43:48 +00:00
|
|
|
|
2014-07-03 21:04:26 +00:00
|
|
|
def notify_git_update(self, new_version = "??"):
|
2014-07-03 06:43:48 +00:00
|
|
|
if sickbeard.USE_NMA:
|
2014-07-03 21:04:26 +00:00
|
|
|
update_text=common.notifyStrings[common.NOTIFY_GIT_UPDATE_TEXT]
|
|
|
|
title=common.notifyStrings[common.NOTIFY_GIT_UPDATE]
|
2014-07-03 06:43:48 +00:00
|
|
|
self._sendNMA(nma_api=None, nma_priority=None, event=title, message=update_text + new_version)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
def _sendNMA(self, nma_api=None, nma_priority=None, event=None, message=None, force=False):
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-11-12 16:43:14 +00:00
|
|
|
title = 'SickGear'
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
if not sickbeard.USE_NMA and not force:
|
|
|
|
return False
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-20 18:03:22 +00:00
|
|
|
if nma_api == None:
|
2014-03-10 05:18:05 +00:00
|
|
|
nma_api = sickbeard.NMA_API
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-20 18:03:22 +00:00
|
|
|
if nma_priority == None:
|
2014-03-10 05:18:05 +00:00
|
|
|
nma_priority = sickbeard.NMA_PRIORITY
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
batch = False
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
p = pynma.PyNMA()
|
|
|
|
keys = nma_api.split(',')
|
|
|
|
p.addkey(keys)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
if len(keys) > 1: batch = True
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-05-29 00:30:38 +00:00
|
|
|
logger.log("NMA: Sending notice with details: event=\"%s\", message=\"%s\", priority=%s, batch=%s" % (event, message, nma_priority, batch), logger.DEBUG)
|
2014-03-10 05:18:05 +00:00
|
|
|
response = p.push(title, event, message, priority=nma_priority, batch_mode=batch)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
if not response[nma_api][u'code'] == u'200':
|
|
|
|
logger.log(u'Could not send notification to NotifyMyAndroid', logger.ERROR)
|
|
|
|
return False
|
|
|
|
else:
|
2014-05-29 00:30:38 +00:00
|
|
|
logger.log(u"NMA: Notification sent to NotifyMyAndroid", logger.MESSAGE)
|
2014-03-10 05:18:05 +00:00
|
|
|
return True
|
2014-03-25 05:57:24 +00:00
|
|
|
|
|
|
|
|
2014-05-29 00:30:38 +00:00
|
|
|
notifier = NMA_Notifier
|