Skip to content

Commit d1768e6

Browse files
committed
[cli] Ensure optional CLI flags are consistent
1 parent bdb62ba commit d1768e6

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

scenedetect/_cli/__init__.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ def scenedetect(
281281
config: ty.Optional[ty.AnyStr],
282282
framerate: ty.Optional[float],
283283
min_scene_len: ty.Optional[str],
284-
drop_short_scenes: bool,
285-
merge_last_scene: bool,
284+
drop_short_scenes: ty.Optional[bool],
285+
merge_last_scene: ty.Optional[bool],
286286
backend: ty.Optional[str],
287287
downscale: ty.Optional[int],
288288
frame_skip: ty.Optional[int],
@@ -1028,6 +1028,7 @@ def export_html_command(
10281028
"-n",
10291029
is_flag=True,
10301030
flag_value=True,
1031+
default=None,
10311032
help="Only print scene list.%s"
10321033
% (USER_CONFIG.get_help_string("list-scenes", "no-output-file")),
10331034
)
@@ -1036,13 +1037,15 @@ def export_html_command(
10361037
"-q",
10371038
is_flag=True,
10381039
flag_value=True,
1040+
default=None,
10391041
help="Suppress printing scene list.%s" % (USER_CONFIG.get_help_string("list-scenes", "quiet")),
10401042
)
10411043
@click.option(
10421044
"--skip-cuts",
10431045
"-s",
10441046
is_flag=True,
10451047
flag_value=True,
1048+
default=None,
10461049
help="Skip cutting list as first row in the CSV file. Set for RFC 4180 compliant output.%s"
10471050
% (USER_CONFIG.get_help_string("list-scenes", "skip-cuts")),
10481051
)
@@ -1051,26 +1054,26 @@ def list_scenes_command(
10511054
ctx: click.Context,
10521055
output: ty.Optional[ty.AnyStr],
10531056
filename: ty.Optional[ty.AnyStr],
1054-
no_output_file: bool,
1055-
quiet: bool,
1056-
skip_cuts: bool,
1057+
no_output_file: ty.Optional[bool],
1058+
quiet: ty.Optional[bool],
1059+
skip_cuts: ty.Optional[bool],
10571060
):
10581061
"""Create scene list CSV file (will be named $VIDEO_NAME-Scenes.csv by default)."""
10591062
ctx = ctx.obj
10601063
assert isinstance(ctx, CliContext)
10611064

1062-
no_output_file = no_output_file or ctx.config.get_value("list-scenes", "no-output-file")
1063-
scene_list_dir = ctx.config.get_value("list-scenes", "output", output)
1064-
scene_list_name_format = ctx.config.get_value("list-scenes", "filename", filename)
1065+
create_file = not ctx.config.get_value("list-scenes", "no-output-file", no_output_file)
1066+
output_dir = ctx.config.get_value("list-scenes", "output", output)
1067+
name_format = ctx.config.get_value("list-scenes", "filename", filename)
10651068
list_scenes_args = {
10661069
"cut_format": TimecodeFormat[ctx.config.get_value("list-scenes", "cut-format").upper()],
10671070
"display_scenes": ctx.config.get_value("list-scenes", "display-scenes"),
10681071
"display_cuts": ctx.config.get_value("list-scenes", "display-cuts"),
1069-
"scene_list_output": not no_output_file,
1070-
"scene_list_name_format": scene_list_name_format,
1071-
"skip_cuts": skip_cuts or ctx.config.get_value("list-scenes", "skip-cuts"),
1072-
"output_dir": scene_list_dir,
1073-
"quiet": quiet or ctx.config.get_value("list-scenes", "quiet") or ctx.quiet_mode,
1072+
"scene_list_output": create_file,
1073+
"scene_list_name_format": name_format,
1074+
"skip_cuts": ctx.config.get_value("list-scenes", "skip-cuts", skip_cuts),
1075+
"output_dir": output_dir,
1076+
"quiet": ctx.config.get_value("list-scenes", "quiet", quiet) or ctx.quiet_mode,
10741077
}
10751078
ctx.add_command(cli_commands.list_scenes, list_scenes_args)
10761079

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

1192-
# We only load the config values for these flags/options if none of the other
1193-
# encoder flags/options were set via the CLI to avoid any conflicting options
1194-
# (e.g. if the config file sets `high-quality = yes` but `--copy` is specified).
1196+
# Overwrite flags if no encoder flags/options were set via the CLI to avoid conflicting options
1197+
# (e.g. `--copy` should override any `high-quality = yes` setting in the config file).
11951198
if not (mkvmerge or copy or high_quality or args or rate_factor or preset):
11961199
mkvmerge = ctx.config.get_value("split-video", "mkvmerge")
11971200
copy = ctx.config.get_value("split-video", "copy")
@@ -1244,7 +1247,7 @@ def split_video_command(
12441247
"name_format": ctx.config.get_value("split-video", "filename", filename),
12451248
"use_mkvmerge": mkvmerge,
12461249
"output_dir": ctx.config.get_value("split-video", "output", output),
1247-
"show_output": not quiet,
1250+
"show_output": not ctx.config.get_value("split-video", "quiet", quiet),
12481251
"ffmpeg_args": args,
12491252
}
12501253
ctx.add_command(cli_commands.split_video, split_video_args)

scenedetect/_cli/context.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ def handle_options(
160160
downscale: ty.Optional[int],
161161
frame_skip: int,
162162
min_scene_len: str,
163-
drop_short_scenes: bool,
164-
merge_last_scene: bool,
163+
drop_short_scenes: ty.Optional[bool],
164+
merge_last_scene: ty.Optional[bool],
165165
backend: ty.Optional[str],
166166
quiet: bool,
167167
logfile: ty.Optional[ty.AnyStr],
@@ -245,11 +245,11 @@ def handle_options(
245245
if min_scene_len is not None
246246
else self.config.get_value("global", "min-scene-len"),
247247
)
248-
self.drop_short_scenes = drop_short_scenes or self.config.get_value(
249-
"global", "drop-short-scenes"
248+
self.drop_short_scenes = self.config.get_value(
249+
"global", "drop-short-scenes", drop_short_scenes
250250
)
251-
self.merge_last_scene = merge_last_scene or self.config.get_value(
252-
"global", "merge-last-scene"
251+
self.merge_last_scene = self.config.get_value(
252+
"global", "merge-last-scene", merge_last_scene
253253
)
254254
self.frame_skip = self.config.get_value("global", "frame-skip", frame_skip)
255255

0 commit comments

Comments
 (0)