Commit f357e90d by Carlos Andrés Rocha

Add support for video download link

Add a download link to the video player. The link is defined in the
content xml using the following structure:

<video youtube="youtubestring">
  <source src="video_link"/>
</video>
parent 67fb486f
...@@ -31,12 +31,23 @@ class VideoModule(XModule): ...@@ -31,12 +31,23 @@ class VideoModule(XModule):
self.youtube = xmltree.get('youtube') self.youtube = xmltree.get('youtube')
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)
if instance_state is not None: if instance_state is not None:
state = json.loads(instance_state) state = json.loads(instance_state)
if 'position' in state: if 'position' in state:
self.position = int(float(state['position'])) self.position = int(float(state['position']))
def _get_source(self, xmltree):
# find the first valid source
source = None
for element in xmltree.findall('source'):
src = element.get('src')
if src:
source = src
break
return source
def handle_ajax(self, dispatch, get): def handle_ajax(self, dispatch, get):
''' '''
Handle ajax calls to this video. Handle ajax calls to this video.
...@@ -73,6 +84,7 @@ class VideoModule(XModule): ...@@ -73,6 +84,7 @@ class VideoModule(XModule):
'streams': self.video_list(), 'streams': self.video_list(),
'id': self.location.html_id(), 'id': self.location.html_id(),
'position': self.position, 'position': self.position,
'source': self.source,
'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'],
...@@ -82,6 +94,5 @@ class VideoModule(XModule): ...@@ -82,6 +94,5 @@ class VideoModule(XModule):
class VideoDescriptor(RawDescriptor): class VideoDescriptor(RawDescriptor):
module_class = VideoModule module_class = VideoModule
stores_state = True stores_state = True
template_dir_name = "video" template_dir_name = "video"
...@@ -13,3 +13,8 @@ ...@@ -13,3 +13,8 @@
</article> </article>
</div> </div>
</div> </div>
% if source:
<div class="video-sources">
<p>Download video <a href="${source}">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