From f4ebc20461bc8a13ce9cab8bb7f27fb31525457a Mon Sep 17 00:00:00 2001 From: Blondel MONDESIR Date: Thu, 29 Jun 2023 15:41:34 -0400 Subject: [PATCH] feat: add video[book] playback support --- cps/constants.py | 3 ++- cps/templates/detail.html | 27 +++++++++++++++++++++++++++ cps/web.py | 5 +++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cps/constants.py b/cps/constants.py index 069630b6..e697e048 100644 --- a/cps/constants.py +++ b/cps/constants.py @@ -142,7 +142,8 @@ except ValueError: del env_CALIBRE_PORT -EXTENSIONS_AUDIO = {'mp3', 'mp4', 'ogg', 'opus', 'wav', 'flac', 'm4a', 'm4b'} +EXTENSIONS_AUDIO = {'mp3', 'ogg', 'opus', 'wav', 'flac', 'm4a', 'm4b'} +EXTENSIONS_VIDEO = {'mp4', 'avi', 'mkv', 'webm'} EXTENSIONS_CONVERT_FROM = ['pdf', 'epub', 'mobi', 'azw3', 'docx', 'rtf', 'fb2', 'lit', 'lrf', 'txt', 'htmlz', 'rtf', 'odt', 'cbz', 'cbr'] EXTENSIONS_CONVERT_TO = ['pdf', 'epub', 'mobi', 'azw3', 'docx', 'rtf', 'fb2', diff --git a/cps/templates/detail.html b/cps/templates/detail.html index 62ba5c4e..979d532a 100755 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -120,6 +120,33 @@ {{ _('Listen in Browser') }} - {{ entry.audio_entries[0] }} {% endif %} + {% elif entry.video_entries|length > 0 and current_user.role_viewer() %} +
+ {% if entry.video_entries|length > 1 %} + + + + {% else %} + {{ _('Watch in Browser') }} - {{ entry.video_entries[0] }} + {% endif %} +
{% endif %} diff --git a/cps/web.py b/cps/web.py index 51ff32b3..a6bdc59a 100755 --- a/cps/web.py +++ b/cps/web.py @@ -1551,6 +1551,11 @@ def read_book(book_id, book_format): log.debug("Start mp3 listening for %d", book_id) return render_title_template('listenmp3.html', mp3file=book_id, audioformat=book_format.lower(), entry=entries, bookmark=bookmark) + for fileExt in constants.EXTENSIONS_VIDEO: + if book_format.lower() == fileExt: + entries = calibre_db.get_filtered_book(book_id) + log.debug("Start video watching for %d", book_id) + return serve_book.__closure__[0].cell_contents(book_id, book_format.lower()) for fileExt in ["cbr", "cbt", "cbz"]: if book_format.lower() == fileExt: all_name = str(book_id)