Skip to content

Commit

Permalink
[cli] Ensure optional CLI flags are consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Breakthrough committed Oct 20, 2024
1 parent bdb62ba commit d1768e6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
37 changes: 20 additions & 17 deletions scenedetect/_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ def scenedetect(
config: ty.Optional[ty.AnyStr],
framerate: ty.Optional[float],
min_scene_len: ty.Optional[str],
drop_short_scenes: bool,
merge_last_scene: bool,
drop_short_scenes: ty.Optional[bool],
merge_last_scene: ty.Optional[bool],
backend: ty.Optional[str],
downscale: ty.Optional[int],
frame_skip: ty.Optional[int],
Expand Down Expand Up @@ -1028,6 +1028,7 @@ def export_html_command(
"-n",
is_flag=True,
flag_value=True,
default=None,
help="Only print scene list.%s"
% (USER_CONFIG.get_help_string("list-scenes", "no-output-file")),
)
Expand All @@ -1036,13 +1037,15 @@ def export_html_command(
"-q",
is_flag=True,
flag_value=True,
default=None,
help="Suppress printing scene list.%s" % (USER_CONFIG.get_help_string("list-scenes", "quiet")),
)
@click.option(
"--skip-cuts",
"-s",
is_flag=True,
flag_value=True,
default=None,
help="Skip cutting list as first row in the CSV file. Set for RFC 4180 compliant output.%s"
% (USER_CONFIG.get_help_string("list-scenes", "skip-cuts")),
)
Expand All @@ -1051,26 +1054,26 @@ def list_scenes_command(
ctx: click.Context,
output: ty.Optional[ty.AnyStr],
filename: ty.Optional[ty.AnyStr],
no_output_file: bool,
quiet: bool,
skip_cuts: bool,
no_output_file: ty.Optional[bool],
quiet: ty.Optional[bool],
skip_cuts: ty.Optional[bool],
):
"""Create scene list CSV file (will be named $VIDEO_NAME-Scenes.csv by default)."""
ctx = ctx.obj
assert isinstance(ctx, CliContext)

no_output_file = no_output_file or ctx.config.get_value("list-scenes", "no-output-file")
scene_list_dir = ctx.config.get_value("list-scenes", "output", output)
scene_list_name_format = ctx.config.get_value("list-scenes", "filename", filename)
create_file = not ctx.config.get_value("list-scenes", "no-output-file", no_output_file)
output_dir = ctx.config.get_value("list-scenes", "output", output)
name_format = ctx.config.get_value("list-scenes", "filename", filename)
list_scenes_args = {
"cut_format": TimecodeFormat[ctx.config.get_value("list-scenes", "cut-format").upper()],
"display_scenes": ctx.config.get_value("list-scenes", "display-scenes"),
"display_cuts": ctx.config.get_value("list-scenes", "display-cuts"),
"scene_list_output": not no_output_file,
"scene_list_name_format": scene_list_name_format,
"skip_cuts": skip_cuts or ctx.config.get_value("list-scenes", "skip-cuts"),
"output_dir": scene_list_dir,
"quiet": quiet or ctx.config.get_value("list-scenes", "quiet") or ctx.quiet_mode,
"scene_list_output": create_file,
"scene_list_name_format": name_format,
"skip_cuts": ctx.config.get_value("list-scenes", "skip-cuts", skip_cuts),
"output_dir": output_dir,
"quiet": ctx.config.get_value("list-scenes", "quiet", quiet) or ctx.quiet_mode,
}
ctx.add_command(cli_commands.list_scenes, list_scenes_args)

Expand Down Expand Up @@ -1098,6 +1101,7 @@ def list_scenes_command(
"-q",
is_flag=True,
flag_value=True,
default=False,
help="Hide output from external video splitting tool.%s"
% (USER_CONFIG.get_help_string("split-video", "quiet")),
)
Expand Down Expand Up @@ -1189,9 +1193,8 @@ def split_video_command(
error = "The split-video command is incompatible with image sequences/URLs."
raise click.BadParameter(error, param_hint="split-video")

# We only load the config values for these flags/options if none of the other
# encoder flags/options were set via the CLI to avoid any conflicting options
# (e.g. if the config file sets `high-quality = yes` but `--copy` is specified).
# Overwrite flags if no encoder flags/options were set via the CLI to avoid conflicting options
# (e.g. `--copy` should override any `high-quality = yes` setting in the config file).
if not (mkvmerge or copy or high_quality or args or rate_factor or preset):
mkvmerge = ctx.config.get_value("split-video", "mkvmerge")
copy = ctx.config.get_value("split-video", "copy")
Expand Down Expand Up @@ -1244,7 +1247,7 @@ def split_video_command(
"name_format": ctx.config.get_value("split-video", "filename", filename),
"use_mkvmerge": mkvmerge,
"output_dir": ctx.config.get_value("split-video", "output", output),
"show_output": not quiet,
"show_output": not ctx.config.get_value("split-video", "quiet", quiet),
"ffmpeg_args": args,
}
ctx.add_command(cli_commands.split_video, split_video_args)
Expand Down
12 changes: 6 additions & 6 deletions scenedetect/_cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def handle_options(
downscale: ty.Optional[int],
frame_skip: int,
min_scene_len: str,
drop_short_scenes: bool,
merge_last_scene: bool,
drop_short_scenes: ty.Optional[bool],
merge_last_scene: ty.Optional[bool],
backend: ty.Optional[str],
quiet: bool,
logfile: ty.Optional[ty.AnyStr],
Expand Down Expand Up @@ -245,11 +245,11 @@ def handle_options(
if min_scene_len is not None
else self.config.get_value("global", "min-scene-len"),
)
self.drop_short_scenes = drop_short_scenes or self.config.get_value(
"global", "drop-short-scenes"
self.drop_short_scenes = self.config.get_value(
"global", "drop-short-scenes", drop_short_scenes
)
self.merge_last_scene = merge_last_scene or self.config.get_value(
"global", "merge-last-scene"
self.merge_last_scene = self.config.get_value(
"global", "merge-last-scene", merge_last_scene
)
self.frame_skip = self.config.get_value("global", "frame-skip", frame_skip)

Expand Down

0 comments on commit d1768e6

Please sign in to comment.