Show More
@@ -2,7 +2,7 b'' | |||
|
2 | 2 | |
|
3 | 3 | Authors : MinRK |
|
4 | 4 | """ |
|
5 | from datetime import timedelta | |
|
5 | import urllib | |
|
6 | 6 | |
|
7 | 7 | class YouTubeVideo(object): |
|
8 | 8 | """Class for embedding a YouTube Video in an IPython session, based on its video id. |
@@ -16,27 +16,34 b' class YouTubeVideo(object):' | |||
|
16 | 16 | vid = YouTubeVideo("foo") |
|
17 | 17 | display(vid) |
|
18 | 18 | |
|
19 |
To start from |
|
|
19 | To start from 30 seconds: | |
|
20 | 20 | |
|
21 |
vid = YouTubeVideo("abc", start= |
|
|
21 | vid = YouTubeVideo("abc", start=30) | |
|
22 | 22 | display(vid) |
|
23 | ||
|
24 | Other parameters can be provided as documented at | |
|
25 | https://developers.google.com/youtube/player_parameters#parameter-subheader | |
|
23 | 26 | """ |
|
24 | 27 | |
|
25 |
def __init__(self, id, width=400, height=300, |
|
|
28 | def __init__(self, id, width=400, height=300, **kwargs): | |
|
26 | 29 | self.id = id |
|
27 | 30 | self.width = width |
|
28 | 31 | self.height = height |
|
29 | self.start = start.total_seconds() | |
|
32 | self.params = **kwargs | |
|
30 | 33 | |
|
31 | 34 | def _repr_html_(self): |
|
32 | 35 | """return YouTube embed iframe for this video id""" |
|
36 | if self.params: | |
|
37 | params = "?" + urllib.urlencode(self.params) | |
|
38 | else: | |
|
39 | params = "" | |
|
33 | 40 | return """ |
|
34 | 41 | <iframe |
|
35 | 42 | width="%i" |
|
36 | 43 | height="%i" |
|
37 |
src="http://www.youtube.com/embed/%s |
|
|
44 | src="http://www.youtube.com/embed/%s%s" | |
|
38 | 45 | frameborder="0" |
|
39 | 46 | allowfullscreen |
|
40 | 47 | ></iframe> |
|
41 | """%(self.width, self.height, self.id, self.start) | |
|
48 | """%(self.width, self.height, self.id, self.start, params) | |
|
42 | 49 |
General Comments 0
You need to be logged in to leave comments.
Login now