Commit 25d48209 by Carlos Andrés Rocha

Merge pull request #955 from MITx/louis/srt_downloads

Add support for subtitle download link
parents 27cffb93 b1cfee45
......@@ -32,6 +32,7 @@ class VideoModule(XModule):
self.position = 0
self.show_captions = xmltree.get('show_captions', 'true')
self.source = self._get_source(xmltree)
self.track = self._get_track(xmltree)
if instance_state is not None:
state = json.loads(instance_state)
......@@ -40,13 +41,25 @@ class VideoModule(XModule):
def _get_source(self, xmltree):
# find the first valid source
source = None
for element in xmltree.findall('source'):
return self._get_first_external(xmltree, 'source')
def _get_track(self, xmltree):
# find the first valid track
return self._get_first_external(xmltree, 'track')
def _get_first_external(self, xmltree, tag):
"""
Will return the first valid element
of the given tag.
'valid' means has a non-empty 'src' attribute
"""
result = None
for element in xmltree.findall(tag):
src = element.get('src')
if src:
source = src
result = src
break
return source
return result
def handle_ajax(self, dispatch, get):
'''
......@@ -85,6 +98,7 @@ class VideoModule(XModule):
'id': self.location.html_id(),
'position': self.position,
'source': self.source,
'track' : self.track,
'display_name': self.display_name,
# TODO (cpennington): This won't work when we move to data that isn't on the filesystem
'data_dir': self.metadata['data_dir'],
......
......@@ -18,3 +18,9 @@
<p>Download video <a href="${source}">here</a>.</p>
</div>
% endif
% if track:
<div class="video-tracks">
<p>Download subtitles <a href="${track}">here</a>.</p>
</div>
% endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment