Skip to content

Commit

Permalink
Add --reverse warning
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniorIsAJitterbug committed Oct 6, 2024
1 parent 9a4e122 commit fda9160
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 73 deletions.
150 changes: 78 additions & 72 deletions src/tbc_video_export/opts/opt_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,78 @@ def validate_opts(
_validate_decoder_opts(state, opts)


def valiate_metadata_file_exists(value: str) -> Path:
"""Return metadata path if it exists."""
if (path := Path(value)).is_file():
return path.absolute()

raise exceptions.FileIOError(f"Metadata file {value} not found.")


def validate_audio_track_opts(value: str) -> AudioTrackOpt:
"""Return AudioTrackOpt from string."""
return AudioTrackOpt(Path(value).absolute())


def validate_audio_track_advanced_opts(value: str) -> AudioTrackOpt:
"""Validate input types for the audio track advanced object."""
try:
data: list[Any] = literal_eval(value)
type_check: set[bool] = set()

if not data:
raise exceptions.FileIOError(
"File path is required for ffmpeg track, see --help for examples."
)

# ensure input are correct types
with suppress(IndexError):
type_check.add(isinstance(data[0], str))
type_check.add(isinstance(data[1], str | None))
type_check.add(isinstance(data[2], str | None))
type_check.add(isinstance(data[3], str | int | None))
type_check.add(isinstance(data[4], str | None))
type_check.add(isinstance(data[5], int | None))
type_check.add(isinstance(data[6], str | None))
type_check.add(isinstance(data[7], int | float | None))

if False in type_check:
raise SyntaxError

# clone input and change file name to absolute path
opts = data.copy()
opts[0] = Path(data[0]).absolute()

return AudioTrackOpt(*opts)
except (SyntaxError, AttributeError) as e:
raise exceptions.InvalidOptsError(
"Invalid FFmpeg audio track opts, check --help for examples."
) from e


def validate_black_levels_opts(value: str) -> tuple[int, int, int] | None:
"""Validate black level opts.
If a single value is provded we return it three times, if 3 values are provides we
return all 3.
"""
try:
if values := value.split(","):
if len(values) == 1:
return (int(values[0]), int(values[0]), int(values[0]))

if len(values) == 3:
return (int(values[0]), int(values[1]), int(values[2]))
except ValueError as e:
raise exceptions.InvalidOptsError(
"Invalid black level opts, check --help for examples."
) from e

raise exceptions.InvalidOptsError(
"Invalid black levels, check --help for examples."
)


def _validate_line_opts(parser: argparse.ArgumentParser, opts: Opts) -> None:
if opts.contains_active_line_opts() and (
opts.vbi or opts.full_vertical or opts.letterbox
Expand Down Expand Up @@ -113,78 +185,6 @@ def _validate_luma_only_opts(parser: argparse.ArgumentParser, opts: Opts) -> Non
)


def valiate_metadata_file_exists(value: str) -> Path:
"""Return metadata path if it exists."""
if (path := Path(value)).is_file():
return path.absolute()

raise exceptions.FileIOError(f"Metadata file {value} not found.")


def validate_audio_track_opts(value: str) -> AudioTrackOpt:
"""Return AudioTrackOpt from string."""
return AudioTrackOpt(Path(value).absolute())


def validate_audio_track_advanced_opts(value: str) -> AudioTrackOpt:
"""Validate input types for the audio track advanced object."""
try:
data: list[Any] = literal_eval(value)
type_check: set[bool] = set()

if not data:
raise exceptions.FileIOError(
"File path is required for ffmpeg track, see --help for examples."
)

# ensure input are correct types
with suppress(IndexError):
type_check.add(isinstance(data[0], str))
type_check.add(isinstance(data[1], str | None))
type_check.add(isinstance(data[2], str | None))
type_check.add(isinstance(data[3], str | int | None))
type_check.add(isinstance(data[4], str | None))
type_check.add(isinstance(data[5], int | None))
type_check.add(isinstance(data[6], str | None))
type_check.add(isinstance(data[7], int | float | None))

if False in type_check:
raise SyntaxError

# clone input and change file name to absolute path
opts = data.copy()
opts[0] = Path(data[0]).absolute()

return AudioTrackOpt(*opts)
except (SyntaxError, AttributeError) as e:
raise exceptions.InvalidOptsError(
"Invalid FFmpeg audio track opts, check --help for examples."
) from e


def validate_black_levels_opts(value: str) -> tuple[int, int, int] | None:
"""Validate black level opts.
If a single value is provded we return it three times, if 3 values are provides we
return all 3.
"""
try:
if values := value.split(","):
if len(values) == 1:
return (int(values[0]), int(values[0]), int(values[0]))

if len(values) == 3:
return (int(values[0]), int(values[1]), int(values[2]))
except ValueError as e:
raise exceptions.InvalidOptsError(
"Invalid black level opts, check --help for examples."
) from e

raise exceptions.InvalidOptsError(
"Invalid black levels, check --help for examples."
)


def _validate_decoder_opts(state: ProgramState, opts: Opts) -> None:
"""Validate chroma-decoder opts."""
if state.export_mode is ExportMode.LUMA_4FSC:
Expand All @@ -210,3 +210,9 @@ def _validate_decoder_opts(state: ProgramState, opts: Opts) -> None:
raise exceptions.InvalidOptsError(
"--simple-pal is only implemented with Transform2D/Transform3D."
)

if opts.reverse and not opts.no_dropout_correct:
raise exceptions.InvalidOptsError(
"arguments --reverse: requires --no-dropout-correct, run dropout "
"correction manually if required"
)
3 changes: 2 additions & 1 deletion src/tbc_video_export/opts/opts_ldtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def add_ldtool_opts(parent: argparse.ArgumentParser) -> None:
"--reverse",
action="store_true",
default=False,
help="Reverse the field order to second/first.\n\n",
help="Reverse the field order to second/first.\n"
"Note: This requires --no-dropout-correct to be set.\n\n",
)

decoder_opts.add_argument(
Expand Down

0 comments on commit fda9160

Please sign in to comment.