From 282a2fbac177e62c39b3cd4843d18ada4118ce01 2012-11-02 23:43:03 From: Bradley M. Froehle Date: 2012-11-02 23:43:03 Subject: [PATCH] Merge pull request #2530 from dannystaple/patch-1 YouTubeVideo: Use kwargs to pass video parameters (start time, etc). --- diff --git a/IPython/lib/display.py b/IPython/lib/display.py index b25ef56..e023593 100644 --- a/IPython/lib/display.py +++ b/IPython/lib/display.py @@ -1,7 +1,8 @@ """Various display related classes. -Authors : MinRK +Authors : MinRK, dannystaple """ +import urllib class YouTubeVideo(object): """Class for embedding a YouTube Video in an IPython session, based on its video id. @@ -14,22 +15,37 @@ class YouTubeVideo(object): vid = YouTubeVideo("foo") display(vid) + + To start from 30 seconds: + + vid = YouTubeVideo("abc", start=30) + display(vid) + + To calculate seconds from time as hours, minutes, seconds use: + start=int(timedelta(hours=1, minutes=46, seconds=40).total_seconds()) + + Other parameters can be provided as documented at + https://developers.google.com/youtube/player_parameters#parameter-subheader """ - def __init__(self, id, width=400, height=300): + def __init__(self, id, width=400, height=300, **kwargs): self.id = id self.width = width self.height = height + self.params = kwargs def _repr_html_(self): """return YouTube embed iframe for this video id""" + if self.params: + params = "?" + urllib.urlencode(self.params) + else: + params = "" return """ - """%(self.width, self.height, self.id) - + """ % (self.width, self.height, self.id, params)