Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

YouTube Videos.list API has drastic delays when called by requests.get

$
0
0
def validate_youtube_video(link:str, sessionid:str) -> Tuple[bool, str]:  # Returns (status, sanitized_link|error_message)  import urllib.parse  res = urllib.parse.urlparse(link)  vidid = None  if res.netloc == 'www.youtube.com' and res.path == '/watch':    queries = res.query.split('&')    for q in queries:      if q.startswith('v='):        vidid = q[2:]  if res.netloc == 'youtu.be':    vidid = res.path[1:]  resp = requests.get(f'https://www.googleapis.com/youtube/v3/videos?id={vidid}&part=snippet,contentDetails,status&key=[REDACTED]').json()  if resp['items'] == []:    return (False, 'Invalid ID')  if resp['items'][0]['snippet']['title'] != f'[REDACTED] {sessionid}' or resp['items'][0]['snippet']['description'] != '':    return (False, 'Invalid title or description')  if resp['items'][0]['status']['privacyStatus'] != 'unlisted':    return (False, 'Privacy status is not unlisted')  return (True, f'https://youtu.be/{vidid}')

This code aims to call the YouTube Videos.list API V3 to check if the video has required title, description and privacy status for anonymity. It takes less than 1 second in my browser (with the API key) but takes more than 4 minutes when called using requests.get. Does anyone know why?


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>