Show More
@@ -252,12 +252,26 b' class YouTubeVideo(IFrame):' | |||||
252 |
|
252 | |||
253 | Other parameters can be provided as documented at |
|
253 | Other parameters can be provided as documented at | |
254 | https://developers.google.com/youtube/player_parameters#parameter-subheader |
|
254 | https://developers.google.com/youtube/player_parameters#parameter-subheader | |
|
255 | ||||
|
256 | When converting the notebook using nbconvert, a jpeg representation of the video | |||
|
257 | will be inserted in the document. | |||
255 | """ |
|
258 | """ | |
256 |
|
259 | |||
257 | def __init__(self, id, width=400, height=300, **kwargs): |
|
260 | def __init__(self, id, width=400, height=300, **kwargs): | |
|
261 | self.id=id | |||
258 | src = "https://www.youtube.com/embed/{0}".format(id) |
|
262 | src = "https://www.youtube.com/embed/{0}".format(id) | |
259 | super(YouTubeVideo, self).__init__(src, width, height, **kwargs) |
|
263 | super(YouTubeVideo, self).__init__(src, width, height, **kwargs) | |
260 |
|
264 | |||
|
265 | def _repr_jpeg_(self): | |||
|
266 | try: | |||
|
267 | from urllib.request import urlopen # Py3 | |||
|
268 | except ImportError: | |||
|
269 | from urllib2 import urlopen | |||
|
270 | try: | |||
|
271 | return urlopen("https://img.youtube.com/vi/{id}/hqdefault.jpg".format(id=self.id)).read() | |||
|
272 | except IOError: | |||
|
273 | return None | |||
|
274 | ||||
261 | class VimeoVideo(IFrame): |
|
275 | class VimeoVideo(IFrame): | |
262 | """ |
|
276 | """ | |
263 | Class for embedding a Vimeo video in an IPython session, based on its video id. |
|
277 | Class for embedding a Vimeo video in an IPython session, based on its video id. |
General Comments 0
You need to be logged in to leave comments.
Login now