Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workaround for] OOM / memory "502 Bad Gateway" crashes w/ large videos' playback or download-to-client [SEE ALSO #37 & #53] #51

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
41 changes: 41 additions & 0 deletions cps/templates/watchvideo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>{{ entry.title }}</title>
<!-- Other meta tags -->
</head>

<body>

<div class="row" style="display: inline-block; width: 100%;">
<div class="col-sm-3 col-lg-3 col-xs-5">
</div>
<div class="col-sm-6 col-lg-6 book-meta" style="margin-bottom: 2%;">
<div class="video-container">
<!-- Native HTML5 video player with autoplay -->
<video
id="my-video"
controls
width="100%"
height="auto"
autoplay
preload="auto"
>
<!-- Actual video file path -->
<source src="{{ videofile }}" type="{{ videotype }}" />
Your browser does not support the video tag.
</video>
</div>

<!-- Book metadata and other information -->
<h2 id="title">{{entry.title}}</h2>

</div>
</div>

</body>

</html>
21 changes: 20 additions & 1 deletion cps/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import glob
import os
import json
import mimetypes
Expand Down Expand Up @@ -1568,7 +1569,25 @@ def read_book(book_id, book_format):
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(), anyname="")
video_path = os.path.join(config.config_calibre_dir, book.path)
# look into video_path for any file with webm or mp4 extension
video_file = ""
for file in os.listdir(video_path):
if file.endswith(".webm") or file.endswith(".mp4"):
video_file = os.path.join(video_path, file)
# align with nginx path
Copy link
Member

@holta holta Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# align with nginx path
# align with nginx path (e.g. "books-direct") specified on Lines ~24 and ~29 of:
# https://github.com/iiab/calibre-web/blob/master/scripts/calibre-web-nginx.conf

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deldesir can you take the above suggestion seriously — or if not explain why?

In lieu of soft-coding (or posting constants on top of files, as is traditional to make software more maintainable...) please at least consider clear documentation explaining how to maintain de facto global constants.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it. Definitely useful adding context in comments.

video_file = video_file.replace(config.config_calibre_dir, "/books-direct")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aligned with iiab/iiab#3680

log.debug("Found video file: %s", video_file)
break
if not video_file:
log.debug("Selected book is unavailable. File does not exist or is not accessible")
flash(_("Oops! Selected book is unavailable. File does not exist or is not accessible"),
category="error")
return redirect(url_for("web.index"))
video_type = "video/" + book_format.lower()
return render_title_template('watchvideo.html', videofile=video_file , videotype=video_type,
entry=entries, bookmark=bookmark)

for fileExt in ["cbr", "cbt", "cbz"]:
if book_format.lower() == fileExt:
all_name = str(book_id)
Expand Down