From 08f9dcb12f3efe6acaa8ce56f534c68f159f7726 Mon Sep 17 00:00:00 2001 From: Breakthrough Date: Sat, 19 Oct 2024 19:15:03 -0400 Subject: [PATCH] [export-html] Invoke `save-images` automatically --- scenedetect/_cli/__init__.py | 42 +++++++++++++++++++----------------- website/pages/changelog.md | 3 +++ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/scenedetect/_cli/__init__.py b/scenedetect/_cli/__init__.py index 1c45213d..8cc74da2 100644 --- a/scenedetect/_cli/__init__.py +++ b/scenedetect/_cli/__init__.py @@ -959,9 +959,10 @@ def load_scenes_command( ) @click.option( "--no-images", + "-n", is_flag=True, flag_value=True, - help="Export the scene list including or excluding the saved images.%s" + help="Do not include images with the result.%s" % (USER_CONFIG.get_help_string("export-html", "no-images")), ) @click.option( @@ -997,21 +998,22 @@ def export_html_command( image_height: ty.Optional[int], show: bool, ): - """Export scene list to HTML file. Requires save-images unless --no-images is specified.""" + """Export scene list to HTML file. + + To customize image generation, specify the `save-images` command before `export-html`. This command always uses the result of the preceeding `save-images` command, or runs it with the default config values unless `--no-images` is set. + """ ctx = ctx.obj assert isinstance(ctx, CliContext) - - no_images = no_images or ctx.config.get_value("export-html", "no-images") - if not ctx.save_images and not no_images: - raise click.BadArgumentUsage( - "export-html requires that save-images precedes it or --no-images is specified." - ) export_html_args = { "html_name_format": ctx.config.get_value("export-html", "filename", filename), "image_width": ctx.config.get_value("export-html", "image-width", image_width), "image_height": ctx.config.get_value("export-html", "image-height", image_height), "show": ctx.config.get_value("export-html", "show", show), } + no_images = no_images or ctx.config.get_value("export-html", "no-images") + if not ctx.save_images and not no_images: + # Ensure we generate some images for the HTML unless --no-images was specified. + save_images_command.callback() ctx.add_command(cli_commands.export_html, export_html_args) @@ -1366,18 +1368,18 @@ def split_video_command( @click.pass_context def save_images_command( ctx: click.Context, - output: ty.Optional[ty.AnyStr], - filename: ty.Optional[ty.AnyStr], - num_images: ty.Optional[int], - jpeg: bool, - webp: bool, - quality: ty.Optional[int], - png: bool, - compression: ty.Optional[int], - frame_margin: ty.Optional[int], - scale: ty.Optional[float], - height: ty.Optional[int], - width: ty.Optional[int], + output: ty.Optional[ty.AnyStr] = None, + filename: ty.Optional[ty.AnyStr] = None, + num_images: ty.Optional[int] = None, + jpeg: bool = False, + webp: bool = False, + quality: ty.Optional[int] = None, + png: bool = False, + compression: ty.Optional[int] = None, + frame_margin: ty.Optional[int] = None, + scale: ty.Optional[float] = None, + height: ty.Optional[int] = None, + width: ty.Optional[int] = None, ): """Create images for each detected scene. diff --git a/website/pages/changelog.md b/website/pages/changelog.md index f82110e1..070426a4 100644 --- a/website/pages/changelog.md +++ b/website/pages/changelog.md @@ -588,3 +588,6 @@ Development - [bugfix] Fix `ContentDetector` crash when using callbacks [#416](https://github.com/Breakthrough/PySceneDetect/issues/416) [#420](https://github.com/Breakthrough/PySceneDetect/issues/420) - [general] Timecodes of the form `MM:SS[.nnn]` are now processed correctly [#443](https://github.com/Breakthrough/PySceneDetect/issues/443) - [api] The `save_to_csv` function now works correctly with paths from the `pathlib` module + - [feature] Add new `--show` flag to `export-html` command to launch browser after processing (#442) + - [improvement] The `export-html` command now implicitly invokes `save-images` with default parameters + - The output of the `export-html` command will always use the result of the `save-images` command that *precedes* it