mirror of
https://github.com/evilhero/mylar
synced 2025-03-15 08:18:44 +00:00
IMP: Added qBitorrrent test connection option and added some additional error logging
This commit is contained in:
parent
1f895fd32d
commit
1b2a2f5da3
3 changed files with 87 additions and 39 deletions
|
@ -683,15 +683,15 @@
|
|||
<fieldset id="qbittorrent_options">
|
||||
<div class="row">
|
||||
<label>qBittorrent Host:Port </label>
|
||||
<input type="text" name="qbittorrent_host" value="${config['qbittorrent_host']}" size="30">
|
||||
<input type="text" name="qbittorrent_host" id="qbittorrent_host" value="${config['qbittorrent_host']}" size="30">
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>qBittorrent Username</label>
|
||||
<input type="text" name="qbittorrent_username" value="${config['qbittorrent_username']}" size="30">
|
||||
<input type="text" name="qbittorrent_username" id="qbittorrent_username" value="${config['qbittorrent_username']}" size="30">
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>qBittorrent Password</label>
|
||||
<input type="password" name="qbittorrent_password" value="${config['qbittorrent_password']}" size="30">
|
||||
<input type="password" name="qbittorrent_password" id="qbittorrent_password" value="${config['qbittorrent_password']}" size="30">
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>qBittorrent Label</label>
|
||||
|
@ -703,20 +703,24 @@
|
|||
<input type="text" name="qbittorrent_folder" value="${config['qbittorrent_folder']}" size="30"><br/>
|
||||
<small>Folder path where torrents will be assigned to</small>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Add torrent action:</label>
|
||||
<select name="qbittorrent_loadaction">
|
||||
%for x in ['default', 'force_start', 'pause']:
|
||||
<%
|
||||
if config['qbittorrent_loadaction'] == x:
|
||||
outputselect = 'selected'
|
||||
else:
|
||||
outputselect = ''
|
||||
%>
|
||||
<option value=${x} ${outputselect}>${x}</option>
|
||||
%endfor
|
||||
</select>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Add torrent action:</label>
|
||||
<select name="qbittorrent_loadaction">
|
||||
%for x in ['default', 'force_start', 'pause']:
|
||||
<%
|
||||
if config['qbittorrent_loadaction'] == x:
|
||||
outputselect = 'selected'
|
||||
else:
|
||||
outputselect = ''
|
||||
%>
|
||||
<option value=${x} ${outputselect}>${x}</option>
|
||||
%endfor
|
||||
</select>
|
||||
</div>
|
||||
<div class="row">
|
||||
<img name="qbittorrent_statusicon" id="qbittorrent_statusicon" src="interfaces/default/images/successs.png" style="float:right;visibility:hidden;" height="20" width="20" />
|
||||
<input type="button" value="Test Connection" id="qbittorrent_test" />
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</td>
|
||||
|
@ -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("<div class='msg'><span class='ui-icon ui-icon-check'></span>"+data+"</div>");
|
||||
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('<input type="hidden" name="tsab" value=1 />');
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue