Skip to content

Commit

Permalink
Merge pull request #726 from philborman/master
Browse files Browse the repository at this point in the history
Bug fixes and tidying
  • Loading branch information
philborman authored Apr 5, 2017
2 parents aae4383 + 202c47c commit 2fa91b6
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 109 deletions.
1 change: 0 additions & 1 deletion data/interfaces/bookstrap/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ <h1>${title}</h1>
<div class="form-group col-md-6">
<label for="testSynology" class="control-label">Synology Connection:</label><br>
<button class="button btn btn-sm btn-primary" type="button" value="Test Synology" id="testSynology"><i class="fa fa-list-ul"></i> Test Synology</button>
<span class="help-block">Save settings before testing</span>
<br><br>
</div>
</fieldset>
Expand Down
129 changes: 64 additions & 65 deletions data/interfaces/default/config.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/interfaces/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ <h1>&nbsp&nbsp${title}</h1>

<%def name="javascriptIncludes()">
<script src="js/libs/jquery.dataTables.min.js"></script>
<script src="js/natural.js"></script>
<script>
$(document).ready(function()
{
Expand Down
5 changes: 1 addition & 4 deletions lazylibrarian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,10 +911,7 @@ def build_monthtable():
locale.setlocale(locale.LC_ALL, current_locale) # restore entry state
logger.warn("Unable to load requested locale [%s] %s" % (lang, str(e)))
try:
if '_' in lang:
wanted_lang = lang.split('_')[0]
else:
wanted_lang = lang
wanted_lang = lang.split('_')[0]
params = ['locale', '-a']
all_locales = subprocess.check_output(params).split()
locale_list = []
Expand Down
8 changes: 7 additions & 1 deletion lazylibrarian/deluge.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import lib.requests as requests
from lazylibrarian import logger
from lazylibrarian.common import setperm
from lazylibrarian.formatter import check_int

delugeweb_auth = {}
delugeweb_url = ''
Expand Down Expand Up @@ -209,6 +210,11 @@ def _get_auth():
delugeweb_auth = {}

delugeweb_host = lazylibrarian.CONFIG['DELUGE_HOST']
delugeweb_port = check_int(lazylibrarian.CONFIG['DELUGE_PORT'], 0)
if not delugeweb_host or not delugeweb_port:
logger.error('Invalid delugeweb host or port, check your config')
return None

delugeweb_password = lazylibrarian.CONFIG['DELUGE_PASS']

if not delugeweb_host.startswith('http'):
Expand All @@ -217,7 +223,7 @@ def _get_auth():
if delugeweb_host.endswith('/'):
delugeweb_host = delugeweb_host[:-1]

delugeweb_host = "%s:%s" % (delugeweb_host, lazylibrarian.CONFIG['DELUGE_PORT'])
delugeweb_host = "%s:%s" % (delugeweb_host, delugeweb_port)

delugeweb_url = delugeweb_host + '/json'

Expand Down
3 changes: 1 addition & 2 deletions lazylibrarian/gb.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def find_results(self, searchterm=None, queue=None):
elif api_value == 'intitle:':
searchterm = fullterm
if title: # just search for title
if ' (' in title:
title = title.split(' (')[0] # with out any series info
title = title.split(' (')[0] # with out any series info
searchterm = title
searchterm = searchterm.replace("'","").replace('"','') # and no quotes
searchterm = searchterm.strip()
Expand Down
9 changes: 3 additions & 6 deletions lazylibrarian/magazinescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ def create_cover(issuefile=None, refresh=False):
res = subprocess.check_output(params, stderr=subprocess.STDOUT)
logger.debug("Found %s [%s] version %s" % (generator, GS, res))
generator = "%s version %s" % (generator, res)
if '[' in issuefile:
issuefile = issuefile.split('[')[0]
issuefile = issuefile.split('[')[0]
params = [GS, "-sDEVICE=jpeg", "-dNOPAUSE", "-dBATCH", "-dSAFER", "-dFirstPage=1", "-dLastPage=1",
"-dUseCropBox", "-sOutputFile=%s" % coverfile, issuefile]
res = subprocess.check_output(params, stderr=subprocess.STDOUT)
Expand Down Expand Up @@ -215,8 +214,7 @@ def create_cover(issuefile=None, refresh=False):
res = subprocess.check_output(params, stderr=subprocess.STDOUT)
logger.debug("Found gs [%s] version %s" % (GS, res))
generator = "%s version %s" % (generator, res)
if '[' in issuefile:
issuefile = issuefile.split('[')[0]
issuefile = issuefile.split('[')[0]
params = [GS, "-sDEVICE=jpeg", "-dNOPAUSE", "-dBATCH", "-dSAFER", "-dFirstPage=1",
"-dLastPage=1", "-dUseCropBox", "-sOutputFile=%s" % coverfile, issuefile]
res = subprocess.check_output(params, stderr=subprocess.STDOUT)
Expand Down Expand Up @@ -251,8 +249,7 @@ def magazineScan():
myDB = database.DBConnection()

mag_path = lazylibrarian.CONFIG['MAG_DEST_FOLDER']
if '$' in mag_path:
mag_path = mag_path.split('$')[0]
mag_path = mag_path.split('$')[0]

if lazylibrarian.CONFIG['MAG_RELATIVE']:
if mag_path[0] not in '._':
Expand Down
3 changes: 1 addition & 2 deletions lazylibrarian/manualbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ def searchItem(item=None, bookid=None):
words -= len(getList(title))
score -= abs(words)
if score >= 40: # ignore wildly wrong results?
if '?' in url:
url = url.split('?')[0]
url = url.split('?')[0]
result = {'score': score, 'title': title, 'provider': provider, 'size': size, 'date': date,
'url': urllib.quote_plus(url), 'mode': mode}

Expand Down
8 changes: 5 additions & 3 deletions lazylibrarian/nzbget.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import lazylibrarian
from lazylibrarian import logger
from lazylibrarian.formatter import check_int


def checkLink():
Expand All @@ -48,8 +49,9 @@ def sendNZB(nzb, cmd=None, nzbID=None):
# by setting nzbID and cmd (we currently only use test and delete)

host = lazylibrarian.CONFIG['NZBGET_HOST']
if host is None:
logger.error(u"No NZBget host found in configuration. Please configure it.")
port = check_int(lazylibrarian.CONFIG['NZBGET_PORT'], 0)
if not host or not port:
logger.error('Invalid NZBget host or port, check your config')
return False

addToTop = False
Expand All @@ -63,7 +65,7 @@ def sendNZB(nzb, cmd=None, nzbID=None):
hostparts = host.split('://')

url = hostparts[0] + '://' + nzbgetXMLrpc % {"host": hostparts[1], "username": lazylibrarian.CONFIG['NZBGET_USER'],
"port": lazylibrarian.CONFIG['NZBGET_PORT'],
"port": port,
"password": lazylibrarian.CONFIG['NZBGET_PASS']}
try:
nzbGetRPC = xmlrpclib.ServerProxy(url)
Expand Down
7 changes: 2 additions & 5 deletions lazylibrarian/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,8 @@ def processDir(reset=False):
# so we try to do a "best match" on the name, there might be a better way...

matchname = fname
if ' LL.(' in matchname:
matchname = matchname.split(' LL.(')[0]

if ' LL.(' in matchtitle:
matchtitle = matchtitle.split(' LL.(')[0]
matchname = matchname.split(' LL.(')[0]
matchtitle = matchtitle.split(' LL.(')[0]
match = fuzz.token_set_ratio(matchtitle, matchname)
if int(lazylibrarian.LOGLEVEL) > 2:
logger.debug("%s%% match %s : %s" % (match, matchtitle, matchname))
Expand Down
7 changes: 6 additions & 1 deletion lazylibrarian/qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import lazylibrarian
from lazylibrarian import logger
from lazylibrarian.common import USER_AGENT
from lazylibrarian.formatter import check_int


class qbittorrentclient(object):
Expand All @@ -36,6 +37,10 @@ class qbittorrentclient(object):
def __init__(self):

host = lazylibrarian.CONFIG['QBITTORRENT_HOST']
port = check_int(lazylibrarian.CONFIG['QBITTORRENT_PORT'], 0)
if not host or not port:
logger.error('Invalid Qbittorrent host or port, check your config')

if not host.startswith('http'):
host = 'http://' + host

Expand All @@ -45,7 +50,7 @@ def __init__(self):
if host.endswith('/gui'):
host = host[:-4]

host = "%s:%s" % (host, lazylibrarian.CONFIG['QBITTORRENT_PORT'])
host = "%s:%s" % (host, port)
self.base_url = host
self.username = lazylibrarian.CONFIG['QBITTORRENT_USER']
self.password = lazylibrarian.CONFIG['QBITTORRENT_PASS']
Expand Down
3 changes: 2 additions & 1 deletion lazylibrarian/rtorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
def getServer():
host = lazylibrarian.CONFIG['RTORRENT_HOST']
if not host:
logger.debug("rtorrent error: No host found")
logger.error("rtorrent error: No host found, check your config")
return False

if not host.startswith('http'):
host = 'http://' + host
if host.endswith('/'):
Expand Down
8 changes: 7 additions & 1 deletion lazylibrarian/sabnzbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import lazylibrarian
from lazylibrarian import logger
from lazylibrarian.formatter import check_int


def checkLink():
Expand Down Expand Up @@ -49,12 +50,17 @@ def SABnzbd(title=None, nzburl=None, remove_data=False):
return False

hostname = lazylibrarian.CONFIG['SAB_HOST']
port = check_int(lazylibrarian.CONFIG['SAB_PORT'], 0)
if not hostname or not port:
logger.error('Invalid sabnzbd host or port, check your config')
return False

if hostname.endswith('/'):
hostname = hostname[:-1]
if not hostname.startswith("http"):
hostname = 'http://' + hostname

HOST = "%s:%s" % (hostname, lazylibrarian.CONFIG['SAB_PORT'])
HOST = "%s:%s" % (hostname, port)

if lazylibrarian.CONFIG['SAB_SUBDIR']:
HOST = HOST + "/" + lazylibrarian.CONFIG['SAB_SUBDIR']
Expand Down
3 changes: 1 addition & 2 deletions lazylibrarian/searchtorrents.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ def TORDownloadMethod(bookid=None, tor_title=None, tor_url=None):
# torznab results need to be re-encoded
# had a problem with torznab utf-8 encoded strings not matching
# our utf-8 strings because of long/short form differences
url = tor_url.split('&file=')[0]
value = tor_url.split('&file=')[1]
url, value = tor_url.split('&file=', 1)
if isinstance(value, str):
value = value.decode('utf-8') # make unicode
value = unicodedata.normalize('NFC', value) # normalize to short form
Expand Down
7 changes: 4 additions & 3 deletions lazylibrarian/synology.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import lazylibrarian
from lazylibrarian import logger
from lazylibrarian.cache import fetchURL
from lazylibrarian.formatter import check_int


def _getJSON(URL, params):
Expand Down Expand Up @@ -276,9 +277,9 @@ def _addTorrentURI(task_cgi, sid, torurl):
def _hostURL():
# Build webapi_url from config settings
host = lazylibrarian.CONFIG['SYNOLOGY_HOST']
port = lazylibrarian.CONFIG['SYNOLOGY_PORT']
if not host:
logger.debug("Synology host not defined, check config")
port = check_int(lazylibrarian.CONFIG['SYNOLOGY_PORT'], 0)
if not host or not port:
logger.debug("Invalid Synology host or port, check your config")
return False
if not host.startswith('http'):
host = 'http://' + host
Expand Down
8 changes: 7 additions & 1 deletion lazylibrarian/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import lazylibrarian
from lazylibrarian import logger, request
from lazylibrarian.formatter import check_int


# This is just a simple script to send torrents to transmission. The
Expand Down Expand Up @@ -168,7 +169,12 @@ def checkLink():
def torrentAction(method, arguments):

host = lazylibrarian.CONFIG['TRANSMISSION_HOST']
port = lazylibrarian.CONFIG['TRANSMISSION_PORT']
port = check_int(lazylibrarian.CONFIG['TRANSMISSION_PORT'], 0)

if not host or not port:
logger.error('Invalid transmission host or port, check your config')
return False

username = lazylibrarian.CONFIG['TRANSMISSION_USER']
password = lazylibrarian.CONFIG['TRANSMISSION_PASS']

Expand Down
7 changes: 6 additions & 1 deletion lazylibrarian/utorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import lazylibrarian
from lazylibrarian import logger
from lazylibrarian.common import USER_AGENT
from lazylibrarian.formatter import check_int


class utorrentclient(object):
Expand All @@ -34,6 +35,10 @@ def __init__(self, base_url='', # lazylibrarian.CONFIG['UTORRENT_HOST'],
password='',): # lazylibrarian.CONFIG['UTORRENT_PASS']):

host = lazylibrarian.CONFIG['UTORRENT_HOST']
port = check_int(lazylibrarian.CONFIG['UTORRENT_PORT'], 0)
if not host or not port:
logger.error('Invalid Utorrent host or port, check your config')

if not host.startswith('http'):
host = 'http://' + host

Expand All @@ -43,7 +48,7 @@ def __init__(self, base_url='', # lazylibrarian.CONFIG['UTORRENT_HOST'],
if host.endswith('/gui'):
host = host[:-4]

host = "%s:%s" % (host, lazylibrarian.CONFIG['UTORRENT_PORT'])
host = "%s:%s" % (host, port)
self.base_url = host
self.username = lazylibrarian.CONFIG['UTORRENT_USER']
self.password = lazylibrarian.CONFIG['UTORRENT_PASS']
Expand Down
1 change: 1 addition & 0 deletions lazylibrarian/webServe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,7 @@ def testNZBget(self, **kwargs):
lazylibrarian.CONFIG['NZBGET_CATEGORY'] = kwargs['cat']
if 'pri' in kwargs:
lazylibrarian.CONFIG['NZBGET_PRIORITY'] = kwargs['pri']

msg = nzbget.checkLink()
if 'success' in msg:
lazylibrarian.config_write()
Expand Down
24 changes: 14 additions & 10 deletions lib/deluge_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@ class CallTimeoutException(Exception):

class DelugeRPCClient(object):
timeout = 20

def __init__(self, host, port, username, password):
self.host = host
self.port = port
self.username = username
self.password = password

self.request_id = 0
self.connected = False
self._socket = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
self._socket.settimeout(self.timeout)

def connect(self):
"""
Connects to the Deluge instance
"""
if not self.host or not self.port:
logger.error('Invalid deluge daemon host or port, check your config')
return False

logger.info('Connecting to %s:%s' % (self.host, self.port))
self._socket.connect((self.host, self.port))
logger.debug('Connected to Deluge, logging in')
Expand All @@ -48,27 +52,27 @@ def connect(self):
result = self.call('auth.login', self.password)
logger.debug('Logged in with value %r' % result)
self.connected = True

def call(self, method, *args, **kwargs):
"""
Calls an RPC function
"""
self.request_id += 1
logger.debug('Calling reqid %s method %r with args:%r kwargs:%r' % (self.request_id, method, args, kwargs))

req = ((self.request_id, method, args, kwargs), )
req = zlib.compress(dumps(req))

#self._socket.send('D' + struct.pack("!i", len(req))) # seems to be for the future !
self._socket.send(req)

data = b''
while True:
try:
d = self._socket.recv(READ_SIZE)
except ssl.SSLError:
raise CallTimeoutException()

data += d
try:
data = zlib.decompress(data)
Expand All @@ -77,11 +81,11 @@ def call(self, method, *args, **kwargs):
raise ConnectionLostException()
continue
break

data = list(loads(data))
msg_type = data.pop(0)
request_id = data.pop(0)

if msg_type == RPC_ERROR:
exception_type, exception_msg, traceback = data
raise Exception()
Expand Down

0 comments on commit 2fa91b6

Please sign in to comment.