diff --git a/src/ytdl_sub/config/config_validator.py b/src/ytdl_sub/config/config_validator.py index 52dd62c4c..cbe377c2a 100644 --- a/src/ytdl_sub/config/config_validator.py +++ b/src/ytdl_sub/config/config_validator.py @@ -6,6 +6,7 @@ from ytdl_sub.prebuilt_presets import PREBUILT_PRESETS from ytdl_sub.utils.system import IS_WINDOWS +from ytdl_sub.validators.file_path_validators import ExistingFileValidator from ytdl_sub.validators.strict_dict_validator import StrictDictValidator from ytdl_sub.validators.validators import LiteralDictValidator from ytdl_sub.validators.validators import StringValidator @@ -39,12 +40,11 @@ def __init__(self, name: str, value: Any): self._lock_directory = self._validate_key( key="lock_directory", validator=StringValidator, default=_DEFAULT_LOCK_DIRECTORY ) - # TODO: Validate these exist self._ffmpeg_path = self._validate_key( - key="ffmpeg_path", validator=StringValidator, default=_DEFAULT_FFMPEG_PATH + key="ffmpeg_path", validator=ExistingFileValidator, default=_DEFAULT_FFMPEG_PATH ) self._ffprobe_path = self._validate_key( - key="ffprobe_path", validator=StringValidator, default=_DEFAULT_FFPROBE_PATH + key="ffprobe_path", validator=ExistingFileValidator, default=_DEFAULT_FFPROBE_PATH ) @property @@ -102,14 +102,16 @@ def lock_directory(self) -> str: @property def ffmpeg_path(self) -> str: """ - TODO: Fill out! + Optional. Path to ffmpeg executable. Defaults to ``/usr/bin/ffmpeg`` for Linux, and + ``ffmpeg.exe`` for Windows (in the same directory as ytdl-sub). """ return self._ffmpeg_path.value @property def ffprobe_path(self) -> str: """ - TODO: Fill out! + Optional. Path to ffprobe executable. Defaults to ``/usr/bin/ffprobe`` for Linux, and + ``ffprobe.exe`` for Windows (in the same directory as ytdl-sub). """ return self._ffprobe_path.value diff --git a/src/ytdl_sub/validators/file_path_validators.py b/src/ytdl_sub/validators/file_path_validators.py index 0ba4e070e..18b1fb490 100644 --- a/src/ytdl_sub/validators/file_path_validators.py +++ b/src/ytdl_sub/validators/file_path_validators.py @@ -1,9 +1,27 @@ import os from pathlib import Path +from typing import Any from typing import Dict from ytdl_sub.validators.string_formatter_validators import OverridesStringFormatterValidator from ytdl_sub.validators.string_formatter_validators import StringFormatterValidator +from ytdl_sub.validators.validators import StringValidator + + +class ExistingFileValidator(StringValidator): + _expected_value_type_name = "file" + + def __init__(self, name: str, value: Any): + super().__init__(name, value) + if not os.path.isfile(self._value): + raise self._validation_exception( + f"Expects an existing file, but '{self.value}' is not a file" + ) + + @property + def value(self) -> str: + """Turn into a Path, then a string, to get correct directory separators""" + return str(Path(self._value)) class StringFormatterFilePathValidator(StringFormatterValidator):