2014-03-10 01:18:05 -04:00
|
|
|
# Author: Maciej Olesinski (https://github.com/molesinski/)
|
|
|
|
# Based on prowl.py by Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-05-23 08:37:22 -04:00
|
|
|
# This file is part of SickRage.
|
2014-03-10 01:18:05 -04:00
|
|
|
#
|
2014-05-23 08:37:22 -04:00
|
|
|
# SickRage is free software: you can redistribute it and/or modify
|
2014-03-10 01:18:05 -04:00
|
|
|
# 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.
|
|
|
|
#
|
2014-05-23 08:37:22 -04:00
|
|
|
# SickRage is distributed in the hope that it will be useful,
|
2014-03-10 01:18:05 -04:00
|
|
|
# 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
|
2014-05-23 08:37:22 -04:00
|
|
|
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
from httplib import HTTPSConnection, HTTPException
|
|
|
|
from urllib import urlencode
|
|
|
|
from ssl import SSLError
|
|
|
|
|
|
|
|
import sickbeard
|
|
|
|
from sickbeard import logger, common
|
|
|
|
|
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
class PushalotNotifier:
|
2014-03-10 01:18:05 -04:00
|
|
|
def test_notify(self, pushalot_authorizationtoken):
|
2014-03-25 01:57:24 -04:00
|
|
|
return self._sendPushalot(pushalot_authorizationtoken, event="Test",
|
2014-05-23 08:37:22 -04:00
|
|
|
message="Testing Pushalot settings from SickRage", force=True)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
def notify_snatch(self, ep_name):
|
|
|
|
if sickbeard.PUSHALOT_NOTIFY_ONSNATCH:
|
2014-03-25 01:57:24 -04:00
|
|
|
self._sendPushalot(pushalot_authorizationtoken=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.PUSHALOT_NOTIFY_ONDOWNLOAD:
|
2014-03-25 01:57:24 -04:00
|
|
|
self._sendPushalot(pushalot_authorizationtoken=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.PUSHALOT_NOTIFY_ONSUBTITLEDOWNLOAD:
|
2014-03-25 01:57:24 -04:00
|
|
|
self._sendPushalot(pushalot_authorizationtoken=None,
|
|
|
|
event=common.notifyStrings[common.NOTIFY_SUBTITLE_DOWNLOAD],
|
|
|
|
message=ep_name + ": " + lang)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
def _sendPushalot(self, pushalot_authorizationtoken=None, event=None, message=None, force=False):
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
if not sickbeard.USE_PUSHALOT and not force:
|
2014-03-25 01:57:24 -04:00
|
|
|
return False
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
if pushalot_authorizationtoken == None:
|
2014-03-10 01:18:05 -04:00
|
|
|
pushalot_authorizationtoken = sickbeard.PUSHALOT_AUTHORIZATIONTOKEN
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
logger.log(u"Pushalot event: " + event, logger.DEBUG)
|
|
|
|
logger.log(u"Pushalot message: " + message, logger.DEBUG)
|
|
|
|
logger.log(u"Pushalot api: " + pushalot_authorizationtoken, logger.DEBUG)
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
http_handler = HTTPSConnection("pushalot.com")
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
data = {'AuthorizationToken': pushalot_authorizationtoken,
|
|
|
|
'Title': event.encode('utf-8'),
|
2014-03-25 01:57:24 -04:00
|
|
|
'Body': message.encode('utf-8')}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
http_handler.request("POST",
|
2014-03-25 01:57:24 -04:00
|
|
|
"/api/sendmessage",
|
|
|
|
headers={'Content-type': "application/x-www-form-urlencoded"},
|
|
|
|
body=urlencode(data))
|
2014-03-10 01:18:05 -04:00
|
|
|
except (SSLError, HTTPException):
|
|
|
|
logger.log(u"Pushalot notification failed.", logger.ERROR)
|
|
|
|
return False
|
|
|
|
response = http_handler.getresponse()
|
|
|
|
request_status = response.status
|
|
|
|
|
|
|
|
if request_status == 200:
|
2014-03-25 01:57:24 -04:00
|
|
|
logger.log(u"Pushalot notifications sent.", logger.DEBUG)
|
|
|
|
return True
|
|
|
|
elif request_status == 410:
|
|
|
|
logger.log(u"Pushalot auth failed: %s" % response.reason, logger.ERROR)
|
|
|
|
return False
|
2014-03-10 01:18:05 -04:00
|
|
|
else:
|
2014-03-25 01:57:24 -04:00
|
|
|
logger.log(u"Pushalot notification failed.", logger.ERROR)
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
notifier = PushalotNotifier
|