Skip to content

Commit b2383b5

Browse files
committed
[cli] Replace export-html with save-html
1 parent c5840cb commit b2383b5

File tree

9 files changed

+203
-142
lines changed

9 files changed

+203
-142
lines changed

benchmark/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import argparse
2-
import time
32
import os
3+
import time
44
import typing as ty
55

66
from tqdm import tqdm

docs/cli.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,17 +432,17 @@ Commands
432432
************************************************************************
433433

434434

435-
.. _command-export-html:
435+
.. _command-save-html:
436436

437-
.. program:: scenedetect export-html
437+
.. program:: scenedetect save-html
438438

439439

440-
``export-html``
440+
``save-html``
441441
========================================================================
442442

443-
Export scene list to HTML file.
443+
Save scene list to HTML file.
444444

445-
To customize image generation, specify the :ref:`save-images <command-save-images>` command before :ref:`export-html <command-export-html>`. This command always uses the result of the preceeding :ref:`save-images <command-save-images>` command, or runs it with the default config values unless ``--no-images`` is set.
445+
To customize image generation, specify the :ref:`save-images <command-save-images>` command before :ref:`save-html <command-save-html>`. This command always uses the result of the preceeding :ref:`save-images <command-save-images>` command, or runs it with the default config values unless ``--no-images`` is set.
446446

447447

448448
Options

scenedetect.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
#threading = yes
245245

246246

247-
[export-html]
247+
[save-html]
248248
# Filename format of created HTML file. Can use $VIDEO_NAME in the name.
249249
#filename = $VIDEO_NAME-Scenes.html
250250

scenedetect/_cli/__init__.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import os
2424
import os.path
2525
import typing as ty
26+
from copy import deepcopy
2627

2728
import click
2829

@@ -350,6 +351,13 @@ def scenedetect(
350351
)
351352

352353

354+
def add_hidden_alias(command: click.Command, alias: str):
355+
"""Adds a copy of `command` that can be invoked under the name `alias`."""
356+
hidden_command = deepcopy(command)
357+
hidden_command.hidden = True
358+
scenedetect.add_command(hidden_command, alias)
359+
360+
353361
@click.command("help", cls=Command)
354362
@click.argument(
355363
"command_name",
@@ -359,6 +367,7 @@ def scenedetect(
359367
@click.pass_context
360368
def help_command(ctx: click.Context, command_name: str):
361369
"""Print full help reference."""
370+
# TODO: Other commands still seem to run if this is specified.
362371
assert isinstance(ctx.parent.command, click.MultiCommand)
363372
parent_command = ctx.parent.command
364373
all_commands = set(parent_command.list_commands(ctx))
@@ -973,45 +982,45 @@ def load_scenes_command(
973982
)
974983

975984

976-
EXPORT_HTML_HELP = """Export scene list to HTML file.
985+
SAVE_HTML_HELP = """Save scene list to HTML file.
977986
978-
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.
987+
To customize image generation, specify the `save-images` command before `save-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.
979988
"""
980989

981990

982-
@click.command("export-html", cls=Command, help=EXPORT_HTML_HELP)
991+
@click.command("save-html", cls=Command, help=SAVE_HTML_HELP)
983992
@click.option(
984993
"--filename",
985994
"-f",
986995
metavar="NAME",
987996
default="$VIDEO_NAME-Scenes.html",
988997
type=click.STRING,
989998
help="Filename format to use for the scene list HTML file. You can use the $VIDEO_NAME macro in the file name. Note that you may have to wrap the format name using single quotes.%s"
990-
% (USER_CONFIG.get_help_string("export-html", "filename")),
999+
% (USER_CONFIG.get_help_string("save-html", "filename")),
9911000
)
9921001
@click.option(
9931002
"--no-images",
9941003
"-n",
9951004
is_flag=True,
9961005
flag_value=True,
9971006
help="Do not include images with the result.%s"
998-
% (USER_CONFIG.get_help_string("export-html", "no-images")),
1007+
% (USER_CONFIG.get_help_string("save-html", "no-images")),
9991008
)
10001009
@click.option(
10011010
"--image-width",
10021011
"-w",
10031012
metavar="pixels",
10041013
type=click.INT,
10051014
help="Width in pixels of the images in the resulting HTML table.%s"
1006-
% (USER_CONFIG.get_help_string("export-html", "image-width", show_default=False)),
1015+
% (USER_CONFIG.get_help_string("save-html", "image-width", show_default=False)),
10071016
)
10081017
@click.option(
10091018
"--image-height",
10101019
"-h",
10111020
metavar="pixels",
10121021
type=click.INT,
10131022
help="Height in pixels of the images in the resulting HTML table.%s"
1014-
% (USER_CONFIG.get_help_string("export-html", "image-height", show_default=False)),
1023+
% (USER_CONFIG.get_help_string("save-html", "image-height", show_default=False)),
10151024
)
10161025
@click.option(
10171026
"--show",
@@ -1020,34 +1029,33 @@ def load_scenes_command(
10201029
flag_value=True,
10211030
default=None,
10221031
help="Automatically open resulting HTML when processing is complete.%s"
1023-
% (USER_CONFIG.get_help_string("export-html", "show")),
1032+
% (USER_CONFIG.get_help_string("save-html", "show")),
10241033
)
10251034
@click.pass_context
1026-
def export_html_command(
1035+
def save_html_command(
10271036
ctx: click.Context,
10281037
filename: ty.Optional[ty.AnyStr],
10291038
no_images: bool,
10301039
image_width: ty.Optional[int],
10311040
image_height: ty.Optional[int],
10321041
show: bool,
10331042
):
1034-
# TODO: Rename this command to save-html to align with other export commands. This will require
1035-
# that we allow `export-html` as an alias on the CLI and via the config file for a few versions
1036-
# as to not break existing workflows.
1043+
if ctx.command.name == "save-html":
1044+
logger.warning("WARNING: export-html is deprecated, use save-html instead.")
10371045
ctx = ctx.obj
10381046
assert isinstance(ctx, CliContext)
1039-
include_images = not ctx.config.get_value("export-html", "no-images", no_images)
1047+
include_images = not ctx.config.get_value("save-html", "no-images", no_images)
10401048
# Make sure a save-images command is in the pipeline for us to use the results from.
10411049
if include_images and not ctx.save_images:
10421050
save_images_command.callback()
1043-
export_html_args = {
1044-
"html_name_format": ctx.config.get_value("export-html", "filename", filename),
1045-
"image_width": ctx.config.get_value("export-html", "image-width", image_width),
1046-
"image_height": ctx.config.get_value("export-html", "image-height", image_height),
1051+
save_html_args = {
1052+
"html_name_format": ctx.config.get_value("save-html", "filename", filename),
1053+
"image_width": ctx.config.get_value("save-html", "image-width", image_width),
1054+
"image_height": ctx.config.get_value("save-html", "image-height", image_height),
10471055
"include_images": include_images,
1048-
"show": ctx.config.get_value("export-html", "show", show),
1056+
"show": ctx.config.get_value("save-html", "show", show),
10491057
}
1050-
ctx.add_command(cli_commands.export_html, export_html_args)
1058+
ctx.add_command(cli_commands.save_html, save_html_args)
10511059

10521060

10531061
LIST_SCENES_HELP = """Create scene list CSV file (will be named $VIDEO_NAME-Scenes.csv by default).
@@ -1509,7 +1517,7 @@ def save_images_command(
15091517
}
15101518
ctx.add_command(cli_commands.save_images, save_images_args)
15111519

1512-
# Record that we added a save-images command to the pipeline so we can allow export-html
1520+
# Record that we added a save-images command to the pipeline so we can allow save-html
15131521
# to run afterwards (it is dependent on the output).
15141522
ctx.save_images = True
15151523

@@ -1585,8 +1593,11 @@ def save_qp_command(
15851593
scenedetect.add_command(detect_threshold_command)
15861594

15871595
# Output
1588-
scenedetect.add_command(export_html_command)
1596+
scenedetect.add_command(save_html_command)
15891597
scenedetect.add_command(save_qp_command)
15901598
scenedetect.add_command(list_scenes_command)
15911599
scenedetect.add_command(save_images_command)
15921600
scenedetect.add_command(split_video_command)
1601+
1602+
# Deprecated Commands (Hidden From Help Output)
1603+
add_hidden_alias(save_html_command, "export-html") # Deprecated in v0.6.6, replaced with save-html

scenedetect/_cli/commands.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
logger = logging.getLogger("pyscenedetect")
3636

3737

38-
def export_html(
38+
def save_html(
3939
context: CliContext,
4040
scenes: SceneList,
4141
cuts: CutList,
@@ -45,7 +45,7 @@ def export_html(
4545
include_images: bool,
4646
show: bool,
4747
):
48-
"""Handles the `export-html` command."""
48+
"""Handles the `save-html` command."""
4949
(image_filenames, output_dir) = (
5050
context.save_images_result
5151
if context.save_images_result is not None
@@ -198,7 +198,7 @@ def save_images(
198198
interpolation=interpolation,
199199
threading=threading,
200200
)
201-
# Save the result for use by `export-html` if required.
201+
# Save the result for use by `save-html` if required.
202202
context.save_images_result = (images, output_dir)
203203

204204

0 commit comments

Comments
 (0)