import requests,re,html,os,sys
from pathlib import Path
files={
'20261017_165151.mp4':'1FTZD5scA-t4d9A_pZt08we1B0dhlm08N',
'20261019_121805.mp4':'1vHeeezbG3z-LoDmUYkpHivcGMf1Chfo4',
'20261024_144648.mp4':'1jIO5U48lOrCsAL98wG1KFeJx6NVEpfKD',
'20261024_144707.mp4':'1PXIZzhU7f1KW28s-2J_Cwl4UPIhCf7ZG',
'20261024_144951.mp4':'1AtIr6D_I22zZL0ajLDOL9ItgW75eOSge',
'20261024_163840.mp4':'1JDy21U-v53s1jwAQ-VZjbWay_P6vO15K',
'20261026_013647.mp4':'1LC8ZkcBupqACQX170H0wBeiVVI11gTNB',
'20261026_014149.mp4':'14OVbYIh3lH62Z4i-tC2tb2CeGIgEbGAX',
'20261026_015152.mp4':'1HC3WgjepMnlKjx5jU9n0AjXVMwRE2b75',
'20261026_020000.mp4':'16J0tYpvacbmMgNcCTTBgCFGZQqLzgc0X',
}
out=Path('/home/spazio/cosmos-reels/source');out.mkdir(parents=True,exist_ok=True)
s=requests.Session(); headers={'User-Agent':'Mozilla/5.0'}
for name,fid in files.items():
 p=out/name
 if p.exists() and p.stat().st_size>1000000:
  print('SKIP',name,p.stat().st_size,flush=True);continue
 url=f'https://drive.google.com/uc?export=download&id={fid}'
 r=s.get(url,headers=headers,stream=True,timeout=60)
 ct=r.headers.get('content-type','')
 if 'text/html' in ct:
  text=r.text
  form=re.search(r'<form[^>]+action="([^"]+)"[^>]*>(.*?)</form>',text,re.S)
  if not form: raise RuntimeError(f'no confirm form for {name}')
  action=html.unescape(form.group(1)); fields=dict(re.findall(r'name="([^"]+)"\s+value="([^"]*)"',form.group(2)))
  r=s.get(action,params=fields,headers=headers,stream=True,timeout=60)
 r.raise_for_status()
 with open(p,'wb') as f:
  for chunk in r.iter_content(1024*1024):
   if chunk:f.write(chunk)
 print('DONE',name,p.stat().st_size,flush=True)
