From fbac3e38ac116855b930ee60fb3c997337ae17b7 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 8 May 2022 12:55:54 +0200 Subject: [PATCH] Eenabled send epubs to E-Reader devices --- README.md | 4 +- cps/admin.py | 6 +- cps/helper.py | 66 +- cps/static/js/caliBlur.js | 16 +- cps/tasks/convert.py | 16 +- cps/templates/admin.html | 2 +- cps/templates/detail.html | 16 +- cps/templates/shelfdown.html | 2 +- cps/templates/user_edit.html | 2 +- cps/templates/user_table.html | 2 +- cps/web.py | 6 +- test/Calibre-Web TestSummary_Linux.html | 824 +++++++++--------------- 12 files changed, 358 insertions(+), 604 deletions(-) mode change 100644 => 100755 README.md mode change 100644 => 100755 cps/admin.py mode change 100644 => 100755 cps/helper.py mode change 100644 => 100755 cps/static/js/caliBlur.js mode change 100644 => 100755 cps/tasks/convert.py mode change 100644 => 100755 cps/templates/admin.html mode change 100644 => 100755 cps/templates/detail.html mode change 100644 => 100755 cps/templates/shelfdown.html mode change 100644 => 100755 cps/templates/user_edit.html mode change 100644 => 100755 cps/templates/user_table.html mode change 100644 => 100755 cps/web.py diff --git a/README.md b/README.md old mode 100644 new mode 100755 index c3422041..41cb5818 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Calibre-Web is a web app providing a clean interface for browsing, reading and d - Support for converting eBooks through Calibre binaries - Restrict eBook download to logged-in users - Support for public user registration -- Send eBooks to Kindle devices with the click of a button +- Send eBooks to E-Readers with the click of a button - Sync your Kobo devices through Calibre-Web with your Calibre library - Support for reading eBooks directly in the browser (.txt, .epub, .pdf, .cbr, .cbt, .cbz, .djvu) - Upload new books in many formats, including audio formats (.mp3, .m4a, .m4b) @@ -65,7 +65,7 @@ Afterwards you can configure your Calibre-Web instance ([Basic Configuration](ht python 3.5+ -Optionally, to enable on-the-fly conversion from one ebook format to another when using the send-to-kindle feature, or during editing of ebooks metadata: +Optionally, to enable on-the-fly conversion from one ebook format to another when using the send-to-ereader feature, or during editing of ebooks metadata: [Download and install](https://calibre-ebook.com/download) the Calibre desktop program for your platform and enter the folder including program name (normally /opt/calibre/ebook-convert, or C:\Program Files\calibre\ebook-convert.exe) in the field "calibre's converter tool" on the setup page. diff --git a/cps/admin.py b/cps/admin.py old mode 100644 new mode 100755 index c928fe19..22127eb2 --- a/cps/admin.py +++ b/cps/admin.py @@ -1521,11 +1521,11 @@ def ldap_import_create_user(user, user_data): log.warning("LDAP User %s Already in Database", user_data) return 0, None - kindlemail = '' + ereader_mail = '' if 'mail' in user_data: useremail = user_data['mail'][0].decode('utf-8') if len(user_data['mail']) > 1: - kindlemail = user_data['mail'][1].decode('utf-8') + ereader_mail = user_data['mail'][1].decode('utf-8') else: log.debug('No Mail Field Found in LDAP Response') @@ -1541,7 +1541,7 @@ def ldap_import_create_user(user, user_data): content.name = username content.password = '' # dummy password which will be replaced by ldap one content.email = useremail - content.kindle_mail = kindlemail + content.kindle_mail = ereader_mail content.default_language = config.config_default_language content.locale = config.config_default_locale content.role = config.config_default_role diff --git a/cps/helper.py b/cps/helper.py old mode 100644 new mode 100755 index 91afe727..e8e45289 --- a/cps/helper.py +++ b/cps/helper.py @@ -72,7 +72,7 @@ except (ImportError, RuntimeError) as e: # Convert existing book entry to new format -def convert_book_format(book_id, calibre_path, old_book_format, new_book_format, user_id, kindle_mail=None): +def convert_book_format(book_id, calibre_path, old_book_format, new_book_format, user_id, ereader_mail=None): book = calibre_db.get_book(book_id) data = calibre_db.get_book_format(book.id, old_book_format) file_path = os.path.join(calibre_path, book.path, data.name) @@ -91,9 +91,9 @@ def convert_book_format(book_id, calibre_path, old_book_format, new_book_format, format=old_book_format, fn=data.name + "." + old_book_format.lower()) return error_message # read settings and append converter task to queue - if kindle_mail: + if ereader_mail: settings = config.get_mail_settings() - settings['subject'] = _('Send to Kindle') # pretranslate Subject for e-mail + settings['subject'] = _('Send to E-Reader') # pretranslate Subject for e-mail settings['body'] = _(u'This e-mail has been sent via Calibre-Web.') else: settings = dict() @@ -104,14 +104,14 @@ def convert_book_format(book_id, calibre_path, old_book_format, new_book_format, link) settings['old_book_format'] = old_book_format settings['new_book_format'] = new_book_format - WorkerThread.add(user_id, TaskConvert(file_path, book.id, txt, settings, kindle_mail, user_id)) + WorkerThread.add(user_id, TaskConvert(file_path, book.id, txt, settings, ereader_mail, user_id)) return None # Texts are not lazy translated as they are supposed to get send out as is -def send_test_mail(kindle_mail, user_name): +def send_test_mail(ereader_mail, user_name): WorkerThread.add(user_name, TaskEmail(_(u'Calibre-Web test e-mail'), None, None, - config.get_mail_settings(), kindle_mail, N_(u"Test e-mail"), + config.get_mail_settings(), ereader_mail, N_(u"Test e-mail"), _(u'This e-mail has been sent via Calibre-Web.'))) return @@ -139,26 +139,26 @@ def send_registration_mail(e_mail, user_name, default_password, resend=False): return -def check_send_to_kindle_with_converter(formats): +def check_send_to_ereader_with_converter(formats): book_formats = list() - if 'EPUB' in formats and 'MOBI' not in formats: - book_formats.append({'format': 'Mobi', + if 'EPUB' in formats and 'EPUB' not in formats: + book_formats.append({'format': 'Epub', 'convert': 1, - 'text': _('Convert %(orig)s to %(format)s and send to Kindle', - orig='Epub', - format='Mobi')}) - if 'AZW3' in formats and 'MOBI' not in formats: - book_formats.append({'format': 'Mobi', + 'text': _('Convert %(orig)s to %(format)s and send to E-Reader', + orig='Mobi', + format='Epub')}) + if 'AZW3' in formats and 'EPUB' not in formats: + book_formats.append({'format': 'Epub', 'convert': 2, - 'text': _('Convert %(orig)s to %(format)s and send to Kindle', + 'text': _('Convert %(orig)s to %(format)s and send to E-Reader', orig='Azw3', - format='Mobi')}) + format='Epub')}) return book_formats -def check_send_to_kindle(entry): +def check_send_to_ereader(entry): """ - returns all available book formats for sending to Kindle + returns all available book formats for sending to E-Reader """ formats = list() book_formats = list() @@ -166,20 +166,24 @@ def check_send_to_kindle(entry): for ele in iter(entry.data): if ele.uncompressed_size < config.mail_size: formats.append(ele.format) + if 'EPUB' in formats: + book_formats.append({'format': 'Epub', + 'convert': 0, + 'text': _('Send %(format)s to E-Reader', format='Epub')}) if 'MOBI' in formats: book_formats.append({'format': 'Mobi', 'convert': 0, - 'text': _('Send %(format)s to Kindle', format='Mobi')}) + 'text': _('Send %(format)s to E-Reader', format='Mobi')}) if 'PDF' in formats: book_formats.append({'format': 'Pdf', 'convert': 0, - 'text': _('Send %(format)s to Kindle', format='Pdf')}) + 'text': _('Send %(format)s to E-Reader', format='Pdf')}) if 'AZW' in formats: book_formats.append({'format': 'Azw', 'convert': 0, - 'text': _('Send %(format)s to Kindle', format='Azw')}) + 'text': _('Send %(format)s to E-Reader', format='Azw')}) if config.config_converterpath: - book_formats.extend(check_send_to_kindle_with_converter(formats)) + book_formats.extend(check_send_to_ereader_with_converter(formats)) return book_formats else: log.error(u'Cannot find book entry %d', entry.id) @@ -199,27 +203,27 @@ def check_read_formats(entry): # Files are processed in the following order/priority: -# 1: If Mobi file is existing, it's directly send to kindle email, -# 2: If Epub file is existing, it's converted and send to kindle email, -# 3: If Pdf file is existing, it's directly send to kindle email -def send_mail(book_id, book_format, convert, kindle_mail, calibrepath, user_id): +# 1: If Mobi file is existing, it's directly send to E-Reader email, +# 2: If Epub file is existing, it's converted and send to E-Reader email, +# 3: If Pdf file is existing, it's directly send to E-Reader email +def send_mail(book_id, book_format, convert, ereader_mail, calibrepath, user_id): """Send email with attachments""" book = calibre_db.get_book(book_id) 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) + return convert_book_format(book_id, calibrepath, u'epub', book_format.lower(), user_id, ereader_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) + return convert_book_format(book_id, calibrepath, u'azw3', book_format.lower(), user_id, ereader_mail) for entry in iter(book.data): if entry.format.upper() == book_format.upper(): converted_file_name = entry.name + '.' + book_format.lower() link = '{}'.format(url_for('web.show_book', book_id=book_id), escape(book.title)) - email_text = N_(u"%(book)s send to Kindle", book=link) - WorkerThread.add(user_id, TaskEmail(_(u"Send to Kindle"), book.path, converted_file_name, - config.get_mail_settings(), kindle_mail, + email_text = N_(u"%(book)s send to E-Reader", book=link) + WorkerThread.add(user_id, TaskEmail(_(u"Send to E-Reader"), book.path, converted_file_name, + config.get_mail_settings(), ereader_mail, email_text, _(u'This e-mail has been sent via Calibre-Web.'))) return return _(u"The requested file could not be read. Maybe wrong permissions?") diff --git a/cps/static/js/caliBlur.js b/cps/static/js/caliBlur.js old mode 100644 new mode 100755 index f99779bd..0f179645 --- a/cps/static/js/caliBlur.js +++ b/cps/static/js/caliBlur.js @@ -201,7 +201,7 @@ if ($("body.book").length > 0) { // Move dropdown lists higher in dom, replace bootstrap toggle with own toggle. $('ul[aria-labelledby="read-in-browser"]').insertBefore(".blur-wrapper").addClass("readinbrowser-drop"); - $('ul[aria-labelledby="send-to-kindle"]').insertBefore(".blur-wrapper").addClass("sendtokindle-drop"); + $('ul[aria-labelledby="send-to-kereader"]').insertBefore(".blur-wrapper").addClass("sendtoereader-drop"); $(".leramslist").insertBefore(".blur-wrapper"); $('ul[aria-labelledby="btnGroupDrop1"]').insertBefore(".blur-wrapper").addClass("leramslist"); $("#add-to-shelves").insertBefore(".blur-wrapper"); @@ -215,7 +215,7 @@ if ($("body.book").length > 0) { }); $("#sendbtn2").click(function () { - $(".sendtokindle-drop").toggle(); + $(".sendtoereader-drop").toggle(); }); @@ -242,12 +242,12 @@ if ($("body.book").length > 0) { if ($("#sendbtn2").length > 0) { position = $("#sendbtn2").offset().left - if (position + $(".sendtokindle-drop").width() > $(window).width()) { - positionOff = position + $(".sendtokindle-drop").width() - $(window).width(); + if (position + $(".sendtoereader-drop").width() > $(window).width()) { + positionOff = position + $(".sendtoereader-drop").width() - $(window).width(); ribPosition = position - positionOff - 5 - $(".sendtokindle-drop").attr("style", "left: " + ribPosition + "px !important; right: auto; top: " + topPos + "px"); + $(".sendtoereader-drop").attr("style", "left: " + ribPosition + "px !important; right: auto; top: " + topPos + "px"); } else { - $(".sendtokindle-drop").attr("style", "left: " + position + "px !important; right: auto; top: " + topPos + "px"); + $(".sendtoereader-drop").attr("style", "left: " + position + "px !important; right: auto; top: " + topPos + "px"); } } @@ -300,7 +300,7 @@ if ($("body.book").length > 0) { $(document).mouseup(function (e) { var container = new Array(); container.push($('ul[aria-labelledby="read-in-browser"]')); - container.push($(".sendtokindle-drop")); + container.push($(".sendtoereader-drop")); container.push($(".leramslist")); container.push($("#add-to-shelves")); container.push($(".navbar-collapse.collapse.in")); @@ -666,7 +666,7 @@ $("#sendbtn").attr({ $("#sendbtn2").attr({ "data-toggle-two": "tooltip", - "title": $("#sendbtn2").text(), // "Send to Kindle", + "title": $("#sendbtn2").text(), // "Send to E-Reader", "data-placement": "bottom", "data-viewport": ".btn-toolbar" }) diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py old mode 100644 new mode 100755 index 3062850d..a9f0f055 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -41,13 +41,13 @@ log = logger.create() class TaskConvert(CalibreTask): - def __init__(self, file_path, book_id, task_message, settings, kindle_mail, user=None): + def __init__(self, file_path, book_id, task_message, settings, ereader_mail, user=None): super(TaskConvert, self).__init__(task_message) self.file_path = file_path self.book_id = book_id self.title = "" self.settings = settings - self.kindle_mail = kindle_mail + self.ereader_mail = ereader_mail self.user = user self.results = dict() @@ -85,16 +85,16 @@ class TaskConvert(CalibreTask): # Upload files to gdrive gdriveutils.updateGdriveCalibreFromLocal() self._handleSuccess() - if self.kindle_mail: - # if we're sending to kindle after converting, create a one-off task and run it immediately + if self.ereader_mail: + # if we're sending to E-Reader after converting, create a one-off task and run it immediately # todo: figure out how to incorporate this into the progress try: - EmailText = N_(u"%(book)s send to Kindle", book=escape(self.title)) + EmailText = N_(u"%(book)s send to E-Reader", book=escape(self.title)) worker_thread.add(self.user, TaskEmail(self.settings['subject'], self.results["path"], filename, self.settings, - self.kindle_mail, + self.ereader_mail, EmailText, self.settings['body'], internal=True) @@ -112,7 +112,7 @@ class TaskConvert(CalibreTask): # check to see if destination format already exists - or if book is in database # if it does - mark the conversion task as complete and return a success - # this will allow send to kindle workflow to continue to work + # this will allow send to E-Reader workflow to continue to work if os.path.isfile(file_path + format_new_ext) or\ local_db.get_book_format(self.book_id, self.settings['new_book_format']): log.info("Book id %d already converted to %s", book_id, format_new_ext) @@ -273,7 +273,7 @@ class TaskConvert(CalibreTask): return N_("Convert") def __str__(self): - return "Convert {} {}".format(self.book_id, self.kindle_mail) + return "Convert {} {}".format(self.book_id, self.ereader_mail) @property def is_cancellable(self): diff --git a/cps/templates/admin.html b/cps/templates/admin.html old mode 100644 new mode 100755 index f1c3749a..553dcbb6 --- a/cps/templates/admin.html +++ b/cps/templates/admin.html @@ -12,7 +12,7 @@ {{_('Username')}} {{_('E-mail Address')}} - {{_('Send to Kindle E-mail Address')}} + {{_('Send to E-Reader E-mail Address')}} {{_('Downloads')}} {{_('Admin')}} {{_('Password')}} diff --git a/cps/templates/detail.html b/cps/templates/detail.html old mode 100644 new mode 100755 index 3af205fb..50151603 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -10,7 +10,7 @@