From f6d59c5eef52870f2a44bfba7fbbab0ab66cddbc Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Wed, 5 Jul 2017 22:01:33 +0200 Subject: [PATCH 1/4] Code tidying and additional messages --- lazylibrarian/notifiers/__init__.py | 2 +- lazylibrarian/notifiers/email_notify.py | 12 ++++++++++-- lazylibrarian/postprocess.py | 15 ++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lazylibrarian/notifiers/__init__.py b/lazylibrarian/notifiers/__init__.py index 14fc3c22e..583411504 100644 --- a/lazylibrarian/notifiers/__init__.py +++ b/lazylibrarian/notifiers/__init__.py @@ -72,7 +72,7 @@ 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']: + if n == 'email_notifier': n.notify_download(title, bookid) else: n.notify_download(title) diff --git a/lazylibrarian/notifiers/email_notify.py b/lazylibrarian/notifiers/email_notify.py index 6c8f12cde..38e32df59 100644 --- a/lazylibrarian/notifiers/email_notify.py +++ b/lazylibrarian/notifiers/email_notify.py @@ -102,31 +102,39 @@ 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: + if lazylibrarian.CONFIG['EMAIL_SENDFILE_ONDOWNLOAD'] and not bookid: + logger.debug('Requested to attach book, but no bookid') + elif bookid: myDB = database.DBConnection() data = myDB.match('SELECT BookFile,BookName from books where BookID=?', (bookid,)) try: + if not data: + logger.debug('[%s] is not a valid bookid' % bookid) 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: + if not data: + logger.debug('[%s] is not a valid issueid' % bookid) 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) + logger.debug("No attachment found for [%s]" % 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" diff --git a/lazylibrarian/postprocess.py b/lazylibrarian/postprocess.py index 4efcd2f2b..cb3bcab50 100644 --- a/lazylibrarian/postprocess.py +++ b/lazylibrarian/postprocess.py @@ -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 @@ -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': @@ -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 From 3d569d857632b1ccbd4fa314ecde4165846a68df Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Wed, 5 Jul 2017 23:21:53 +0200 Subject: [PATCH 2/4] Removed torznab url split --- lazylibrarian/manualbook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lazylibrarian/manualbook.py b/lazylibrarian/manualbook.py index 72bf80d32..978104ccc 100644 --- a/lazylibrarian/manualbook.py +++ b/lazylibrarian/manualbook.py @@ -127,7 +127,7 @@ def searchItem(item=None, bookid=None, cat=None): words -= len(getList(title)) score -= abs(words) if score >= 40: # ignore wildly wrong results? - if not url.startswith('magnet'): + if not url.startswith('magnet') and 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} From e4414bb21f4bb1d3ba883ec67662574f7e028aae Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Thu, 6 Jul 2017 11:12:02 +0200 Subject: [PATCH 3/4] Code tidying --- lazylibrarian/manualbook.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lazylibrarian/manualbook.py b/lazylibrarian/manualbook.py index 978104ccc..45ef2f93b 100644 --- a/lazylibrarian/manualbook.py +++ b/lazylibrarian/manualbook.py @@ -127,8 +127,9 @@ def searchItem(item=None, bookid=None, cat=None): words -= len(getList(title)) score -= abs(words) if score >= 40: # ignore wildly wrong results? - if not url.startswith('magnet') and not mode == 'torznab': # what is this split for?? - url = url.split('?')[0] + if not url.startswith('magnet'): + 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} From 33c6e72ca4a68de6766379d6b667127f2c62076b Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Thu, 6 Jul 2017 11:12:13 +0200 Subject: [PATCH 4/4] Reworked debug messages --- lazylibrarian/notifiers/__init__.py | 2 +- lazylibrarian/notifiers/email_notify.py | 50 ++++++++++++------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/lazylibrarian/notifiers/__init__.py b/lazylibrarian/notifiers/__init__.py index 583411504..f6ed7798a 100644 --- a/lazylibrarian/notifiers/__init__.py +++ b/lazylibrarian/notifiers/__init__.py @@ -73,7 +73,7 @@ def notify_download(title, bookid=None): try: for n in notifiers: if n == 'email_notifier': - n.notify_download(title, bookid) + n.notify_download(title, bookid=bookid) else: n.notify_download(title) except Exception as e: diff --git a/lazylibrarian/notifiers/email_notify.py b/lazylibrarian/notifiers/email_notify.py index 38e32df59..339f4c57b 100644 --- a/lazylibrarian/notifiers/email_notify.py +++ b/lazylibrarian/notifiers/email_notify.py @@ -108,31 +108,30 @@ def notify_download(self, title, bookid=None, force=False): if lazylibrarian.CONFIG['EMAIL_NOTIFY_ONDOWNLOAD']: files = None event = notifyStrings[NOTIFY_DOWNLOAD] - if lazylibrarian.CONFIG['EMAIL_SENDFILE_ONDOWNLOAD'] and not bookid: - logger.debug('Requested to attach book, but no bookid') - elif bookid: - myDB = database.DBConnection() - data = myDB.match('SELECT BookFile,BookName from books where BookID=?', (bookid,)) - try: - if not data: + 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) - 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: - if not data: - logger.debug('[%s] is not a valid issueid' % bookid) - filename = data['IssueFile'] - title = "%s - %s" % (data['Title'], data['IssueDate']) - logger.debug('Found %s for issueid %s' % (filename, bookid)) - except Exception: - logger.debug("No attachment found for [%s]" % bookid) - filename = '' - if filename: - files = [filename] # could add cover_image, opf - event = "LazyLibrarian Download" + 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 @@ -143,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