Fix #29: validate --container against known containers

Before this fix, passing an invalid container name (e.g., 'nonexistent')
was passed directly to FFmpeg, which would fail with a cryptic error.
Now the container name is validated against CONTAINER_NAMES before any
processing begins, and a clear error message listing valid containers
is shown.
This commit was merged in pull request #30.
This commit is contained in:
2026-09-02 15:41:38 +05:00
parent 25e8c0293e
commit 8b67de59a3
+7
View File
@@ -32,6 +32,7 @@ from .defaults import (
DEFAULT_SKIP_EXISTING, DEFAULT_SKIP_EXISTING,
DEFAULT_DELETE_ORIGINAL, DEFAULT_DELETE_ORIGINAL,
) )
from .constants import CONTAINER_NAMES
from .core import split_audio from .core import split_audio
from .tracklist import read_tracklist, parse_format from .tracklist import read_tracklist, parse_format
from .ffmpeg import has_cover_or_video, validate_cover_images from .ffmpeg import has_cover_or_video, validate_cover_images
@@ -196,6 +197,12 @@ def main():
print(f"Error: Tracklist file not found: {args.tracklist_file}") print(f"Error: Tracklist file not found: {args.tracklist_file}")
sys.exit(1) sys.exit(1)
# Validate container if provided
if args.container and args.container not in CONTAINER_NAMES:
print(f"Error: Invalid container '{args.container}'. "
f"Valid containers: {', '.join(sorted(CONTAINER_NAMES))}.")
sys.exit(1)
# Check FFmpeg # Check FFmpeg
try: try:
subprocess.run(['ffmpeg', '-version'], capture_output=True, check=True) subprocess.run(['ffmpeg', '-version'], capture_output=True, check=True)