From ed600a9aeb638f021903edc9f3b9fa4babc53182 Mon Sep 17 00:00:00 2001 From: Aleksei Besogonov Date: Sun, 8 Dec 2024 17:29:03 -0800 Subject: [PATCH 1/2] Add a title to OPDS links This allows the OPDS consumers to distinguish `epub` and `kepub` files as they have the same MIME-type. --- cps/templates/feed.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cps/templates/feed.xml b/cps/templates/feed.xml index fb9166d7..eed76051 100644 --- a/cps/templates/feed.xml +++ b/cps/templates/feed.xml @@ -70,7 +70,7 @@ {% endif %} {% for format in entry.Books.data %} + length="{{format.uncompressed_size}}" title="{{format.format}}" mtime="{{entry.Books.atom_timestamp}}" type="{{format.format|lower|mimetype}}"/> {% endfor %} {% endfor %} From 01215aaa6874a9a2b11e5b5257d118e63b18b826 Mon Sep 17 00:00:00 2001 From: Aleksei Besogonov Date: Sun, 8 Dec 2024 23:30:05 -0800 Subject: [PATCH 2/2] Allow the web reader to use KEPUB files and print file sizes This commit allows the web reader to read the KEPUB (Kobo EPUB) files, and also shows the file sizes. This is especially useful if you have giant EPUB files with built-in audiobooks and media overlays. --- cps/helper.py | 2 +- cps/templates/detail.html | 4 ++-- cps/templates/read.html | 4 ++-- cps/web.py | 12 +++++++++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index 0706d40b..51eedb00 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -199,7 +199,7 @@ def check_send_to_ereader(entry): # Check if a reader is existing for any of the book formats, if not, return empty list, otherwise return # list with supported formats def check_read_formats(entry): - extensions_reader = {'TXT', 'PDF', 'EPUB', 'CBZ', 'CBT', 'CBR', 'DJVU', 'DJV'} + extensions_reader = {'TXT', 'PDF', 'EPUB', 'KEPUB', 'CBZ', 'CBT', 'CBR', 'DJVU', 'DJV'} book_formats = list() if len(entry.data): for ele in iter(entry.data): diff --git a/cps/templates/detail.html b/cps/templates/detail.html index b273ef9e..08f10ca9 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -88,7 +88,7 @@ @@ -97,7 +97,7 @@ href="{{ url_for('web.read_book', book_id=entry.id, book_format=entry.reader_list[0]) }}" id="readbtn" class="btn btn-primary" role="button"> {{ _('Read in Browser') }} - - {{ entry.reader_list[0] }} + - {{ entry.reader_list[0] }} ({{ entry.reader_list_sizes[entry.reader_list[0]]|filesizeformat }}) {% endif %} {% endif %} diff --git a/cps/templates/read.html b/cps/templates/read.html index affc8f42..258ab715 100644 --- a/cps/templates/read.html +++ b/cps/templates/read.html @@ -126,8 +126,8 @@ window.calibre = { filePath: "{{ url_for('static', filename='js/libs/') }}", cssPath: "{{ url_for('static', filename='css/') }}", - bookmarkUrl: "{{ url_for('web.set_bookmark', book_id=bookid, book_format='EPUB') }}", - bookUrl: "{{ url_for('web.serve_book', book_id=bookid, book_format='epub', anyname='file.epub') }}", + bookmarkUrl: "{{ url_for('web.set_bookmark', book_id=bookid, book_format=book_format or 'EPUB') }}", + bookUrl: "{{ url_for('web.serve_book', book_id=bookid, book_format=book_format, anyname='file.epub') }}", bookmark: "{{ bookmark.bookmark_key if bookmark != None }}", useBookmarks: "{{ current_user.is_authenticated | tojson }}" }; diff --git a/cps/web.py b/cps/web.py index e1068c6f..12e8454d 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1581,9 +1581,10 @@ def read_book(book_id, book_format): bookmark = ub.session.query(ub.Bookmark).filter(and_(ub.Bookmark.user_id == int(current_user.id), ub.Bookmark.book_id == book_id, ub.Bookmark.format == book_format.upper())).first() - if book_format.lower() == "epub": - log.debug("Start epub reader for %d", book_id) - return render_title_template('read.html', bookid=book_id, title=book.title, bookmark=bookmark) + if book_format.lower() == "epub" or book_format.lower() == "kepub": + log.debug("Start [k]epub reader for %d", book_id) + return render_title_template('read.html', bookid=book_id, title=book.title, bookmark=bookmark, + book_format=book_format) elif book_format.lower() == "pdf": log.debug("Start pdf reader for %d", book_id) return render_title_template('readpdf.html', pdffile=book_id, title=book.title) @@ -1644,6 +1645,11 @@ def show_book(book_id): entry.email_share_list = check_send_to_ereader(entry) entry.reader_list = check_read_formats(entry) + entry.reader_list_sizes = dict() + for data in entry.data: + if data.format.lower() in entry.reader_list: + entry.reader_list_sizes[data.format.lower()] = data.uncompressed_size + entry.audio_entries = [] for media_format in entry.data: if media_format.format.lower() in constants.EXTENSIONS_AUDIO: