Skip to content

Instantly share code, notes, and snippets.

@ryonsherman
Last active May 19, 2016 17:59
Show Gist options
  • Save ryonsherman/4079966 to your computer and use it in GitHub Desktop.
Save ryonsherman/4079966 to your computer and use it in GitHub Desktop.
Parse Youtube URL, extract video ID, and provide embed iframe.
from urlparse import urlparse, parse_qs
url = urlparse('https://www.youtube.com/watch?v=XXXXXXXXXXX')
if 'youtube' in url.netloc.lower():
video_id = parse_qs(url.query).get('v', [False])[0]
if video_id:
print '<iframe width="560" height="315" src="http://www.youtube.com/embed/{0}" frameborder="0" allowfullscreen></iframe>'.format(video_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment