Skip to content

Commit

Permalink
Merge pull request #355 from philborman/master
Browse files Browse the repository at this point in the history
Support deluge webui,  closes #351
  • Loading branch information
nncrypted committed May 11, 2016
2 parents 18ea40d + 7fd7bef commit a7fb2b2
Show file tree
Hide file tree
Showing 9 changed files with 500 additions and 28 deletions.
471 changes: 471 additions & 0 deletions lazylibrarian/deluge.py

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions lazylibrarian/magazinescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,9 @@ def magazineScan(thread=None):
if match:
issuedate = match.group("issuedate")
title = match.group("title")
# print issuedate
# print title
else:
logger.debug("Pattern match failed for [%s]" % fname)
continue
# title = fname.split('-')[3]
# title = title.split('.')[-2]
# title = title.strip()
# issuedate = fname.split(' ')[0]
except:
logger.debug("Invalid name format for [%s]" % fname)
continue
Expand Down
10 changes: 4 additions & 6 deletions lazylibrarian/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ def import_book(pp_path=None, bookID=None):
myDB.upsert("wanted", newValueDict, controlValueDict)
processExtras(myDB, dest_path, global_name, data)
logger.info('Successfully processed: %s' % global_name)
notifiers.notify_download(formatter.latinToAscii(global_name) + ' at ' + formatter.now())
return True
else:
logger.error('Postprocessing for %s has failed.' % global_name)
Expand Down Expand Up @@ -484,7 +485,7 @@ def processAutoAdd(src_path=None):
def processIMG(dest_path=None, bookimg=None, global_name=None):
# handle pictures
try:
if not bookimg.startswith('images'):
if bookimg.startswith('http'):
logger.debug('Downloading cover from ' + bookimg)
coverpath = os.path.join(dest_path, global_name + '.jpg')
with open(coverpath, 'wb') as img:
Expand Down Expand Up @@ -551,7 +552,7 @@ def csv_file(search_dir=None):
if search_dir and os.path.isdir(search_dir) is True:
for fname in os.listdir(search_dir):
if fname.endswith('.csv'):
return os.path.join(search_dir, fname).encode(lazylibrarian.SYS_ENCODING)
return os.path.join(search_dir, fname) # .encode(lazylibrarian.SYS_ENCODING)
return ""


Expand All @@ -577,10 +578,7 @@ def exportCSV(search_dir=None, status="Wanted"):
quotechar='"', quoting=csv.QUOTE_MINIMAL)

# write headers, change AuthorName BookName BookIsbn to match import csv names (Author, Title, ISBN10)
csvwrite.writerow([
'BookID', 'Author', 'Title',
'ISBN', 'AuthorID'
])
csvwrite.writerow(['BookID', 'Author', 'Title', 'ISBN', 'AuthorID'])

for resulted in find_status:
logger.debug(u"Exported CSV for book %s" % resulted['BookName'].encode(lazylibrarian.SYS_ENCODING))
Expand Down
2 changes: 1 addition & 1 deletion lazylibrarian/sabnzbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def checkLink():
def SABnzbd(title=None, nzburl=None):

HOST = "%s:%i" % (lazylibrarian.SAB_HOST, lazylibrarian.SAB_PORT)
if not str(HOST)[:4] == "http":
if not HOST.startswith("http"):
HOST = 'http://' + HOST

if lazylibrarian.SAB_SUBDIR:
Expand Down
12 changes: 7 additions & 5 deletions lazylibrarian/searchtorrents.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import lazylibrarian

from lazylibrarian import logger, database, formatter, providers, notifiers, utorrent, transmission, qbittorrent
from lazylibrarian import logger, database, formatter, providers, notifiers, utorrent, transmission, qbittorrent, deluge

from lib.deluge_client import DelugeRPCClient

Expand Down Expand Up @@ -271,20 +271,22 @@ def TORDownloadMethod(bookid=None, tor_prov=None, tor_title=None, tor_url=None):

if (lazylibrarian.TOR_DOWNLOADER_DELUGE and lazylibrarian.DELUGE_HOST):
logger.debug("Sending %s to Deluge" % tor_title)
client = DelugeRPCClient(lazylibrarian.DELUGE_HOST,
if not lazylibrarian.DELUGE_USER:
# no username, talk to the webui
download = deluge.addTorrent(tor_url)
else:
# have username, talk to the daemon
client = DelugeRPCClient(lazylibrarian.DELUGE_HOST,
int(lazylibrarian.DELUGE_PORT),
lazylibrarian.DELUGE_USER,
lazylibrarian.DELUGE_PASS)
if lazylibrarian.DELUGE_PASS and lazylibrarian.DELUGE_USER:
client.connect()
args = {"name": tor_title}
download = client.call('core.add_torrent_url', tor_url, args)
logger.debug('Deluge torrent_id: %s' % download)
if download and lazylibrarian.DELUGE_LABEL:
labelled = client.call('label.set_torrent', download, lazylibrarian.DELUGE_LABEL)
logger.debug('Deluge label returned: %s' % labelled)
else:
logger.warn('Need user and password for deluge, check config.')
else:
logger.warn('No torrent download method is enabled, check config.')
return False
Expand Down
3 changes: 1 addition & 2 deletions lazylibrarian/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def dbUpdate(forcefull=False):
logger.info('Starting update for %i active authors' % len(activeauthors))

for author in activeauthors:

authorid = author[0]
# authorid = author[0]
authorname = author[1]
importer.addAuthorToDB(authorname, refresh=True)

Expand Down
2 changes: 1 addition & 1 deletion lazylibrarian/versioncheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import threading

import lazylibrarian
from lazylibrarian import logger, version
from lazylibrarian import logger

import lib.simplejson as simplejson

Expand Down
15 changes: 10 additions & 5 deletions lazylibrarian/webServe.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from lazylibrarian import logger, importer, database, postprocess, formatter, \
notifiers, librarysync, versioncheck, magazinescan, common, bookwork, \
qbittorrent, utorrent, transmission, sabnzbd, nzbget
qbittorrent, utorrent, transmission, sabnzbd, nzbget, deluge
from lazylibrarian.searchnzb import search_nzb_book, NZBDownloadMethod
from lazylibrarian.searchtorrents import search_tor_book, TORDownloadMethod
from lazylibrarian.searchmag import search_magazines
Expand Down Expand Up @@ -1493,6 +1493,11 @@ def getManage(self, iDisplayStart=0, iDisplayLength=100, iSortCol_0=0, sSortDir_
def testDeluge(self):
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
try:
if not lazylibrarian.DELUGE_USER:
# no username, talk to the webui
return deluge.checkLink()

# if there's a username, talk to the daemon directly
client = DelugeRPCClient(lazylibrarian.DELUGE_HOST,
int(lazylibrarian.DELUGE_PORT),
lazylibrarian.DELUGE_USER,
Expand All @@ -1507,14 +1512,14 @@ def testDeluge(self):
for label in labels:
msg += '%s\n' % label
else:
msg += "Deluge seems to have no labels set"
msg += "Deluge daemon seems to have no labels set"
return msg
return "Deluge: Connection Successful"
return "Deluge: Daemon connection Successful"
except Exception as e:
msg = "Deluge: Connect FAILED\n"
msg = "Deluge: Daemon connection FAILED\n"
if 'Connection refused' in str(e):
msg += str(e)
msg += "Check Deluge HOST and PORT settings"
msg += "Check Deluge daemon HOST and PORT settings"
elif 'need more than 1 value' in str(e):
msg += "Invalid USERNAME or PASSWORD"
else:
Expand Down
7 changes: 5 additions & 2 deletions lib/deluge_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, host, port, username, password):
self.username = username
self.password = password

self.request_id = 1
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)
Expand All @@ -42,7 +42,10 @@ def connect(self):
logger.info('Connecting to %s:%s' % (self.host, self.port))
self._socket.connect((self.host, self.port))
logger.debug('Connected to Deluge, logging in')
result = self.call('daemon.login', self.username, self.password)
if self.username:
result = self.call('daemon.login', self.username, self.password)
else:
result = self.call('auth.login', self.password)
logger.debug('Logged in with value %r' % result)
self.connected = True

Expand Down

0 comments on commit a7fb2b2

Please sign in to comment.