Skip to content

Instantly share code, notes, and snippets.

@minrk
Created July 29, 2011 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save minrk/1114390 to your computer and use it in GitHub Desktop.
Save minrk/1114390 to your computer and use it in GitHub Desktop.
from IPython.core.display import display
class YouTubeVideo(object):
"""Class for embedding a YouTube Video in an IPython session, based on its video id.
e.g. to embed the video on this page:
http://www.youtube.com/watch?v=foo
you would do:
vid = YouTubeVideo("foo")
display(vid)
"""
def __init__(self, id, width=400, height=300):
self.id = id
self.width = width
self.height = height
def _repr_html_(self):
"""return YouTube embed iframe for this video id"""
return """
<iframe
width="%i"
height="%i"
src="http://www.youtube.com/embed/%s"
frameborder="0"
allowfullscreen
></iframe>
"""%(self.width, self.height, self.id)
vid = YouTubeVideo("dQw4w9WgXcQ")
display(vid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment