diff --git a/couchpotato/core/downloaders/deluge/main.py b/couchpotato/core/downloaders/deluge/main.py index 53b87d91..4fe23aa2 100644 --- a/couchpotato/core/downloaders/deluge/main.py +++ b/couchpotato/core/downloaders/deluge/main.py @@ -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: diff --git a/couchpotato/core/downloaders/nzbget/main.py b/couchpotato/core/downloaders/nzbget/main.py index a690572c..8b9c88d1 100644 --- a/couchpotato/core/downloaders/nzbget/main.py +++ b/couchpotato/core/downloaders/nzbget/main.py @@ -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 = {} diff --git a/couchpotato/core/downloaders/nzbvortex/main.py b/couchpotato/core/downloaders/nzbvortex/main.py index 205ceb1b..048aa44d 100644 --- a/couchpotato/core/downloaders/nzbvortex/main.py +++ b/couchpotato/core/downloaders/nzbvortex/main.py @@ -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 = {} diff --git a/couchpotato/core/downloaders/rtorrent/main.py b/couchpotato/core/downloaders/rtorrent/main.py index f934de5f..a35cb006 100755 --- a/couchpotato/core/downloaders/rtorrent/main.py +++ b/couchpotato/core/downloaders/rtorrent/main.py @@ -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') diff --git a/couchpotato/core/downloaders/sabnzbd/main.py b/couchpotato/core/downloaders/sabnzbd/main.py index 72c23708..a21aee0e 100644 --- a/couchpotato/core/downloaders/sabnzbd/main.py +++ b/couchpotato/core/downloaders/sabnzbd/main.py @@ -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 = {} diff --git a/couchpotato/core/downloaders/synology/main.py b/couchpotato/core/downloaders/synology/main.py index 26a4558d..2ffbb8d8 100644 --- a/couchpotato/core/downloaders/synology/main.py +++ b/couchpotato/core/downloaders/synology/main.py @@ -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()) diff --git a/couchpotato/core/downloaders/transmission/main.py b/couchpotato/core/downloaders/transmission/main.py index d3f17598..5e952306 100644 --- a/couchpotato/core/downloaders/transmission/main.py +++ b/couchpotato/core/downloaders/transmission/main.py @@ -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 = {} diff --git a/libs/rtorrent/__init__.py b/libs/rtorrent/__init__.py index 683ef1c7..52b4bbe1 100755 --- a/libs/rtorrent/__init__.py +++ b/libs/rtorrent/__init__.py @@ -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