Skip to content

Commit

Permalink
[DOCS] Add ffmpeg path docs (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbannon authored Mar 1, 2023
1 parent 196b99c commit 7cfd14e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/ytdl_sub/config/config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions src/ytdl_sub/validators/file_path_validators.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit 7cfd14e

Please sign in to comment.