import tomllib, hashlib, os, glob, shutil, urllib.request, concurrent.futures as cf P="/home/logan/Development/onion-mc/mods" srcs=[os.path.expanduser("~/.local/share/PrismLauncher/instances/Onion MC/minecraft/mods"),"/tmp/fd/jars"] def h(p): return hashlib.new def one(f): t=tomllib.load(open(f,"rb")); fn=t["filename"]; d=t["download"]; out=f"jars/{fn}" def ok(p): hh=hashlib.new(d["hash-format"]); hh.update(open(p,"rb").read()); return hh.hexdigest()==d["hash"] if os.path.exists(out) and ok(out): return fn,"cached" for s in srcs: p=os.path.join(s,fn) if os.path.exists(p) and ok(p): shutil.copy(p,out); return fn,"local" url=d.get("url") if not url: return fn,"NOURL "+str(t.get("update")) req=urllib.request.Request(url.replace(" ","%20"),headers={"User-Agent":"onion-mc-audit"}) open(out,"wb").write(urllib.request.urlopen(req,timeout=120).read()) return fn,"dl" if ok(out) else "BADHASH" with cf.ThreadPoolExecutor(8) as ex: for fn,s in ex.map(one,sorted(glob.glob(P+"/*.pw.toml"))): if s not in("cached","local","dl"): print(s,fn) print(len(os.listdir("jars")))