mirror of https://github.com/evilhero/mylar
IMP: Added qBitorrrent test connection option and added some additional error logging
This commit is contained in:
parent
1f895fd32d
commit
1b2a2f5da3
|
@ -683,15 +683,15 @@
|
||||||
<fieldset id="qbittorrent_options">
|
<fieldset id="qbittorrent_options">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label>qBittorrent Host:Port </label>
|
<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>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label>qBittorrent Username</label>
|
<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>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label>qBittorrent Password</label>
|
<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>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label>qBittorrent Label</label>
|
<label>qBittorrent Label</label>
|
||||||
|
@ -703,20 +703,24 @@
|
||||||
<input type="text" name="qbittorrent_folder" value="${config['qbittorrent_folder']}" size="30"><br/>
|
<input type="text" name="qbittorrent_folder" value="${config['qbittorrent_folder']}" size="30"><br/>
|
||||||
<small>Folder path where torrents will be assigned to</small>
|
<small>Folder path where torrents will be assigned to</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label>Add torrent action:</label>
|
<label>Add torrent action:</label>
|
||||||
<select name="qbittorrent_loadaction">
|
<select name="qbittorrent_loadaction">
|
||||||
%for x in ['default', 'force_start', 'pause']:
|
%for x in ['default', 'force_start', 'pause']:
|
||||||
<%
|
<%
|
||||||
if config['qbittorrent_loadaction'] == x:
|
if config['qbittorrent_loadaction'] == x:
|
||||||
outputselect = 'selected'
|
outputselect = 'selected'
|
||||||
else:
|
else:
|
||||||
outputselect = ''
|
outputselect = ''
|
||||||
%>
|
%>
|
||||||
<option value=${x} ${outputselect}>${x}</option>
|
<option value=${x} ${outputselect}>${x}</option>
|
||||||
%endfor
|
%endfor
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
@ -2159,6 +2163,32 @@
|
||||||
$("#add_torznab").before(torformfields);
|
$("#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() {
|
function addAction() {
|
||||||
$('#autoadd').append('<input type="hidden" name="tsab" value=1 />');
|
$('#autoadd').append('<input type="hidden" name="tsab" value=1 />');
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,29 +11,33 @@ class TorrentClient(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.conn = None
|
self.conn = None
|
||||||
|
|
||||||
def connect(self, host, username, password):
|
def connect(self, host, username, password, test=False):
|
||||||
if self.conn is not None:
|
if self.conn is not None:
|
||||||
return self.connect
|
return self.connect
|
||||||
|
|
||||||
if not host:
|
if not host:
|
||||||
return {'status': False}
|
return {'status': False, 'error': 'host not specified'}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.info(host)
|
|
||||||
self.client = client.Client(host)
|
self.client = client.Client(host)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Could not create qBittorrent Object' + str(e))
|
logger.error('Could not create qBittorrent Object %s' % e)
|
||||||
return {'status': False}
|
return {'status': False, 'error': e}
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self.client.login(username, password)
|
self.client.login(username, password)
|
||||||
except Exception as e:
|
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:
|
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):
|
def find_torrent(self, hash):
|
||||||
logger.debug('Finding Torrent hash: ' + hash)
|
logger.debug('Finding Torrent hash: %s' % hash)
|
||||||
torrent_info = self.get_torrent(hash)
|
torrent_info = self.get_torrent(hash)
|
||||||
if torrent_info:
|
if torrent_info:
|
||||||
return True
|
return True
|
||||||
|
@ -41,11 +45,11 @@ class TorrentClient(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_torrent(self, hash):
|
def get_torrent(self, hash):
|
||||||
logger.debug('Getting Torrent info hash: ' + hash)
|
logger.debug('Getting Torrent info hash: %s' % hash)
|
||||||
try:
|
try:
|
||||||
torrent_info = self.client.get_torrent(hash)
|
torrent_info = self.client.get_torrent(hash)
|
||||||
except Exception as e:
|
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
|
return False
|
||||||
else:
|
else:
|
||||||
logger.info('Successfully located information for torrent')
|
logger.info('Successfully located information for torrent')
|
||||||
|
@ -55,7 +59,7 @@ class TorrentClient(object):
|
||||||
def load_torrent(self, filepath):
|
def load_torrent(self, filepath):
|
||||||
|
|
||||||
if not filepath.startswith('magnet'):
|
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:
|
if self.client._is_authenticated is True:
|
||||||
logger.info('Checking if Torrent Exists!')
|
logger.info('Checking if Torrent Exists!')
|
||||||
|
@ -68,15 +72,15 @@ class TorrentClient(object):
|
||||||
logger.debug('Magnet (load_torrent) initiating')
|
logger.debug('Magnet (load_torrent) initiating')
|
||||||
else:
|
else:
|
||||||
hash = self.get_the_hash(filepath)
|
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
|
#Check if torrent already added
|
||||||
if self.find_torrent(hash):
|
if self.find_torrent(hash):
|
||||||
logger.info('load_torrent: Torrent already exists!')
|
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
|
#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
|
#multiple copies of the same issues that's already downloaded
|
||||||
else:
|
else:
|
||||||
|
@ -94,8 +98,8 @@ class TorrentClient(object):
|
||||||
else:
|
else:
|
||||||
tid = self.client.download_from_link(filepath, category=str(mylar.CONFIG.QBITTORRENT_LABEL))
|
tid = self.client.download_from_link(filepath, category=str(mylar.CONFIG.QBITTORRENT_LABEL))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug('Torrent not added')
|
logger.error('Torrent not added')
|
||||||
return {'status': False}
|
return {'status': False, 'error': e}
|
||||||
else:
|
else:
|
||||||
logger.debug('Successfully submitted for add as a magnet. Verifying item is now on client.')
|
logger.debug('Successfully submitted for add as a magnet. Verifying item is now on client.')
|
||||||
else:
|
else:
|
||||||
|
@ -106,8 +110,8 @@ class TorrentClient(object):
|
||||||
else:
|
else:
|
||||||
tid = self.client.download_from_file(torrent_content, category=str(mylar.CONFIG.QBITTORRENT_LABEL))
|
tid = self.client.download_from_file(torrent_content, category=str(mylar.CONFIG.QBITTORRENT_LABEL))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug('Torrent not added')
|
logger.error('Torrent not added')
|
||||||
return {'status': False}
|
return {'status': False, 'error': e}
|
||||||
else:
|
else:
|
||||||
logger.debug('Successfully submitted for add via file. Verifying item is now on client.')
|
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')
|
logger.info('Attempting to force start torrent')
|
||||||
try:
|
try:
|
||||||
startit = self.client.force_start(hash)
|
startit = self.client.force_start(hash)
|
||||||
logger.info('startit returned:' + str(startit))
|
logger.info('startit returned: %s' % startit)
|
||||||
except:
|
except:
|
||||||
logger.warn('Unable to force start torrent - please check your client.')
|
logger.warn('Unable to force start torrent - please check your client.')
|
||||||
elif mylar.CONFIG.QBITTORRENT_LOADACTION == 'pause':
|
elif mylar.CONFIG.QBITTORRENT_LOADACTION == 'pause':
|
||||||
logger.info('Attempting to pause torrent after loading')
|
logger.info('Attempting to pause torrent after loading')
|
||||||
try:
|
try:
|
||||||
startit = self.client.pause(hash)
|
startit = self.client.pause(hash)
|
||||||
logger.info('startit paused:' + str(startit))
|
logger.info('startit paused: %s' % startit)
|
||||||
except:
|
except:
|
||||||
logger.warn('Unable to pause torrent - possibly already paused?')
|
logger.warn('Unable to pause torrent - possibly already paused?')
|
||||||
else:
|
else:
|
||||||
|
@ -133,7 +137,7 @@ class TorrentClient(object):
|
||||||
tinfo = self.get_torrent(hash)
|
tinfo = self.get_torrent(hash)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn('Torrent was not added! Please check logs')
|
logger.warn('Torrent was not added! Please check logs')
|
||||||
return {'status': False}
|
return {'status': False, 'error': e}
|
||||||
else:
|
else:
|
||||||
logger.info('Torrent successfully added!')
|
logger.info('Torrent successfully added!')
|
||||||
filelist = self.client.get_torrent_files(hash)
|
filelist = self.client.get_torrent_files(hash)
|
||||||
|
@ -165,6 +169,5 @@ class TorrentClient(object):
|
||||||
metainfo = bencode.decode(torrent_file.read())
|
metainfo = bencode.decode(torrent_file.read())
|
||||||
info = metainfo['info']
|
info = metainfo['info']
|
||||||
thehash = hashlib.sha1(bencode.encode(info)).hexdigest().upper()
|
thehash = hashlib.sha1(bencode.encode(info)).hexdigest().upper()
|
||||||
logger.debug('Hash: ' + thehash)
|
|
||||||
return thehash
|
return thehash
|
||||||
|
|
||||||
|
|
|
@ -5686,6 +5686,21 @@ class WebInterface(object):
|
||||||
return "Successfully validated connection to %s" % host
|
return "Successfully validated connection to %s" % host
|
||||||
testrtorrent.exposed = True
|
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):
|
def testnewznab(self, name, host, ssl, apikey):
|
||||||
result = helpers.newznab_test(name, host, ssl, apikey)
|
result = helpers.newznab_test(name, host, ssl, apikey)
|
||||||
|
|
Loading…
Reference in New Issue