diff --git a/common/lib/xmodule/xmodule/videoalpha_module.py b/common/lib/xmodule/xmodule/videoalpha_module.py index 7ec63f6015..9c6b870676 100644 --- a/common/lib/xmodule/xmodule/videoalpha_module.py +++ b/common/lib/xmodule/xmodule/videoalpha_module.py @@ -42,10 +42,13 @@ class VideoAlphaModule(XModule): self.youtube = xmltree.get('youtube') self.position = 0 self.show_captions = xmltree.get('show_captions', 'true') - self.source = self._get_source(xmltree) - self.mp4_source = self._get_source(xmltree, ['mp4']) - self.webm_source = self._get_source(xmltree, ['webm']) - self.ogv_source = self._get_source(xmltree, ['ogv']) + self.source, _ = self._get_source(xmltree) + self.mp4_source, self.mp4_element = self._get_source(xmltree, ['mp4']) + self.webm_source, self.webm_element = self._get_source(xmltree, ['webm']) + self.ogv_source, self.ogv_element = self._get_source(xmltree, ['ogv']) + self.mp4_sub = self.mp4_element.get('sub') if self.mp4_element else None + self.webm_sub = self.webm_element.get('sub') if self.webm_element else None + self.ogv_sub = self.ogv_element.get('sub') if self.ogv_element else None self.track = self._get_track(xmltree) self.start_time, self.end_time = self._get_timeframe(xmltree) @@ -58,21 +61,23 @@ class VideoAlphaModule(XModule): """Find the first valid source, which ends with one of `extensions`.""" condition = lambda src: any([src.endswith(ext) for ext in extensions]) - return self._get_first_external(xmltree, 'source', condition) + return self._get_first_external(xmltree, 'source', condition, True) def _get_track(self, xmltree): # find the first valid track return self._get_first_external(xmltree, 'track') - def _get_first_external(self, xmltree, tag, condition=bool): + def _get_first_external(self, xmltree, tag, condition=bool, + return_element=False): """Will return the first 'valid' element of the given tag. 'valid' means that `condition('src' attribute) == True` """ - result = None + result = (None, None) if return_element else None + for element in xmltree.findall(tag): src = element.get('src') if condition(src): - result = src + result = (src, element) if return_element else src break return result @@ -139,6 +144,9 @@ class VideoAlphaModule(XModule): 'mp4_source': self.mp4_source, 'webm_source': self.webm_source, 'ogv_source': self.ogv_source, + 'mp4_sub': self.mp4_sub, + 'webm_sub': self.webm_sub, + 'ogv_sub': self.ogv_sub, 'source': self.source, 'track': self.track, 'display_name': self.display_name, diff --git a/lms/templates/videoalpha.html b/lms/templates/videoalpha.html index 18c8135823..fc15622e9f 100644 --- a/lms/templates/videoalpha.html +++ b/lms/templates/videoalpha.html @@ -12,6 +12,9 @@ ${'data-mp4-source="{}"'.format(mp4_source) if mp4_source else ''} ${'data-webm-source="{}"'.format(webm_source) if webm_source else ''} ${'data-ogg-source="{}"'.format(ogv_source) if ogv_source else ''} + ${'data-mp4-sub="{}"'.format(mp4_sub) if mp4_sub else ''} + ${'data-webm-sub="{}"'.format(webm_sub) if webm_sub else ''} + ${'data-ogg-sub="{}"'.format(ogv_sub) if ogv_sub else ''} data-caption-data-dir="${data_dir}" data-show-captions="${show_captions}" data-start="${start}"