Skip to content

Commit

Permalink
[DOCS] More verbose error when ffmpeg/ffprobe not found (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbannon authored Mar 2, 2023
1 parent 76c0097 commit 265dae1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/ytdl_sub/config/config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

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.file_path_validators import FFmpegFileValidator
from ytdl_sub.validators.file_path_validators import FFprobeFileValidator
from ytdl_sub.validators.strict_dict_validator import StrictDictValidator
from ytdl_sub.validators.validators import LiteralDictValidator
from ytdl_sub.validators.validators import StringValidator
Expand Down Expand Up @@ -41,10 +42,10 @@ def __init__(self, name: str, value: Any):
key="lock_directory", validator=StringValidator, default=_DEFAULT_LOCK_DIRECTORY
)
self._ffmpeg_path = self._validate_key(
key="ffmpeg_path", validator=ExistingFileValidator, default=_DEFAULT_FFMPEG_PATH
key="ffmpeg_path", validator=FFmpegFileValidator, default=_DEFAULT_FFMPEG_PATH
)
self._ffprobe_path = self._validate_key(
key="ffprobe_path", validator=ExistingFileValidator, default=_DEFAULT_FFPROBE_PATH
key="ffprobe_path", validator=FFprobeFileValidator, default=_DEFAULT_FFPROBE_PATH
)

@property
Expand Down
15 changes: 11 additions & 4 deletions src/ytdl_sub/validators/file_path_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
from ytdl_sub.validators.validators import StringValidator


class ExistingFileValidator(StringValidator):
_expected_value_type_name = "file"
class FFmpegFileValidator(StringValidator):
_expected_value_type_name = "ffmpeg dependency"
_ffmpeg_dependency = "ffmpeg"

def __init__(self, name: str, value: Any):
super().__init__(name, value)
if not os.path.isfile(self._value):
if not os.path.isfile(self.value):
raise self._validation_exception(
f"Expects an existing file, but '{self.value}' is not a file"
f"Expects an {self._ffmpeg_dependency} executable at '{self.value}', but "
f"does not exist. See https://github.com/jmbannon/ytdl-sub#installation on how "
f"to install ffmpeg dependencies."
)

@property
Expand All @@ -24,6 +27,10 @@ def value(self) -> str:
return str(Path(self._value))


class FFprobeFileValidator(FFmpegFileValidator):
_ffmpeg_dependency = "ffprobe"


class StringFormatterFilePathValidator(StringFormatterValidator):
_expected_value_type_name = "filepath"

Expand Down
2 changes: 1 addition & 1 deletion src/ytdl_sub/validators/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _validate_key(
if key not in self._dict and default is None:
raise self._validation_exception(f"{key} is missing when it should be present.")

validator_name = f"{self._name}.{key}"
validator_name = f"{self._name}.{key}" if self._name else key
validator_instance = validator(
name=validator_name,
value=self._dict.get(key, default),
Expand Down

0 comments on commit 265dae1

Please sign in to comment.