mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-01 08:53:37 +00:00
3fa750651c
Notifiers are now loaded into memory on demand. Add bubble links to Notifications config tabs. Add Discordapp notifier to Notifications config/Social. Add Gitter notifier to Notifications config/Social. Change order of notifiers in Notifications config tabs. Remove Pushalot notifier. Remove XBMC notifier. Refactor update_library, notify, test notify and test results functions. Change most IDs and vars consistent for HTML, CSS, JS, and Python - related to notifications, camelCase for JS, underscore separated lower_case for python, hyphen separated-lowercase for CSS. A couple of exceptions have been left untouched in this clean up. Change commented out some unused vars in preparation for later removal.
94 lines
3.1 KiB
Python
94 lines
3.1 KiB
Python
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
#
|
|
# This file is part of SickGear.
|
|
#
|
|
# SickGear is free software: you can redistribute it and/or modify
|
|
# 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.
|
|
#
|
|
# SickGear is distributed in the hope that it will be useful,
|
|
# 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
|
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import os
|
|
from urllib import urlencode
|
|
from urllib2 import Request, urlopen, HTTPError
|
|
|
|
import sickbeard
|
|
# noinspection PyPep8Naming
|
|
from sickbeard import encodingKludge as ek
|
|
from sickbeard.exceptions import ex
|
|
from sickbeard.notifiers.generic import BaseNotifier
|
|
|
|
|
|
class PyTivoNotifier(BaseNotifier):
|
|
|
|
def update_library(self, ep_obj=None, **kwargs):
|
|
|
|
host = sickbeard.PYTIVO_HOST
|
|
share_name = sickbeard.PYTIVO_SHARE_NAME
|
|
tsn = sickbeard.PYTIVO_TIVO_NAME
|
|
|
|
# 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.
|
|
#
|
|
|
|
# Calculated values
|
|
|
|
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
|
|
|
|
# Some show names have colons in them which are illegal in a path location, so strip them out.
|
|
# (Are there other characters?)
|
|
show_name = show_name.replace(':', '')
|
|
|
|
root = show_path.replace(show_name, '')
|
|
show_and_season = root_show_and_season.replace(root, '')
|
|
|
|
container = share_name + '/' + show_and_season
|
|
file_path = '/' + abs_path.replace(root, '')
|
|
|
|
# Finally create the url and make request
|
|
request_url = 'http://%s/TiVoConnect?%s' % (host, urlencode(
|
|
dict(Command='Push', Container=container, File=file_path, tsn=tsn)))
|
|
|
|
self._log_debug(u'Requesting ' + request_url)
|
|
|
|
request = Request(request_url)
|
|
|
|
try:
|
|
urlopen(request)
|
|
|
|
except HTTPError as e:
|
|
if hasattr(e, 'reason'):
|
|
self._log_error(u'Error, failed to reach a server - ' + e.reason)
|
|
return False
|
|
elif hasattr(e, 'code'):
|
|
self._log_error(u'Error, the server couldn\'t fulfill the request - ' + e.code)
|
|
return False
|
|
|
|
except Exception as e:
|
|
self._log_error(u'Unknown exception: ' + ex(e))
|
|
return False
|
|
|
|
self._log(u'Successfully requested transfer of file')
|
|
return True
|
|
|
|
|
|
notifier = PyTivoNotifier
|