A:增加任务进度展示
This commit is contained in:
1 parent
0c55ebd747
commit
ff67b40090
1 file changed
+28
-2
+28
-2
@@ -15,6 +15,7 @@ import argparse
|
||||
import subprocess
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
@@ -158,6 +159,17 @@ def _parse_number_total(number_value: str | None, total_value: str | None) -> tu
|
||||
return number, (total or 0)
|
||||
|
||||
|
||||
def _format_duration(seconds: float | None) -> str:
|
||||
if seconds is None or seconds < 0:
|
||||
return "--:--"
|
||||
total = int(seconds + 0.5)
|
||||
mins, secs = divmod(total, 60)
|
||||
hours, mins = divmod(mins, 60)
|
||||
if hours:
|
||||
return f"{hours:d}:{mins:02d}:{secs:02d}"
|
||||
return f"{mins:02d}:{secs:02d}"
|
||||
|
||||
|
||||
def _mp4_freeform_values(values: list[str]) -> list:
|
||||
if not values:
|
||||
return []
|
||||
@@ -428,6 +440,10 @@ def main():
|
||||
|
||||
max_workers = max(1, os.cpu_count() / 2 or 4)
|
||||
successes = 0
|
||||
failures = 0
|
||||
completed = 0
|
||||
total_targets = len(tasks)
|
||||
start_time = time.monotonic()
|
||||
|
||||
print(f"Using ffmpeg at: {FFMPEG_BIN}")
|
||||
if not HAS_MUTAGEN:
|
||||
@@ -457,11 +473,21 @@ def main():
|
||||
for future in as_completed(future_map):
|
||||
src, dst = future_map[future]
|
||||
ok = future.result()
|
||||
completed += 1
|
||||
if ok:
|
||||
successes += 1
|
||||
print(f"[OK ] {src} -> {dst}")
|
||||
status = "[OK ]"
|
||||
else:
|
||||
print(f"[FAIL] {src} -> {dst}")
|
||||
failures += 1
|
||||
status = "[FAIL]"
|
||||
|
||||
elapsed = time.monotonic() - start_time
|
||||
rate = (completed / elapsed) if elapsed > 0 else 0.0
|
||||
remaining = total_targets - completed
|
||||
eta = (remaining / rate) if rate > 0 else None
|
||||
pct = (completed / total_targets * 100.0) if total_targets else 100.0
|
||||
progress = f"[{completed}/{total_targets} {pct:5.1f}% ETA {_format_duration(eta)}]"
|
||||
print(f"{progress} {status} {src} -> {dst}", flush=True)
|
||||
|
||||
print(f"\nDone. {successes}/{len(tasks)} target(s) written from {len(files)} source file(s).")
|
||||
|
||||
|
||||
Reference in new issue
Block a user