Reputation:
I am creating a video downloader software with Python. And I want to check if the Youtube video link that the user entered is a valid Youtube link or not. How do I do that? (I am using Python 3.5)
Upvotes: 5
Views: 7877
Reputation: 27397
def check_video_url(video_id):
checker_url = "https://www.youtube.com/oembed?url=http://www.youtube.com/watch?v="
video_url = checker_url + video_id
request = requests.get(video_url)
return request.status_code == 200
Upvotes: 2
Reputation: 4225
Use requests.get
and check if "Video unavailable" in response
r = requests.get("https://www.youtube.com/watch?v=OpA2ZxnRs6") # random video id
"Video unavailable" in r.text
>>> True
If its False, then the Video ID/Video is valid
Upvotes: 2