| 1223 | super(Video, self).__init__(data=data, url=url, filename=filename) |
| 1224 | |
| 1225 | def _repr_html_(self): |
| 1226 | width = height = '' |
| 1227 | if self.width: |
| 1228 | width = ' width="%d"' % self.width |
| 1229 | if self.height: |
| 1230 | height = ' height="%d"' % self.height |
| 1231 | |
| 1232 | # External URLs and potentially local files are not embedded into the |
| 1233 | # notebook output. |
| 1234 | if not self.embed: |
| 1235 | url = self.url if self.url is not None else self.filename |
| 1236 | output = """<video src="{0}" {1} {2} {3}> |
| 1237 | Your browser does not support the <code>video</code> element. |
| 1238 | </video>""".format(url, self.html_attributes, width, height) |
| 1239 | return output |
| 1240 | |
| 1241 | # Embedded videos are base64-encoded. |
| 1242 | mimetype = self.mimetype |
| 1243 | if self.filename is not None: |
| 1244 | if not mimetype: |
| 1245 | mimetype, _ = mimetypes.guess_type(self.filename) |
| 1246 | |
| 1247 | with open(self.filename, 'rb') as f: |
| 1248 | video = f.read() |
| 1249 | else: |
| 1250 | video = self.data |
| 1251 | if isinstance(video, str): |
| 1252 | # unicode input is already b64-encoded |
| 1253 | b64_video = video |
| 1254 | else: |
| 1255 | b64_video = b2a_base64(video, newline=False).decode("ascii").rstrip() |
| 1256 | |
| 1257 | output = """<video {0} {1} {2}> |
| 1258 | <source src="data:{3};base64,{4}" type="{3}"> |
| 1259 | Your browser does not support the video tag. |
| 1260 | </video>""".format(self.html_attributes, width, height, mimetype, b64_video) |
| 1261 | return output |
| 1262 | |
| 1263 | def reload(self): |
| 1264 | # TODO |