diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 39aeb506..fb0b58f2 100755 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -683,15 +683,15 @@
- +
- +
- +
@@ -703,20 +703,24 @@
Folder path where torrents will be assigned to
-
- - -
+
+ + +
+
+ + +
@@ -2159,6 +2163,32 @@ $("#add_torznab").before(torformfields); }); + $('#qbittorrent_test').click(function () { + var imagechk = document.getElementById("qbittorrent_statusicon"); + var host = document.getElementById("qbittorrent_host").value; + var username = document.getElementById("qbittorrent_username").value; + var password = document.getElementById("qbittorrent_password").value; + $.get("testqbit", + { host: host, username: username, password: password }, + function(data){ + if (data.error != undefined) { + alert(data.error); + return; + } + $('#ajaxMsg').html("
"+data+"
"); + if ( data.indexOf("Successfully") > -1){ + imagechk.src = ""; + imagechk.src = "interfaces/default/images/success.png"; + imagechk.style.visibility = "visible"; + } else { + imagechk.src = ""; + imagechk.src = "interfaces/default/images/fail.png"; + imagechk.style.visibility = "visible"; + } + }); + $('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut(); + }); + function addAction() { $('#autoadd').append(''); }; diff --git a/mylar/torrent/clients/qbittorrent.py b/mylar/torrent/clients/qbittorrent.py index 5be911e8..1b97d714 100644 --- a/mylar/torrent/clients/qbittorrent.py +++ b/mylar/torrent/clients/qbittorrent.py @@ -11,29 +11,33 @@ class TorrentClient(object): def __init__(self): self.conn = None - def connect(self, host, username, password): + def connect(self, host, username, password, test=False): if self.conn is not None: return self.connect if not host: - return {'status': False} + return {'status': False, 'error': 'host not specified'} try: - logger.info(host) self.client = client.Client(host) except Exception as e: - logger.error('Could not create qBittorrent Object' + str(e)) - return {'status': False} + logger.error('Could not create qBittorrent Object %s' % e) + return {'status': False, 'error': e} else: try: self.client.login(username, password) except Exception as e: - logger.error('Could not connect to qBittorrent ' + host) + logger.error('Could not connect to qBittorrent: %s' % host) + return {'status': False, 'error': e} else: - return self.client + if test is True: + version = self.client.qbittorrent_version + return {'status': True, 'version': version} + else: + return self.client def find_torrent(self, hash): - logger.debug('Finding Torrent hash: ' + hash) + logger.debug('Finding Torrent hash: %s' % hash) torrent_info = self.get_torrent(hash) if torrent_info: return True @@ -41,11 +45,11 @@ class TorrentClient(object): return False def get_torrent(self, hash): - logger.debug('Getting Torrent info hash: ' + hash) + logger.debug('Getting Torrent info hash: %s' % hash) try: torrent_info = self.client.get_torrent(hash) except Exception as e: - logger.error('Could not get torrent info for ' + hash) + logger.error('Could not get torrent info for %s' % hash) return False else: logger.info('Successfully located information for torrent') @@ -55,7 +59,7 @@ class TorrentClient(object): def load_torrent(self, filepath): if not filepath.startswith('magnet'): - logger.info('filepath to torrent file set to : ' + filepath) + logger.info('filepath to torrent file set to : %s' % filepath) if self.client._is_authenticated is True: logger.info('Checking if Torrent Exists!') @@ -68,15 +72,15 @@ class TorrentClient(object): logger.debug('Magnet (load_torrent) initiating') else: hash = self.get_the_hash(filepath) - logger.debug('FileName (load_torrent): ' + str(os.path.basename(filepath))) + logger.debug('FileName (load_torrent): %s' % os.path.basename(filepath)) - logger.debug('Torrent Hash (load_torrent): "' + hash + '"') + logger.debug('Torrent Hash (load_torrent): "%s"' % hash) #Check if torrent already added if self.find_torrent(hash): logger.info('load_torrent: Torrent already exists!') - return {'status': False} + return {'status': False, 'error': 'Torrent already exists'} #should set something here to denote that it's already loaded, and then the failed download checker not run so it doesn't download #multiple copies of the same issues that's already downloaded else: @@ -94,8 +98,8 @@ class TorrentClient(object): else: tid = self.client.download_from_link(filepath, category=str(mylar.CONFIG.QBITTORRENT_LABEL)) except Exception as e: - logger.debug('Torrent not added') - return {'status': False} + logger.error('Torrent not added') + return {'status': False, 'error': e} else: logger.debug('Successfully submitted for add as a magnet. Verifying item is now on client.') else: @@ -106,8 +110,8 @@ class TorrentClient(object): else: tid = self.client.download_from_file(torrent_content, category=str(mylar.CONFIG.QBITTORRENT_LABEL)) except Exception as e: - logger.debug('Torrent not added') - return {'status': False} + logger.error('Torrent not added') + return {'status': False, 'error': e} else: logger.debug('Successfully submitted for add via file. Verifying item is now on client.') @@ -115,14 +119,14 @@ class TorrentClient(object): logger.info('Attempting to force start torrent') try: startit = self.client.force_start(hash) - logger.info('startit returned:' + str(startit)) + logger.info('startit returned: %s' % startit) except: logger.warn('Unable to force start torrent - please check your client.') elif mylar.CONFIG.QBITTORRENT_LOADACTION == 'pause': logger.info('Attempting to pause torrent after loading') try: startit = self.client.pause(hash) - logger.info('startit paused:' + str(startit)) + logger.info('startit paused: %s' % startit) except: logger.warn('Unable to pause torrent - possibly already paused?') else: @@ -133,7 +137,7 @@ class TorrentClient(object): tinfo = self.get_torrent(hash) except Exception as e: logger.warn('Torrent was not added! Please check logs') - return {'status': False} + return {'status': False, 'error': e} else: logger.info('Torrent successfully added!') filelist = self.client.get_torrent_files(hash) @@ -165,6 +169,5 @@ class TorrentClient(object): metainfo = bencode.decode(torrent_file.read()) info = metainfo['info'] thehash = hashlib.sha1(bencode.encode(info)).hexdigest().upper() - logger.debug('Hash: ' + thehash) return thehash diff --git a/mylar/webserve.py b/mylar/webserve.py index 50fb7a31..8a25a58a 100644 --- a/mylar/webserve.py +++ b/mylar/webserve.py @@ -5686,6 +5686,21 @@ class WebInterface(object): return "Successfully validated connection to %s" % host testrtorrent.exposed = True + def testqbit(self, host, username, password): + import torrent.clients.qbittorrent as QbitClient + qc = QbitClient.TorrentClient() + qclient = qc.connect(host, username, password, True) + if not qclient: + logger.warn('[qBittorrent] Could not establish connection to %s' % host) + return 'Error establishing connection to Qbittorrent' + else: + if qclient['status'] is False: + logger.warn('[qBittorrent] Could not establish connection to %s. Error returned:' % (host, qclient['error'])) + return 'Error establishing connection to Qbittorrent' + else: + logger.info('[qBittorrent] Successfully validated connection to %s [%s]' % (host, qclient['version'])) + return 'Successfully validated qBittorrent connection' + testqbit.exposed = True def testnewznab(self, name, host, ssl, apikey): result = helpers.newznab_test(name, host, ssl, apikey)