Permalink
Browse files

Added lib/display.py for extra display related things.

  • Loading branch information...
1 parent a65c2d3 commit c292a9ce434a3e1982ee35537d6defd3926bb0e6 @ellisonbg ellisonbg committed Jul 29, 2011
Showing with 35 additions and 0 deletions.
  1. +35 −0 IPython/lib/display.py
View
@@ -0,0 +1,35 @@
+"""Various display related classes.
+
+Authors : MinRK
+"""
+
+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)
+

0 comments on commit c292a9c

Please sign in to comment.