Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485#!/usr/bin/env python3"""Propose archive.org items for each film in manifest.json.
For each film without an identifier, queries archive.org advanced search andprints the top candidates (identifier, title, downloads, item size). A humanreviews the output and fills `identifier` in manifest.json. Films with anidentifier already set are verified to exist and get their best video filechosen into `file`.
Best-file rule: prefer h.264 MP4s, then MKV/OGV/AVI, largest first, ignoringderivative thumbnails/samples. Items under ~50 MB for features are suspect(likely a trailer or low-grade rip) and get flagged."""import json, sys, time, urllib.parse, urllib.request
ROOT = __import__("pathlib").Path(__file__).resolve().parent.parentMANIFEST = ROOT / "manifest.json"
VIDEO_EXT = (".mp4", ".mkv", ".ogv", ".avi", ".m4v", ".mpeg", ".mpg")
def get(url): req = urllib.request.Request(url, headers={"User-Agent": "laughtown-resolver/1.0"}) with urllib.request.urlopen(req, timeout=30) as r: return json.load(r)
def search(query, rows=5): q = urllib.parse.quote(f"({query}) AND mediatype:movies") url = (f"https://archive.org/advancedsearch.php?q={q}" f"&fl[]=identifier&fl[]=title&fl[]=downloads&fl[]=item_size&fl[]=year" f"&sort[]=downloads+desc&rows={rows}&output=json") return get(url)["response"]["docs"]
def best_file(identifier): meta = get(f"https://archive.org/metadata/{identifier}") files = meta.get("files", []) cands = [] for f in files: name = f.get("name", "") low = name.lower() if not low.endswith(VIDEO_EXT): continue if any(x in low for x in ("sample", "trailer", ".thumbs/")): continue size = int(f.get("size", 0) or 0) pref = 0 if low.endswith(".mp4") else 1 cands.append((pref, -size, name, size)) cands.sort() if not cands: return None, 0 _, _, name, size = cands[0] return name, size
def main(): m = json.loads(MANIFEST.read_text()) mode = sys.argv[1] if len(sys.argv) > 1 else "candidates" for film in m["films"]: t = f"{film['title']} ({film['year']})" if mode == "candidates" and not film["identifier"]: print(f"\n## {t} [{film['group']}]") try: for d in search(film["query"]): print(f" {d['identifier']:<45} | {str(d.get('title',''))[:55]:<55} " f"| dl={d.get('downloads',0):>8} | {int(d.get('item_size',0) or 0)//(1<<20):>6} MB") except Exception as e: print(f" SEARCH FAILED: {e}") time.sleep(0.4) elif mode == "files" and film["identifier"]: try: name, size = best_file(film["identifier"]) if not name: print(f"NOFILE {t}: {film['identifier']}") continue film["file"] = name flag = " (!) small" if size < 50_000_000 and "short" not in film["group"] and film["group"] not in ("chaplin-mutual","arbuckle","fields","chase","laurel-hardy") else "" print(f"OK {t}: {film['identifier']} / {name} ({size//(1<<20)} MB){flag}") except Exception as e: print(f"ERROR {t}: {film['identifier']}: {e}") time.sleep(0.3) if mode == "files": MANIFEST.write_text(json.dumps(m, indent=2) + "\n") print("\nmanifest.json updated with chosen files.")
if __name__ == "__main__": main()