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