from pathlib import Path
import requests,json,hashlib,concurrent.futures
P=Path('/opt/creature-lib-20261017');out=P/'sources/animals';out.mkdir(exist_ok=True)
repo='Tekh-ops/Ultimate-Animated-Animals-July-2021'
sha=requests.get(f'https://api.github.com/repos/{repo}/commits/HEAD',timeout=45).json()['sha']
base=f'https://raw.githubusercontent.com/{repo}/{sha}/'
lic=requests.get(base+'License.txt',timeout=45);lic.raise_for_status();assert 'CC0' in lic.text;print(lic.text);(out/'License.txt').write_text(lic.text)
def one(name):
 url=base+'glTF/'+name+'.gltf';r=requests.get(url,timeout=90);r.raise_for_status();g=r.json();p=out/(name+'.gltf');p.write_bytes(r.content)
 print(name,[a['name'] for a in g['animations']],sum(g['accessors'][pr['indices']]['count']//3 for m in g['meshes'] for pr in m['primitives']),flush=True)
 return {'path':str(p.relative_to(P)),'url':url,'author':'Quaternius','licence':'CC0-1.0','pack_url':'https://quaternius.com/packs/ultimateanimatedanimals.html','sha256':hashlib.sha256(r.content).hexdigest()}
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as ex:rs=list(ex.map(one,['Wolf','Fox','Husky','Deer','Stag','Horse','Bull','Cow','Alpaca','Donkey']))
r=json.loads((P/'evidence/sources.json').read_text());r=[x for x in r if 'failed' not in x];r.extend(rs);(P/'evidence/sources.json').write_text(json.dumps(r,indent=2))
# Discard only this task's failed HTML downloads.
for p in out.glob('Binary *.gltf'):
 if p.read_bytes().startswith(b'<!DOCTYPE html>'):p.unlink()
