(redo: bool = False)
| 81 | |
| 82 | |
| 83 | def cmd_download(redo: bool = False) -> int: |
| 84 | pairs = scan_urls() |
| 85 | print(f"扫描到 {len(pairs)} 个 URL") |
| 86 | skipped = 0 |
| 87 | succeeded = 0 |
| 88 | failed: list[tuple[str, str]] = [] |
| 89 | for local, url in pairs: |
| 90 | local.parent.mkdir(parents=True, exist_ok=True) |
| 91 | if local.exists() and not redo: |
| 92 | if detect_image_kind(local): |
| 93 | skipped += 1 |
| 94 | continue |
| 95 | print(f"REDO {local}(旧文件不是合法图片,重新下载)") |
| 96 | ok, info = download_one(url, local) |
| 97 | if not ok: |
| 98 | ok2, info2 = download_one(url, local) |
| 99 | if not ok2: |
| 100 | failed.append((url, f"{info}; retry: {info2}")) |
| 101 | print(f"FAIL {url} -> {info2}", file=sys.stderr) |
| 102 | continue |
| 103 | info = info2 |
| 104 | succeeded += 1 |
| 105 | print(f"OK {url} -> {local} ({info})") |
| 106 | |
| 107 | print(f"\n下载完成:跳过 {skipped},新下载 {succeeded},失败 {len(failed)}") |
| 108 | if failed: |
| 109 | out = Path("_legacy_images/_failed.txt") |
| 110 | out.write_text("\n".join(f"{u} :: {e}" for u, e in failed), encoding="utf-8") |
| 111 | print(f"失败明细已写到 {out}") |
| 112 | return 1 if failed else 0 |
| 113 | |
| 114 | |
| 115 | def cmd_validate() -> int: |
no test coverage detected