2014-03-10 01:18:05 -04:00
|
|
|
import sickbeard
|
|
|
|
|
|
|
|
from sickbeard import logger, common
|
|
|
|
from lib.pynma import pynma
|
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
class NMA_Notifier:
|
|
|
|
def test_notify(self, nma_api, nma_priority):
|
2014-05-23 08:37:22 -04:00
|
|
|
return self._sendNMA(nma_api, nma_priority, event="Test", message="Testing NMA settings from SickRage",
|
2014-03-25 01:57:24 -04:00
|
|
|
force=True)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
def notify_snatch(self, ep_name):
|
|
|
|
if sickbeard.NMA_NOTIFY_ONSNATCH:
|
2014-03-25 01:57:24 -04:00
|
|
|
self._sendNMA(nma_api=None, nma_priority=None, event=common.notifyStrings[common.NOTIFY_SNATCH],
|
|
|
|
message=ep_name)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
def notify_download(self, ep_name):
|
|
|
|
if sickbeard.NMA_NOTIFY_ONDOWNLOAD:
|
2014-03-25 01:57:24 -04:00
|
|
|
self._sendNMA(nma_api=None, nma_priority=None, event=common.notifyStrings[common.NOTIFY_DOWNLOAD],
|
|
|
|
message=ep_name)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
def notify_subtitle_download(self, ep_name, lang):
|
|
|
|
if sickbeard.NMA_NOTIFY_ONSUBTITLEDOWNLOAD:
|
2014-03-25 01:57:24 -04:00
|
|
|
self._sendNMA(nma_api=None, nma_priority=None, event=common.notifyStrings[common.NOTIFY_SUBTITLE_DOWNLOAD],
|
|
|
|
message=ep_name + ": " + lang)
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
def _sendNMA(self, nma_api=None, nma_priority=None, event=None, message=None, force=False):
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
title = 'Sick-Beard'
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
if not sickbeard.USE_NMA and not force:
|
|
|
|
return False
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
if nma_api == None:
|
2014-03-10 01:18:05 -04:00
|
|
|
nma_api = sickbeard.NMA_API
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
if nma_priority == None:
|
2014-03-10 01:18:05 -04:00
|
|
|
nma_priority = sickbeard.NMA_PRIORITY
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
logger.log(u"NMA title: " + title, logger.DEBUG)
|
|
|
|
logger.log(u"NMA event: " + event, logger.DEBUG)
|
|
|
|
logger.log(u"NMA message: " + message, logger.DEBUG)
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
batch = False
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
p = pynma.PyNMA()
|
|
|
|
keys = nma_api.split(',')
|
|
|
|
p.addkey(keys)
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
if len(keys) > 1: batch = True
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
response = p.push(title, event, message, priority=nma_priority, batch_mode=batch)
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
if not response[nma_api][u'code'] == u'200':
|
|
|
|
logger.log(u'Could not send notification to NotifyMyAndroid', logger.ERROR)
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
2014-03-25 01:57:24 -04:00
|
|
|
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
notifier = NMA_Notifier
|