Last active
May 19, 2016 17:59
-
-
Save ryonsherman/4079966 to your computer and use it in GitHub Desktop.
Parse Youtube URL, extract video ID, and provide embed iframe.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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