Skip to content

Instantly share code, notes, and snippets.

@silentsokolov
silentsokolov / get_youtube_id.py
Last active November 9, 2023 22:16
Python: get youtube id
# Get youtube id
#http://youtu.be/5Y6HSHwhVlY
#http://www.youtube.com/embed/5Y6HSHwhVlY?rel=0
#http://www.youtube.com/watch?v=ZFqlHhCNBOI
regex = re.compile(r'(https?://)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)/(watch\?v=|embed/|v/|.+\?v=)?(?P<id>[A-Za-z0-9\-=_]{11})')
match = regex.match(self.youtube_url)