import json,subprocess,time,pandas as pd,datetime as dt Y='/workspace/yt-venv/bin/yt-dlp'; E=json.load(open('data/streams_flat.json'))['entries']; rows=[] IST=dt.timezone(dt.timedelta(hours=5,minutes=30)) for i,e in enumerate(E): vid=e['id']; r=subprocess.run([Y,'--skip-download','-J',f'https://www.youtube.com/watch?v={vid}'],capture_output=True,text=True) if r.returncode: rows.append(dict(id=vid,title=e.get('title'),error=r.stderr.strip().splitlines()[-1][:300])); print(i,vid,'ERR',rows[-1]['error'],flush=True); else: d=json.loads(r.stdout); rs=d.get('release_timestamp'); ts=d.get('timestamp') ac=d.get('automatic_captions') or {} rows.append(dict(id=vid,title=d.get('title'),url=f'https://www.youtube.com/watch?v={vid}',start_utc=dt.datetime.fromtimestamp(rs,dt.timezone.utc).isoformat() if rs else None,start_ist=dt.datetime.fromtimestamp(rs,IST).isoformat() if rs else None,end_ist_est=dt.datetime.fromtimestamp(rs+d['duration'],IST).isoformat() if rs and d.get('duration') else None,upload_ts_ist=dt.datetime.fromtimestamp(ts,IST).isoformat() if ts else None,duration_s=d.get('duration'),live_status=d.get('live_status'),has_hi_auto=('hi' in ac) or ('hi-orig' in ac),auto_orig=[k for k in ac if k.endswith('-orig')],has_live_chat='live_chat' in (d.get('subtitles') or {}),view_count=d.get('view_count'))) print(i,vid,rows[-1]['start_ist'],rows[-1]['duration_s'],rows[-1]['auto_orig'],flush=True) time.sleep(1.5) pd.DataFrame(rows).to_csv('results/stream_inventory_raw.csv',index=False); print('done',len(rows))