2014-03-10 05:18:05 +00:00
|
|
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# This file is part of SickGear.
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is free software: you can redistribute it and/or modify
|
2014-03-10 05:18:05 +00: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-11-12 16:43:14 +00:00
|
|
|
# SickGear is distributed in the hope that it will be useful,
|
2014-03-10 05:18:05 +00: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-11-12 16:43:14 +00:00
|
|
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
from urllib import urlencode
|
2014-05-26 06:29:22 +00:00
|
|
|
from urllib2 import Request, urlopen, HTTPError
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
import sickbeard
|
|
|
|
# noinspection PyPep8Naming
|
2014-03-10 05:18:05 +00:00
|
|
|
from sickbeard import encodingKludge as ek
|
2017-10-17 15:43:28 +00:00
|
|
|
from sickbeard.exceptions import ex
|
|
|
|
from sickbeard.notifiers.generic import BaseNotifier
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
class PyTivoNotifier(BaseNotifier):
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
def update_library(self, ep_obj=None, **kwargs):
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
host = sickbeard.PYTIVO_HOST
|
2017-10-17 15:43:28 +00:00
|
|
|
share_name = sickbeard.PYTIVO_SHARE_NAME
|
2014-03-10 05:18:05 +00:00
|
|
|
tsn = sickbeard.PYTIVO_TIVO_NAME
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
# There are two more values required, the container and file.
|
2017-10-17 15:43:28 +00:00
|
|
|
#
|
2014-03-10 05:18:05 +00:00
|
|
|
# container: The share name, show name and season
|
|
|
|
#
|
|
|
|
# file: The file name
|
2017-10-17 15:43:28 +00:00
|
|
|
#
|
2014-03-10 05:18:05 +00:00
|
|
|
# Some slicing and dicing of variables is required to get at these values.
|
|
|
|
#
|
2017-10-17 15:43:28 +00:00
|
|
|
# There might be better ways to arrive at the values, but this is the best I have been able to
|
2014-03-10 05:18:05 +00:00
|
|
|
# come up with.
|
|
|
|
#
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
# Calculated values
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
show_path = ep_obj.show.location
|
|
|
|
show_name = ep_obj.show.name
|
|
|
|
root_show_and_season = ek.ek(os.path.dirname, ep_obj.location)
|
|
|
|
abs_path = ep_obj.location
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
# Some show names have colons in them which are illegal in a path location, so strip them out.
|
|
|
|
# (Are there other characters?)
|
2017-10-17 15:43:28 +00:00
|
|
|
show_name = show_name.replace(':', '')
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
root = show_path.replace(show_name, '')
|
|
|
|
show_and_season = root_show_and_season.replace(root, '')
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
container = share_name + '/' + show_and_season
|
|
|
|
file_path = '/' + abs_path.replace(root, '')
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
# Finally create the url and make request
|
2017-10-17 15:43:28 +00:00
|
|
|
request_url = 'http://%s/TiVoConnect?%s' % (host, urlencode(
|
|
|
|
dict(Command='Push', Container=container, File=file_path, tsn=tsn)))
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
self._log_debug(u'Requesting ' + request_url)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
request = Request(request_url)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
try:
|
2017-10-17 15:43:28 +00:00
|
|
|
urlopen(request)
|
|
|
|
|
2015-06-08 12:47:01 +00:00
|
|
|
except HTTPError as e:
|
2014-03-10 05:18:05 +00:00
|
|
|
if hasattr(e, 'reason'):
|
2017-10-17 15:43:28 +00:00
|
|
|
self._log_error(u'Error, failed to reach a server - ' + e.reason)
|
2014-03-10 05:18:05 +00:00
|
|
|
return False
|
|
|
|
elif hasattr(e, 'code'):
|
2017-10-17 15:43:28 +00:00
|
|
|
self._log_error(u'Error, the server couldn\'t fulfill the request - ' + e.code)
|
2014-05-29 00:30:38 +00:00
|
|
|
return False
|
2017-10-17 15:43:28 +00:00
|
|
|
|
2015-06-08 12:47:01 +00:00
|
|
|
except Exception as e:
|
2017-10-17 15:43:28 +00:00
|
|
|
self._log_error(u'Unknown exception: ' + ex(e))
|
2014-05-29 00:30:38 +00:00
|
|
|
return False
|
2017-10-17 15:43:28 +00:00
|
|
|
|
|
|
|
self._log(u'Successfully requested transfer of file')
|
|
|
|
return True
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
notifier = PyTivoNotifier
|