Added connection test to the rest of downloaders

This commit is contained in:
mikke89
2014-01-21 00:24:36 +01:00
parent 964ed5f497
commit 009d6cafaf
8 changed files with 95 additions and 4 deletions
+14 -1
View File
@@ -19,6 +19,7 @@ class Deluge(Downloader):
protocol = ['torrent', 'torrent_magnet']
log = CPLog(__name__)
drpc = None
testable = True
def connect(self):
# Load host from config and split out port.
@@ -27,11 +28,16 @@ class Deluge(Downloader):
log.error('Config properties are not filled in correctly, port is missing.')
return False
if not self.drpc:
if not (self.drpc and self.drpc.test()):
self.drpc = DelugeRPC(host[0], port = host[1], username = self.conf('username'), password = self.conf('password'))
return self.drpc
def test(self):
if self.connect() and self.drpc.test():
return True
return False
def download(self, data = None, media = None, filedata = None):
if not media: media = {}
if not data: data = {}
@@ -178,6 +184,13 @@ class DelugeRPC(object):
self.client = DelugeClient()
self.client.connect(self.host, int(self.port), self.username, self.password)
def test(self):
try:
self.connect()
except:
return False
return True
def add_torrent_magnet(self, torrent, options):
torrent_id = False
try:
@@ -18,6 +18,28 @@ class NZBGet(Downloader):
protocol = ['nzb']
rpc = 'xmlrpc'
testable = True
def test(self):
url = cleanHost(host = self.conf('host'), ssl = self.conf('ssl'), username = self.conf('username'), password = self.conf('password')) + self.rpc
rpc = xmlrpclib.ServerProxy(url)
try:
if rpc.writelog('INFO', 'CouchPotato connected to test connection'):
log.debug('Successfully connected to NZBGet')
else:
log.info('Successfully connected to NZBGet, but unable to send a message')
except socket.error:
log.error('NZBGet is not responding. Please ensure that NZBGet is running and host setting is correct.')
return False
except xmlrpclib.ProtocolError as e:
if e.errcode == 401:
log.error('Password is incorrect.')
else:
log.error('Protocol Error: %s', e)
return False
return True
def download(self, data = None, media = None, filedata = None):
if not media: media = {}
@@ -24,6 +24,15 @@ class NZBVortex(Downloader):
protocol = ['nzb']
api_level = None
session_id = None
testable = True
def test(self):
try:
login_result = self.login()
except:
return False
return login_result
def download(self, data = None, media = None, filedata = None):
if not media: media = {}
+11 -2
View File
@@ -18,6 +18,7 @@ class rTorrent(Downloader):
protocol = ['torrent', 'torrent_magnet']
rt = None
testable = True
# Migration url to host options
def __init__(self):
@@ -37,9 +38,9 @@ class rTorrent(Downloader):
self.deleteConf('url')
def connect(self):
def connect(self, reconnect = False):
# Already connected?
if self.rt is not None:
if not reconnect and self.rt is not None:
return self.rt
url = cleanHost(self.conf('host'), protocol = True, ssl = self.conf('ssl')) + '/' + self.conf('rpc_url').strip('/ ') + '/'
@@ -53,8 +54,16 @@ class rTorrent(Downloader):
else:
self.rt = RTorrent(url)
if not self.rt.test_connection():
self.rt = None
return self.rt
def test(self):
if not self.connect(True):
return False
return True
def _update_provider_group(self, name, data):
if data.get('seed_time'):
log.info('seeding time ignored, not supported')
@@ -15,6 +15,17 @@ log = CPLog(__name__)
class Sabnzbd(Downloader):
protocol = ['nzb']
testable = True
def test(self):
try:
queue = self.call({
'mode': 'version',
})
except:
return False
return bool(queue)
def download(self, data = None, media = None, filedata = None):
if not media: media = {}
@@ -13,6 +13,17 @@ class Synology(Downloader):
protocol = ['nzb', 'torrent', 'torrent_magnet']
status_support = False
testable = True
def test(self):
host = cleanHost(self.conf('host'), protocol = False).split(':')
try:
srpc = SynologyRPC(host[0], host[1], self.conf('username'), self.conf('password'))
test_result = srpc.test()
except:
return False
return test_result
def download(self, data = None, media = None, filedata = None):
if not media: media = {}
@@ -147,3 +158,6 @@ class SynologyRPC(object):
self._logout()
return result
def test(self):
return bool(self._login())
@@ -18,6 +18,7 @@ class Transmission(Downloader):
protocol = ['torrent', 'torrent_magnet']
log = CPLog(__name__)
trpc = None
testable = True
def connect(self):
# Load host from config and split out port.
@@ -26,11 +27,16 @@ class Transmission(Downloader):
log.error('Config properties are not filled in correctly, port is missing.')
return False
if not self.trpc:
if not (self.trpc and self.trpc.get_session()):
self.trpc = TransmissionRPC(host[0], port = host[1], rpc_url = self.conf('rpc_url').strip('/ '), username = self.conf('username'), password = self.conf('password'))
return self.trpc
def test(self):
if self.connect() and self.trpc.get_session():
return True
return False
def download(self, data = None, media = None, filedata = None):
if not media: media = {}
if not data: data = {}
+7
View File
@@ -98,6 +98,13 @@ class RTorrent:
"Error: Minimum rTorrent version required is {0}".format(
MIN_RTORRENT_VERSION_STR)
def test_connection(self):
try:
self._verify_conn()
except:
return False
return True
def _meets_version_requirement(self):
return self._get_client_version_tuple() >= MIN_RTORRENT_VERSION