"""Fetch library files the local meta folder never downloaded. The AstralRinth install has the 1.12.2 java libraries but not the natives-windows classifiers, and the client cannot open a window without lwjgl.dll. Rather than write into another application's cache, missing files go into our own mirror of the same layout, which stage_run.py searches first. python fetch_missing.py """ import json import os import sys import urllib.request def wanted(manifest): """Every artifact and natives-windows path the manifest declares.""" out = [] for entry in manifest['libraries']: downloads = entry.get('downloads') or {} artifact = (downloads.get('artifact') or {}).get('path') if artifact: out.append(artifact) classifiers = downloads.get('classifiers') or {} for key, value in classifiers.items(): if key.startswith('natives-windows') and value and value.get('path'): out.append(value['path']) return sorted(set(out)) def main(): dest_root, meta = sys.argv[1], sys.argv[2] manifest_path = os.path.join(meta, 'versions', '1.12.2', '1.12.2.json') with open(manifest_path, encoding='utf-8') as handle: manifest = json.load(handle) meta_lib = os.path.join(meta, 'libraries') base = 'https://libraries.minecraft.net/' fetched, present, failed = [], 0, [] for rel in wanted(manifest): if os.path.isfile(os.path.join(meta_lib, rel.replace('/', os.sep))): present += 1 continue target = os.path.join(dest_root, rel.replace('/', os.sep)) url = base + rel try: os.makedirs(os.path.dirname(target), exist_ok=True) with urllib.request.urlopen(url, timeout=60) as response: blob = response.read() with open(target, 'wb') as handle: handle.write(blob) fetched.append('%s (%d bytes)' % (os.path.basename(rel), len(blob))) except Exception as error: # noqa: BLE001 failed.append('%s -> %s' % (rel, error)) print('already present: %d' % present) print('fetched: %d' % len(fetched)) for line in fetched: print(' %s' % line) if failed: print('failed: %d' % len(failed)) for line in failed: print(' %s' % line) return 1 if failed else 0 if __name__ == '__main__': raise SystemExit(main())