From 7098d08888a2f0e340737ba8f97202f81d3712cf Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 15 Dec 2019 18:44:02 +0100 Subject: [PATCH] Added option to convert AZW3 to mobi for sending to kindle --- cps/editbooks.py | 4 ++-- cps/helper.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index 51ed9e48..91134db6 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -729,7 +729,7 @@ def convert_bookformat(book_id): if (book_format_from is None) or (book_format_to is None): flash(_(u"Source or destination format for conversion missing"), category="error") - return redirect(request.environ["HTTP_REFERER"]) + return redirect(url_for('editbook.edit_book', book_id=book_id)) log.info('converting: book id: %s from: %s to: %s', book_id, book_format_from, book_format_to) rtn = helper.convert_book_format(book_id, config.config_calibre_dir, book_format_from.upper(), @@ -741,4 +741,4 @@ def convert_bookformat(book_id): category="success") else: flash(_(u"There was an error converting this book: %(res)s", res=rtn), category="error") - return redirect(request.environ["HTTP_REFERER"]) + return redirect(url_for('editbook.edit_book', book_id=book_id)) diff --git a/cps/helper.py b/cps/helper.py index 025fc4d1..2b92ef75 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -167,10 +167,10 @@ def check_send_to_kindle(entry): if 'EPUB' in formats and not 'MOBI' in formats: bookformats.append({'format': 'Mobi','convert':1, 'text':_('Convert %(orig)s to %(format)s and send to Kindle',orig='Epub',format='Mobi')}) - '''if config.config_ebookconverter == 2: - if 'EPUB' in formats and not 'AZW3' in formats: - bookformats.append({'format': 'Azw3','convert':1, - 'text':_('Convert %(orig)s to %(format)s and send to Kindle',orig='Epub',format='Azw3')})''' + if config.config_ebookconverter == 2: + if 'AZW3' in formats and not 'MOBI' in formats: + bookformats.append({'format': 'Mobi','convert':2, + 'text':_('Convert %(orig)s to %(format)s and send to Kindle',orig='Azw3',format='Mobi')}) return bookformats else: log.error(u'Cannot find book entry %d', entry.id) @@ -197,9 +197,13 @@ def send_mail(book_id, book_format, convert, kindle_mail, calibrepath, user_id): """Send email with attachments""" book = db.session.query(db.Books).filter(db.Books.id == book_id).first() - if convert: + if convert == 1: # returns None if success, otherwise errormessage return convert_book_format(book_id, calibrepath, u'epub', book_format.lower(), user_id, kindle_mail) + if convert == 2: + # returns None if success, otherwise errormessage + return convert_book_format(book_id, calibrepath, u'azw3', book_format.lower(), user_id, kindle_mail) + for entry in iter(book.data): if entry.format.upper() == book_format.upper():