Skip to content

Commit 1154c01

Browse files
committed
[cli] Simplify parsing of default values
1 parent ded3708 commit 1154c01

File tree

4 files changed

+25
-30
lines changed

4 files changed

+25
-30
lines changed

scenedetect/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def main():
5252
if __debug__:
5353
raise
5454
else:
55-
logger.critical("Unhandled exception:", exc_info=ex)
55+
logger.critical("ERROR: Unhandled exception:", exc_info=ex)
5656
raise SystemExit(1) from None
5757

5858

scenedetect/_cli/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ def list_scenes_command(
10601060
assert isinstance(ctx, CliContext)
10611061

10621062
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, ignore_default=True)
1063+
scene_list_dir = ctx.config.get_value("list-scenes", "output", output)
10641064
scene_list_name_format = ctx.config.get_value("list-scenes", "filename", filename)
10651065
list_scenes_args = {
10661066
"cut_format": TimecodeFormat[ctx.config.get_value("list-scenes", "cut-format").upper()],
@@ -1243,7 +1243,7 @@ def split_video_command(
12431243
split_video_args = {
12441244
"name_format": ctx.config.get_value("split-video", "filename", filename),
12451245
"use_mkvmerge": mkvmerge,
1246-
"output_dir": ctx.config.get_value("split-video", "output", output, ignore_default=True),
1246+
"output_dir": ctx.config.get_value("split-video", "output", output),
12471247
"show_output": not quiet,
12481248
"ffmpeg_args": args,
12491249
}
@@ -1420,7 +1420,7 @@ def save_images_command(
14201420
]
14211421
logger.debug("\n".join(error_strs))
14221422
raise click.BadParameter("\n".join(error_strs), param_hint="save-images")
1423-
output = ctx.config.get_value("save-images", "output", output, ignore_default=True)
1423+
output = ctx.config.get_value("save-images", "output", output)
14241424

14251425
save_images_args = {
14261426
"encoder_param": compression if png else quality,

scenedetect/_cli/config.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def format(self, timecode: FrameTimecode) -> str:
306306
"display-cuts": True,
307307
"display-scenes": True,
308308
"filename": "$VIDEO_NAME-Scenes.csv",
309-
"output": "",
309+
"output": None,
310310
"no-output-file": False,
311311
"quiet": False,
312312
"skip-cuts": False,
@@ -320,7 +320,7 @@ def format(self, timecode: FrameTimecode) -> str:
320320
"frame-skip": 0,
321321
"merge-last-scene": False,
322322
"min-scene-len": TimecodeValue("0.6s"),
323-
"output": "",
323+
"output": None,
324324
"verbosity": "info",
325325
},
326326
"save-images": {
@@ -330,7 +330,7 @@ def format(self, timecode: FrameTimecode) -> str:
330330
"frame-margin": 1,
331331
"height": 0,
332332
"num-images": 3,
333-
"output": "",
333+
"output": None,
334334
"quality": RangeValue(_PLACEHOLDER, min_val=0, max_val=100),
335335
"scale": 1.0,
336336
"scale-method": "linear",
@@ -342,7 +342,7 @@ def format(self, timecode: FrameTimecode) -> str:
342342
"filename": "$VIDEO_NAME-Scene-$SCENE_NUMBER",
343343
"high-quality": False,
344344
"mkvmerge": False,
345-
"output": "",
345+
"output": None,
346346
"preset": "veryfast",
347347
"quiet": False,
348348
"rate-factor": RangeValue(22, min_val=0, max_val=100),
@@ -580,7 +580,6 @@ def get_value(
580580
command: str,
581581
option: str,
582582
override: Optional[ConfigValue] = None,
583-
ignore_default: bool = False,
584583
) -> ConfigValue:
585584
"""Get the current setting or default value of the specified command option."""
586585
assert command in CONFIG_MAP and option in CONFIG_MAP[command]
@@ -590,8 +589,6 @@ def get_value(
590589
value = self._config[command][option]
591590
else:
592591
value = CONFIG_MAP[command][option]
593-
if ignore_default:
594-
return None
595592
if issubclass(type(value), ValidatedValue):
596593
return value.value
597594
return value

scenedetect/_cli/context.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def handle_options(
187187
init_failure = not self.config.initialized
188188
init_log = self.config.get_init_log()
189189
quiet = not init_failure and quiet
190-
self._initialize_logging(quiet=quiet, verbosity=verbosity, logfile=logfile)
190+
self._initialize_logging(quiet, verbosity, logfile)
191191

192192
# Configuration file was specified via CLI argument -c/--config.
193193
if config and not init_failure:
@@ -229,20 +229,16 @@ def handle_options(
229229
param_hint="frame skip + stats file",
230230
)
231231

232-
# Handle the case where -i/--input was not specified (e.g. for the `help` command).
232+
# Handle case where -i/--input was not specified (e.g. for the `help` command).
233233
if input_path is None:
234234
return
235235

236-
# Have to load the input video to obtain a time base before parsing timecodes.
237-
self._open_video_stream(
238-
input_path=input_path,
239-
framerate=framerate,
240-
backend=self.config.get_value("global", "backend", backend, ignore_default=True),
241-
)
236+
# Load the input video to obtain a time base for parsing timecodes.
237+
self._open_video_stream(input_path, framerate, backend)
242238

243-
self.output_dir = output if output else self.config.get_value("global", "output")
239+
self.output_dir = self.config.get_value("global", "output", output)
244240
if self.output_dir:
245-
logger.info("Output directory set:\n %s", self.output_dir)
241+
logger.debug("Output directory set:\n %s", self.output_dir)
246242

247243
self.min_scene_len = self.parse_timecode(
248244
min_scene_len
@@ -507,7 +503,10 @@ def _initialize_logging(
507503
init_logger(log_level=curr_verbosity, show_stdout=not self.quiet_mode, log_file=logfile)
508504

509505
def _open_video_stream(
510-
self, input_path: ty.AnyStr, framerate: ty.Optional[float], backend: ty.Optional[str]
506+
self,
507+
input_path: ty.AnyStr,
508+
framerate: ty.Optional[float],
509+
backend: ty.Optional[str],
511510
):
512511
if "%" in input_path and backend != "opencv":
513512
raise click.BadParameter(
@@ -517,14 +516,13 @@ def _open_video_stream(
517516
if framerate is not None and framerate < MAX_FPS_DELTA:
518517
raise click.BadParameter("Invalid framerate specified!", param_hint="-f/--framerate")
519518
try:
520-
if backend is None:
521-
backend = self.config.get_value("global", "backend")
522-
else:
523-
if backend not in AVAILABLE_BACKENDS:
524-
raise click.BadParameter(
525-
"Specified backend %s is not available on this system!" % backend,
526-
param_hint="-b/--backend",
527-
)
519+
backend = self.config.get_value("global", "backend", backend)
520+
if backend not in AVAILABLE_BACKENDS:
521+
raise click.BadParameter(
522+
"Specified backend %s is not available on this system!" % backend,
523+
param_hint="-b/--backend",
524+
)
525+
528526
# Open the video with the specified backend, loading any required config settings.
529527
if backend == "pyav":
530528
self.video_stream = open_video(

0 commit comments

Comments
 (0)