-
Notifications
You must be signed in to change notification settings - Fork 6
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
Generate cover [a.k.a. thumbnail/poster] for video manually uploaded #196
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Safe enough @codewiz?
@@ -326,8 +327,11 @@ def generate_video_cover(tmp_file_path): | |||
ffmpeg_args = [ | |||
ffmpeg_executable, | |||
'-i', tmp_file_path, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defensive programming reminder: Sanitize the file path to prevent command injection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a general warning that shlex.quote()
is not bulletproof:
(Though it's probably good enough for path sanitizing!)
@codewiz: review quickly if you can? This PR seeks to resolve: |
"2025 request" While probably not needed in 2024, the "Upload" (Upload to IIAB) button should eventually flag overweight videos that cause congestion for everyone using a school's IIAB WiFi hotspot.
ASIDE: Occasionally overweight videos arrive from the Internet too — e.g. when the video author/publisher has not bothered to compress their own work for easy/broad distribution...
|
cps/uploader.py
Outdated
def generate_video_cover(tmp_file_path): | ||
ffmpeg_executable = os.getenv('FFMPEG_PATH', 'ffmpeg') | ||
ffmpeg_output_file = os.path.splitext(tmp_file_path)[0] + '.cover.jpg' | ||
if not ffmpeg_executable: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because getenv() returns "ffmpeg" as default, this check will never succeed.
Either remove this check, or change the default to "".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
cps/uploader.py
Outdated
sanitized_input_path = sanitize_path(tmp_file_path) | ||
output_file_path = os.path.splitext(tmp_file_path)[0] + '.cover.jpg' | ||
sanitized_output_path = sanitize_path(output_file_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sanitizing this path is unnecessary because it's not controlled by the user.
The path is constructed at line 301:
tmp_file_path = os.path.join(tmp_dir, md5)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think process.Popen
invokes the program directly, avoiding all problems related to shell expansion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path is constructed at line 301:
You mean line 391, ok:
Line 391 in 46f0e6c
tmp_file_path = os.path.join(tmp_dir, md5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think
process.Popen
invokes the program directly, avoiding all problems related to shell expansion.
Clarify a specific recommendation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably @codewiz is talking about:
calibre-web/cps/subproc_wrapper.py
Line 38 in 07e2a05
return subprocess.Popen(exc_command, shell=False, stdout=sout, stderr=serr, universal_newlines=newlines, env=env) # nosec |
@deldesir please go ahead and revise (i.e. tighten up) using Bernie's recommendations, Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@holta, I did not use Calibre-Web's subprocess wrapper here because I thought it's more clear to just call it and use run
from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommendations applied in 2bdd296
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add explanatory comments back
Awesome! Allowing for easier tweaking of ffmpeg in future, if anybody chooses!
Co-authored-by: Bernie Innocenti <bernie@codewiz.org>
|
FYI @nzola a fresh install of IIAB Calibre-Web onto Ubuntu 24.04 (VM) just worked for me. As confirmed by iiab-diagnostics: https://dpaste.com/9DWAB47VX |
|
@nzola you tried two erroneous URLs:
You need to try: |
My vm/iiab is working now. |
Covers are generated using ffmpeg
Tested on Ubuntu 24.04
Related: