If a video is deleted from youtube, its thumbnail is also deleted. So, you can check the HTTP response code for the thumbnail URL to know whether the video exists or has been deleted.
Here is an example to check the status of two youtube videos:
import requests
def check_yt_video_status(id):
"""
This function will check the status of a youtube video.
"""
link = "https://i.ytimg.com/vi/"
picUrl = link + id + "/mqdefault.jpg"
req = requests.head(picUrl)
return req.status_code
if __name__ == "__main__":
vids = ["ZB_cxKau8iQ", "-6OHlIVsWbc"]
for vid in vids:
if check_yt_video_status(vid) == 404:
print("Video {0} has been deleted".format(vid))
else:
print("Video {0} exists".format(vid))
The output of the above code is as follows:
Video ZB_cxKau8iQ exists
Video -6OHlIVsWbc has been deleted