In [7]: youtube_video_is_blocked("tMhzINs6DjA") Out[7]: (False, None)
In [8]: youtube_video_is_blocked("2VfMafuY6o8") Out[8]: (True, [u'CO'])
import requests | |
def youtube_video_is_blocked(video_id): | |
""" | |
is the video bloked in youtube? | |
:param video_id: like "tMhzINs6DjA" | |
:return: tuple, if blocked: True, list of country codes where video is blocked, else: False, None. | |
""" | |
params = { | |
"part": "contentDetails", | |
"id": video_id, | |
"key": "YOUR_API_KEY" | |
} | |
url = "https://www.googleapis.com/youtube/v3/videos" | |
res = requests.get(url, params=params) | |
items = res.json().get("items") | |
for v in items: | |
if "regionRestriction" in v["contentDetails"]: | |
blocked_in = v["contentDetails"]["regionRestriction"]["blocked"] | |
if len(blocked_in) > 0: | |
return True, blocked_in | |
return False, None |