2014-03-10 01:18:05 -04:00
|
|
|
# Author: 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
|
|
|
|
|
|
|
import os
|
|
|
|
import sickbeard
|
|
|
|
|
|
|
|
from urllib import urlencode
|
2014-05-26 02:29:22 -04:00
|
|
|
from urllib2 import Request, urlopen, HTTPError
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
from sickbeard import logger
|
2014-05-28 20:30:38 -04:00
|
|
|
from sickbeard.exceptions import ex
|
2014-03-10 01:18:05 -04:00
|
|
|
from sickbeard import encodingKludge as ek
|
|
|
|
|
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
class pyTivoNotifier:
|
2014-03-10 01:18:05 -04:00
|
|
|
def notify_snatch(self, ep_name):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def notify_download(self, ep_name):
|
|
|
|
pass
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
def notify_subtitle_download(self, ep_name, lang):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def update_library(self, ep_obj):
|
|
|
|
|
|
|
|
# Values from config
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
if not sickbeard.USE_PYTIVO:
|
|
|
|
return False
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
host = sickbeard.PYTIVO_HOST
|
|
|
|
shareName = sickbeard.PYTIVO_SHARE_NAME
|
|
|
|
tsn = sickbeard.PYTIVO_TIVO_NAME
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
# There are two more values required, the container and file.
|
|
|
|
#
|
|
|
|
# container: The share name, show name and season
|
|
|
|
#
|
|
|
|
# file: The file name
|
|
|
|
#
|
|
|
|
# Some slicing and dicing of variables is required to get at these values.
|
|
|
|
#
|
|
|
|
# There might be better ways to arrive at the values, but this is the best I have been able to
|
|
|
|
# come up with.
|
|
|
|
#
|
2014-03-25 01:57:24 -04:00
|
|
|
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
# Calculated values
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
showPath = ep_obj.show.location
|
|
|
|
showName = ep_obj.show.name
|
2014-03-25 01:57:24 -04:00
|
|
|
rootShowAndSeason = ek.ek(os.path.dirname, ep_obj.location)
|
2014-03-10 01:18:05 -04:00
|
|
|
absPath = ep_obj.location
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
# Some show names have colons in them which are illegal in a path location, so strip them out.
|
|
|
|
# (Are there other characters?)
|
2014-03-25 01:57:24 -04:00
|
|
|
showName = showName.replace(":", "")
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
root = showPath.replace(showName, "")
|
|
|
|
showAndSeason = rootShowAndSeason.replace(root, "")
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
container = shareName + "/" + showAndSeason
|
|
|
|
file = "/" + absPath.replace(root, "")
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
# Finally create the url and make request
|
2014-03-25 01:57:24 -04:00
|
|
|
requestUrl = "http://" + host + "/TiVoConnect?" + urlencode(
|
|
|
|
{'Command': 'Push', 'Container': container, 'File': file, 'tsn': tsn})
|
|
|
|
|
2014-05-28 20:30:38 -04:00
|
|
|
logger.log(u"pyTivo notification: Requesting " + requestUrl, logger.DEBUG)
|
2014-03-25 01:57:24 -04:00
|
|
|
|
|
|
|
request = Request(requestUrl)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
try:
|
2014-03-25 01:57:24 -04:00
|
|
|
response = urlopen(request) #@UnusedVariable
|
2014-05-26 02:29:22 -04:00
|
|
|
except HTTPError , e:
|
2014-03-10 01:18:05 -04:00
|
|
|
if hasattr(e, 'reason'):
|
2014-05-28 20:30:38 -04:00
|
|
|
logger.log(u"pyTivo notification: Error, failed to reach a server - " + e.reason, logger.ERROR)
|
2014-03-10 01:18:05 -04:00
|
|
|
return False
|
|
|
|
elif hasattr(e, 'code'):
|
2014-05-29 11:35:51 -04:00
|
|
|
logger.log(u"pyTivo notification: Error, the server couldn't fulfill the request - " + e.code, logger.ERROR)
|
2014-05-28 20:30:38 -04:00
|
|
|
return False
|
|
|
|
except Exception, e:
|
|
|
|
logger.log(u"PYTIVO: Unknown exception: " + ex(e), logger.ERROR)
|
|
|
|
return False
|
2014-03-10 01:18:05 -04:00
|
|
|
else:
|
|
|
|
logger.log(u"pyTivo notification: Successfully requested transfer of file")
|
|
|
|
return True
|
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
notifier = pyTivoNotifier
|