feat: 增加扫描进度提示

This commit is contained in:
kim
2026-04-02 19:31:53 +08:00
parent 915386b778
commit ee002eb1a9
2 changed files with 76 additions and 1 deletions
+52
View File
@@ -114,3 +114,55 @@ def test_main_continues_when_single_file_probe_fails(tmp_path: Path) -> None:
"error_message": "moov atom not found",
}
]
def test_main_reports_scan_progress_to_stderr(tmp_path: Path, capsys) -> None:
input_dir = tmp_path / "videos"
input_dir.mkdir()
first_sample = input_dir / "01-first.mp4"
second_sample = input_dir / "02-second.mp4"
first_sample.write_bytes(b"x" * 2048)
second_sample.write_bytes(b"y" * 1024)
output_dir = tmp_path / "output"
def fake_runner(command: list[str]) -> str:
if command[:2] == ["ffprobe", "-version"]:
return "ffprobe version 8.0.1\nbuilt with ...\n"
if command[:2] == ["ffmpeg", "-version"]:
return "ffmpeg version 8.0.1\nbuilt with ...\n"
if command[0] == "ffprobe" and command[-1] in {str(first_sample), str(second_sample)}:
target = Path(command[-1])
return json.dumps(
{
"format": {
"filename": str(target),
"format_name": "mov,mp4,m4a,3gp,3g2,mj2",
"duration": "8.000000",
"bit_rate": "1024000",
"size": str(target.stat().st_size),
},
"streams": [
{
"codec_type": "video",
"codec_name": "h264",
"width": 1280,
"height": 720,
"avg_frame_rate": "25/1",
}
],
}
)
raise AssertionError(f"unexpected command: {command}")
exit_code = main(
[str(input_dir), "--output-dir", str(output_dir)],
command_runner=fake_runner,
)
captured = capsys.readouterr()
assert exit_code == 0
assert "正在递归扫描输入路径" in captured.err
assert "已发现 2 个视频文件" in captured.err
assert "2/2" in captured.err
assert "02-second.mp4" in captured.err