Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455#!/usr/bin/env python3"""Download every film in manifest.json from archive.org into raw/.
Idempotent: a file whose size matches the archive.org metadata is skipped,partial downloads resume (curl -C -). Run from the repo root."""import json, pathlib, subprocess, sys, urllib.parse, urllib.request
ROOT = pathlib.Path(__file__).resolve().parent.parentRAW = ROOT / "raw"RAW.mkdir(exist_ok=True)
def expected_size(identifier, filename): url = f"https://archive.org/metadata/{identifier}" with urllib.request.urlopen(url, timeout=30) as r: meta = json.load(r) for f in meta.get("files", []): if f.get("name") == filename: return int(f.get("size", 0) or 0) return 0
def main(): films = json.loads((ROOT / "manifest.json").read_text())["films"] failures = [] for i, film in enumerate(films, 1): ident, fname = film["identifier"], film["file"] ext = pathlib.Path(fname).suffix or ".mp4" safe_title = film["title"].replace("/", "-").replace(":", " -") dest = RAW / f"{safe_title} ({film['year']}){ext}" try: want = expected_size(ident, fname) except Exception as e: print(f"[{i}/{len(films)}] METADATA FAIL {film['title']}: {e}", flush=True) failures.append(film["title"]) continue if dest.exists() and want and dest.stat().st_size == want: print(f"[{i}/{len(films)}] ok {dest.name}", flush=True) continue url = f"https://archive.org/download/{ident}/{urllib.parse.quote(fname)}" print(f"[{i}/{len(films)}] fetching {dest.name} ({want // (1 << 20)} MB)", flush=True) rc = subprocess.run([ "curl", "-L", "-C", "-", "--retry", "8", "--retry-all-errors", "--fail", "-sS", "-o", str(dest), url, ]).returncode if rc != 0 or (want and dest.exists() and dest.stat().st_size != want): print(f" FAILED (rc={rc})", flush=True) failures.append(film["title"]) if failures: print(f"\n{len(failures)} failures: {failures}", flush=True) sys.exit(1) print("\nAll films downloaded.", flush=True)
if __name__ == "__main__": main()