Show More
@@ -6,7 +6,27 b' from os.path import exists, isfile, splitext, abspath, join, isdir' | |||||
6 | from os import walk, sep |
|
6 | from os import walk, sep | |
7 |
|
7 | |||
8 |
|
8 | |||
9 |
class |
|
9 | class VideoIframe(object): | |
|
10 | """ | |||
|
11 | Generic class to embed videos in a iframe | |||
|
12 | """ | |||
|
13 | ||||
|
14 | def __init__(self, id, width=400, height=300, **kwargs): | |||
|
15 | self.id = id | |||
|
16 | self.width = width | |||
|
17 | self.height = height | |||
|
18 | self.params = kwargs | |||
|
19 | ||||
|
20 | def _repr_html_(self): | |||
|
21 | """return the embed iframe for this video id""" | |||
|
22 | if self.params: | |||
|
23 | from urllib import urlencode | |||
|
24 | params = "?" + urlencode(self.params) | |||
|
25 | else: | |||
|
26 | params = "" | |||
|
27 | return self.iframe % (self.width, self.height, self.id, params) | |||
|
28 | ||||
|
29 | class YouTubeVideo(VideoIframe): | |||
10 | """Class for embedding a YouTube Video in an IPython session, based on its video id. |
|
30 | """Class for embedding a YouTube Video in an IPython session, based on its video id. | |
11 |
|
31 | |||
12 | e.g. to embed the video on this page: |
|
32 | e.g. to embed the video on this page: | |
@@ -30,20 +50,7 b' class YouTubeVideo(object):' | |||||
30 | https://developers.google.com/youtube/player_parameters#parameter-subheader |
|
50 | https://developers.google.com/youtube/player_parameters#parameter-subheader | |
31 | """ |
|
51 | """ | |
32 |
|
52 | |||
33 | def __init__(self, id, width=400, height=300, **kwargs): |
|
53 | iframe = """ | |
34 | self.id = id |
|
|||
35 | self.width = width |
|
|||
36 | self.height = height |
|
|||
37 | self.params = kwargs |
|
|||
38 |
|
||||
39 | def _repr_html_(self): |
|
|||
40 | """return YouTube embed iframe for this video id""" |
|
|||
41 | if self.params: |
|
|||
42 | from urllib import urlencode # Deferred import |
|
|||
43 | params = "?" + urlencode(self.params) |
|
|||
44 | else: |
|
|||
45 | params = "" |
|
|||
46 | return """ |
|
|||
47 | <iframe |
|
54 | <iframe | |
48 | width="%i" |
|
55 | width="%i" | |
49 | height="%i" |
|
56 | height="%i" | |
@@ -51,7 +58,25 b' class YouTubeVideo(object):' | |||||
51 | frameborder="0" |
|
58 | frameborder="0" | |
52 | allowfullscreen |
|
59 | allowfullscreen | |
53 | ></iframe> |
|
60 | ></iframe> | |
54 | """ % (self.width, self.height, self.id, params) |
|
61 | """ | |
|
62 | ||||
|
63 | class VimeoVideo(VideoIframe): | |||
|
64 | """ | |||
|
65 | Class for embedding a Vimeo video in an IPython session, based on its video id. | |||
|
66 | """ | |||
|
67 | ||||
|
68 | iframe = """ | |||
|
69 | <iframe | |||
|
70 | width = "%i" | |||
|
71 | height = "%i" | |||
|
72 | src="http://player.vimeo.com/video/%s%s" | |||
|
73 | frameborder="0" | |||
|
74 | webkitAllowFullScreen | |||
|
75 | mozallowfullscreen | |||
|
76 | allowFullScreen | |||
|
77 | ></iframe> | |||
|
78 | """ | |||
|
79 | ||||
55 |
|
80 | |||
56 | class FileLink(object): |
|
81 | class FileLink(object): | |
57 | """Class for embedding a local file link in an IPython session, based on path |
|
82 | """Class for embedding a local file link in an IPython session, based on path |
General Comments 0
You need to be logged in to leave comments.
Login now