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): ...@@ -32,6 +32,7 @@ class VideoModule(XModule):
self.position = 0 self.position = 0
self.show_captions = xmltree.get('show_captions', 'true') self.show_captions = xmltree.get('show_captions', 'true')
self.source = self._get_source(xmltree) self.source = self._get_source(xmltree)
self.track = self._get_track(xmltree)
if instance_state is not None: if instance_state is not None:
state = json.loads(instance_state) state = json.loads(instance_state)
...@@ -40,13 +41,25 @@ class VideoModule(XModule): ...@@ -40,13 +41,25 @@ class VideoModule(XModule):
def _get_source(self, xmltree): def _get_source(self, xmltree):
# find the first valid source # find the first valid source
source = None return self._get_first_external(xmltree, 'source')
for element in xmltree.findall('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') src = element.get('src')
if src: if src:
source = src result = src
break break
return source return result
def handle_ajax(self, dispatch, get): def handle_ajax(self, dispatch, get):
''' '''
...@@ -85,6 +98,7 @@ class VideoModule(XModule): ...@@ -85,6 +98,7 @@ class VideoModule(XModule):
'id': self.location.html_id(), 'id': self.location.html_id(),
'position': self.position, 'position': self.position,
'source': self.source, 'source': self.source,
'track' : self.track,
'display_name': self.display_name, 'display_name': self.display_name,
# TODO (cpennington): This won't work when we move to data that isn't on the filesystem # TODO (cpennington): This won't work when we move to data that isn't on the filesystem
'data_dir': self.metadata['data_dir'], 'data_dir': self.metadata['data_dir'],
......
...@@ -18,3 +18,9 @@ ...@@ -18,3 +18,9 @@
<p>Download video <a href="${source}">here</a>.</p> <p>Download video <a href="${source}">here</a>.</p>
</div> </div>
% endif % 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