Explorer
/proc/1357821/root/tmp/aa043_p29_r6_public_probe.py
← Zurück ↓ Download
import requests,re,json,datetime
ids=['P_gY0uz2xOo','9LBSIqAIkis','sKfhEQnAT0c','u1hmak0GoDU']
out=[]
for vid in ids:
 u='https://www.youtube.com/watch?v='+vid
 try:
  r=requests.get(u,headers={'User-Agent':'Mozilla/5.0'},timeout=30,allow_redirects=True)
  t=r.text
  title=re.search(r'<title[^>]*>(.*?)</title>',t,re.I|re.S)
  markers={x:(x.lower() in t.lower()) for x in ['playabilityStatus','LOGIN_REQUIRED','UNPLAYABLE','PRIVATE_VIDEO','Video unavailable','This video is unavailable','members-only','age-restricted','Sign in to confirm your age','country']}
  out.append({'youtube_id':vid,'http':r.status_code,'final_url':r.url,'content_length':len(t),'title':re.sub(r'\\s+',' ',title.group(1)).strip() if title else None,'markers':markers,'response_headers':{k:v for k,v in r.headers.items() if k.lower() in ['content-type','content-length','cache-control','x-cache']}})
 except Exception as e: out.append({'youtube_id':vid,'error_class':type(e).__name__})
print(json.dumps({'checked_at_utc':datetime.datetime.now(datetime.timezone.utc).isoformat(),'results':out},ensure_ascii=False))