Skip to content

Commit

Permalink
Merge pull request #899 from philborman/master
Browse files Browse the repository at this point in the history
torznab url fix, additional email_notifier messages
  • Loading branch information
philborman authored Jul 6, 2017
2 parents 3367f8f + 33c6e72 commit e57cf13
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
3 changes: 2 additions & 1 deletion lazylibrarian/manualbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def searchItem(item=None, bookid=None, cat=None):
score -= abs(words)
if score >= 40: # ignore wildly wrong results?
if not url.startswith('magnet'):
url = url.split('?')[0]
if not mode == 'torznab': # what is this split for??
url = url.split('?')[0]
result = {'score': score, 'title': title, 'provider': provider, 'size': size, 'date': date,
'url': urllib.quote_plus(url), 'mode': mode}

Expand Down
4 changes: 2 additions & 2 deletions lazylibrarian/notifiers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def custom_notify_snatch(bookid):
def notify_download(title, bookid=None):
try:
for n in notifiers:
if n == 'email_notifier' and lazylibrarian.CONFIG['EMAIL_SENDFILE_ONDOWNLOAD']:
n.notify_download(title, bookid)
if n == 'email_notifier':
n.notify_download(title, bookid=bookid)
else:
n.notify_download(title)
except Exception as e:
Expand Down
48 changes: 27 additions & 21 deletions lazylibrarian/notifiers/email_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,31 +102,38 @@ def _notify(message, event, force=False, files=None):
def notify_snatch(self, title):
if lazylibrarian.CONFIG['EMAIL_NOTIFY_ONSNATCH']:
return self._notify(message=title, event=notifyStrings[NOTIFY_SNATCH])
return False

def notify_download(self, title, bookid=None, force=False):
if lazylibrarian.CONFIG['EMAIL_NOTIFY_ONDOWNLOAD']:
files = None
event = notifyStrings[NOTIFY_DOWNLOAD]
if bookid:
myDB = database.DBConnection()
data = myDB.match('SELECT BookFile,BookName from books where BookID=?', (bookid,))
try:
filename = data['BookFile']
title = data['BookName']
logger.debug('Found %s for bookid %s' % (filename, bookid))
except Exception:
data = myDB.match('SELECT IssueFile,Title,IssueDate from issues where IssueID=?', (bookid,))
try:
filename = data['IssueFile']
title = "%s - %s" % (data['Title'], data['IssueDate'])
logger.debug('Found %s for issueid %s' % (filename, bookid))
except Exception:
logger.debug("No download match for %s" % bookid)
filename = ''
if filename:
files = [filename] # could add cover_image, opf
event = "LazyLibrarian Download"
logger.debug('Email send attachment is %s' % lazylibrarian.CONFIG['EMAIL_SENDFILE_ONDOWNLOAD'])
if lazylibrarian.CONFIG['EMAIL_SENDFILE_ONDOWNLOAD']:
if not bookid:
logger.debug('Email request to attach book, but no bookid')
else:
myDB = database.DBConnection()
data = myDB.match('SELECT BookFile,BookName from books where BookID=?', (bookid,))
if data:
filename = data['BookFile']
title = data['BookName']
logger.debug('Found %s for bookid %s' % (filename, bookid))
else:
logger.debug('[%s] is not a valid bookid' % bookid)
data = myDB.match('SELECT IssueFile,Title,IssueDate from issues where IssueID=?', (bookid,))
if data:
filename = data['IssueFile']
title = "%s - %s" % (data['Title'], data['IssueDate'])
logger.debug('Found %s for issueid %s' % (filename, bookid))
else:
logger.debug('[%s] is not a valid bookid/issueid' % bookid)
filename = ''
if filename:
files = [filename] # could add cover_image, opf
event = "LazyLibrarian Download"
return self._notify(message=title, event=event, force=force, files=files)
return False

def test_notify(self, title='Test'):
message = u"This is a test notification from LazyLibrarian"
Expand All @@ -135,7 +142,6 @@ def test_notify(self, title='Test'):
data = myDB.match('SELECT bookid from books where bookfile <> ""')
if data:
return self.notify_download(title=message, bookid=data['bookid'], force=True)

return self._notify(message=message, event=title, force=True)
return self.notify_download(title=message, bookid=None, force=True)

notifier = EmailNotifier
15 changes: 10 additions & 5 deletions lazylibrarian/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,14 @@ def processDir(reset=False):
if to_delete:
# ask downloader to delete the torrent, but not the files
# we may delete them later, depending on other settings
if book['DownloadID'] != "unknown":
logger.debug('Removing %s from %s' % (book['NZBtitle'], book['Source'].lower()))
delete_task(book['Source'], book['DownloadID'], False)
else:
if not book['Source']:
logger.warn("Unable to remove %s, no source" % book['NZBtitle'])
elif not book['DownloadID'] or book['DownloadID'] == "unknown":
logger.warn("Unable to remove %s from %s, no DownloadID" %
(book['NZBtitle'], book['Source'].lower()))
elif book['Source'] != 'DIRECT':
logger.debug('Removing %s from %s' % (book['NZBtitle'], book['Source'].lower()))
delete_task(book['Source'], book['DownloadID'], False)

if to_delete:
# only delete the files if not in download root dir and if DESTINATION_COPY not set
Expand Down Expand Up @@ -635,7 +637,8 @@ def processDir(reset=False):
diff = 0
hours = int(diff / 3600)
if hours >= lazylibrarian.CONFIG['TASK_AGE']:
logger.warn('%s was sent to %s %s hours ago, deleting failed task' %
if book['Source']:
logger.warn('%s was sent to %s %s hours ago, deleting failed task' %
(book['NZBtitle'], book['Source'].lower(), hours))
# change status to "Failed", and ask downloader to delete task and files
if book['BookID'] != 'unknown':
Expand Down Expand Up @@ -692,6 +695,8 @@ def delete_task(Source, DownloadID, remove_data):
except Exception as e:
logger.debug('DelugeRPC failed %s' % str(e))
return False
elif Source == 'DIRECT':
return True
else:
logger.debug("Unknown source [%s] in delete_task" % Source)
return False
Expand Down

0 comments on commit e57cf13

Please sign in to comment.