Skip to content

Commit 25677d2

Browse files
committed
Add --input-list option to read input files from a text file
1 parent 13a65d5 commit 25677d2

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

ffmpeg_normalize/__main__.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ def create_parser() -> argparse.ArgumentParser:
5252
)
5353

5454
group_io = parser.add_argument_group("File Input/output")
55-
group_io.add_argument("input", nargs="+", help="Input media file(s)")
55+
group_io.add_argument("input", nargs="*", help="Input media file(s)")
56+
group_io.add_argument(
57+
"--input-list",
58+
type=str,
59+
help="Path to a text file containing a line-separated list of input files",
60+
)
5661
group_io.add_argument(
5762
"-o",
5863
"--output",
@@ -583,7 +588,18 @@ def _split_options(opts: str) -> list[str]:
583588
"Will apply default file naming for the remaining ones."
584589
)
585590

586-
for index, input_file in enumerate(cli_args.input):
591+
# Collect input files from positional args and --input-list
592+
input_files = list(cli_args.input) if cli_args.input else []
593+
if cli_args.input_list:
594+
if not os.path.exists(cli_args.input_list):
595+
error(f"Input list file '{cli_args.input_list}' does not exist")
596+
with open(cli_args.input_list, "r") as f:
597+
input_files.extend([line.strip() for line in f if line.strip()])
598+
599+
if not input_files:
600+
error("No input files specified. Use positional arguments or --input-list.")
601+
602+
for index, input_file in enumerate(input_files):
587603
if cli_args.output is not None and index < len(cli_args.output):
588604
if cli_args.output_folder and cli_args.output_folder != "normalized":
589605
_logger.warning(

tests/test_all.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ def cleanup(self):
147147
if os.path.isdir("normalized"):
148148
shutil.rmtree("normalized")
149149

150+
def test_input_list(self, tmp_path):
151+
# Create a temporary input list file using pytest tmp_path
152+
input_list_path = tmp_path / "input_list.txt"
153+
input_list_path.write_text("tests/test.mp4\ntests/test.mp4\n")
154+
# Run ffmpeg-normalize with --input-list
155+
ffmpeg_normalize_call(["--input-list", str(input_list_path)])
156+
# Check output files
157+
assert os.path.isfile("normalized/test.mkv")
158+
159+
def test_no_input_specified(self):
160+
"""Run the CLI with no arguments; should exit with error"""
161+
_, stderr = ffmpeg_normalize_call([])
162+
assert "No input files specified" in stderr
163+
164+
def test_empty_input_list_file(self, tmp_path):
165+
# Create an empty input list file using pytest tmp_path
166+
input_list_path = tmp_path / "empty_input_list.txt"
167+
input_list_path.write_text("")
168+
_, stderr = ffmpeg_normalize_call(["--input-list", str(input_list_path)])
169+
# Should error because the list is empty
170+
assert "No input files specified" in stderr
171+
150172
def test_output_filename_and_folder(self):
151173
ffmpeg_normalize_call(["tests/test.mp4"])
152174
assert os.path.isfile("normalized/test.mkv")

0 commit comments

Comments
 (0)