Show More
@@ -1,51 +1,51 b'' | |||||
1 | """Various display related classes. |
|
1 | """Various display related classes. | |
2 |
|
2 | |||
3 | Authors : MinRK, dannystaple |
|
3 | Authors : MinRK, dannystaple | |
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: |
|
24 | To calculate seconds from time as hours, minutes, seconds use: | |
25 | start=int(timedelta(hours=1, minutes=46, seconds=40).total_seconds()) |
|
25 | start=int(timedelta(hours=1, minutes=46, seconds=40).total_seconds()) | |
26 |
|
26 | |||
27 | Other parameters can be provided as documented at |
|
27 | Other parameters can be provided as documented at | |
28 | https://developers.google.com/youtube/player_parameters#parameter-subheader |
|
28 | https://developers.google.com/youtube/player_parameters#parameter-subheader | |
29 | """ |
|
29 | """ | |
30 |
|
30 | |||
31 | def __init__(self, id, width=400, height=300, **kwargs): |
|
31 | def __init__(self, id, width=400, height=300, **kwargs): | |
32 | self.id = id |
|
32 | self.id = id | |
33 | self.width = width |
|
33 | self.width = width | |
34 | self.height = height |
|
34 | self.height = height | |
35 | self.params = kwargs |
|
35 | self.params = kwargs | |
36 |
|
36 | |||
37 | def _repr_html_(self): |
|
37 | def _repr_html_(self): | |
38 | """return YouTube embed iframe for this video id""" |
|
38 | """return YouTube embed iframe for this video id""" | |
39 | if self.params: |
|
39 | if self.params: | |
40 | params = "?" + urllib.urlencode(self.params) |
|
40 | params = "?" + urllib.urlencode(self.params) | |
41 | else: |
|
41 | else: | |
42 | params = "" |
|
42 | params = "" | |
43 | return """ |
|
43 | return """ | |
44 | <iframe |
|
44 | <iframe | |
45 | width="%i" |
|
45 | width="%i" | |
46 | height="%i" |
|
46 | height="%i" | |
47 | src="http://www.youtube.com/embed/%s%s" |
|
47 | src="http://www.youtube.com/embed/%s%s" | |
48 | frameborder="0" |
|
48 | frameborder="0" | |
49 | allowfullscreen |
|
49 | allowfullscreen | |
50 | ></iframe> |
|
50 | ></iframe> | |
51 | """%(self.width, self.height, self.id, params) No newline at end of file |
|
51 | """ % (self.width, self.height, self.id, params) |
General Comments 0
You need to be logged in to leave comments.
Login now