From 71f16d40e1fcf275798a0ec2121b149225037213 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Tue, 13 Nov 2012 13:15:30 -0500 Subject: [PATCH 1/3] wire through course asset path information to the video playback module and corresponding .coffee files --- common/lib/xmodule/xmodule/contentstore/content.py | 5 +++++ .../lib/xmodule/xmodule/js/src/video/display.coffee | 1 + .../js/src/video/display/video_caption.coffee | 5 ++++- .../js/src/video/display/video_player.coffee | 1 + .../lib/xmodule/xmodule/modulestore/xml_importer.py | 13 +++++++++---- common/lib/xmodule/xmodule/video_module.py | 8 ++++++++ lms/templates/video.html | 2 +- 7 files changed, 29 insertions(+), 6 deletions(-) diff --git a/common/lib/xmodule/xmodule/contentstore/content.py b/common/lib/xmodule/xmodule/contentstore/content.py index a7a76fa242..9badd4b892 100644 --- a/common/lib/xmodule/xmodule/contentstore/content.py +++ b/common/lib/xmodule/xmodule/contentstore/content.py @@ -46,6 +46,11 @@ class StaticContent(object): else: return None + @staticmethod + def get_base_url_path_for_course_assets(loc): + if loc is not None: + return "/c4x/{org}/{course}/asset".format(**loc.dict()) + @staticmethod def get_id_from_location(location): return { 'tag':location.tag, 'org' : location.org, 'course' : location.course, diff --git a/common/lib/xmodule/xmodule/js/src/video/display.coffee b/common/lib/xmodule/xmodule/js/src/video/display.coffee index d6c582d6fa..bb87679d37 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display.coffee @@ -3,6 +3,7 @@ class @Video @el = $(element).find('.video') @id = @el.attr('id').replace(/video_/, '') @caption_data_dir = @el.data('caption-data-dir') + @caption_asset_path = @el.data('caption-asset-path') @show_captions = @el.data('show-captions') == "true" window.player = null @el = $("#video_#{@id}") diff --git a/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee b/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee index cdd74c5d07..706971409b 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee @@ -10,7 +10,10 @@ class @VideoCaption extends Subview .bind('DOMMouseScroll', @onMovement) captionURL: -> - "/static/#{@captionDataDir}/subs/#{@youtubeId}.srt.sjson" + if @captionAssetPath != '' + "#{@captionAssetPath}/#{@youtubeId}.srt.sjson" + else + "/static/#{@captionDataDir}/subs/#{@youtubeId}.srt.sjson" render: -> # TODO: make it so you can have a video with no captions. diff --git a/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee b/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee index 8829e25dac..2f2f327ffc 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee @@ -32,6 +32,7 @@ class @VideoPlayer extends Subview youtubeId: @video.youtubeId('1.0') currentSpeed: @currentSpeed() captionDataDir: @video.caption_data_dir + captionAssetPath: @video.caption_asset_path unless onTouchBasedDevice() @volumeControl = new VideoVolumeControl el: @$('.secondary-controls') @speedControl = new VideoSpeedControl el: @$('.secondary-controls'), speeds: @video.speeds, currentSpeed: @currentSpeed() diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py index 02cbb7121f..e30132cff9 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py @@ -11,12 +11,12 @@ from xmodule.contentstore.content import StaticContent, XASSET_SRCREF_PREFIX log = logging.getLogger(__name__) -def import_static_content(modules, course_loc, course_data_path, static_content_store, target_location_namespace): +def import_static_content(modules, course_loc, course_data_path, static_content_store, target_location_namespace, subpath = 'static'): remap_dict = {} - + # now import all static assets - static_dir = course_data_path / 'static/' + static_dir = course_data_path / subpath for dirname, dirnames, filenames in os.walk(static_dir): for filename in filenames: @@ -24,6 +24,8 @@ def import_static_content(modules, course_loc, course_data_path, static_content_ try: content_path = os.path.join(dirname, filename) fullname_with_subpath = content_path.replace(static_dir, '') # strip away leading path from the name + if fullname_with_subpath.startswith('/'): + fullname_with_subpath = fullname_with_subpath[1:] content_loc = StaticContent.compute_location(target_location_namespace.org, target_location_namespace.course, fullname_with_subpath) mime_type = mimetypes.guess_type(filename)[0] @@ -125,8 +127,11 @@ def import_from_xml(store, data_dir, course_dirs=None, course_location = module.location if static_content_store is not None: + _namespace_rename = target_location_namespace if target_location_namespace is not None else module_store.modules[course_id].location + + # first pass to find everything in /static/ import_static_content(module_store.modules[course_id], course_location, course_data_path, static_content_store, - target_location_namespace if target_location_namespace is not None else course_location) + _namespace_rename, subpath='static') for module in module_store.modules[course_id].itervalues(): diff --git a/common/lib/xmodule/xmodule/video_module.py b/common/lib/xmodule/xmodule/video_module.py index 9a22950ca8..5e0639a883 100644 --- a/common/lib/xmodule/xmodule/video_module.py +++ b/common/lib/xmodule/xmodule/video_module.py @@ -6,6 +6,9 @@ from pkg_resources import resource_string, resource_listdir from xmodule.x_module import XModule from xmodule.raw_module import RawDescriptor +from xmodule.modulestore.mongo import MongoModuleStore +from xmodule.modulestore.django import modulestore +from xmodule.contentstore.content import StaticContent log = logging.getLogger(__name__) @@ -93,6 +96,10 @@ class VideoModule(XModule): return self.youtube def get_html(self): + caption_asset_path = '' + if isinstance(modulestore(), MongoModuleStore) : + caption_asset_path = StaticContent.get_base_url_path_for_course_assets(self.location) + return self.system.render_template('video.html', { 'streams': self.video_list(), 'id': self.location.html_id(), @@ -102,6 +109,7 @@ class VideoModule(XModule): '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'], + 'caption_asset_path': caption_asset_path, 'show_captions': self.show_captions }) diff --git a/lms/templates/video.html b/lms/templates/video.html index 5c041d5c70..18c1bcbced 100644 --- a/lms/templates/video.html +++ b/lms/templates/video.html @@ -2,7 +2,7 @@

${display_name}

% endif -
+
From 2d7f1b73d7d5b2d68ffbd003b3c111563d543da9 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Tue, 13 Nov 2012 13:27:03 -0500 Subject: [PATCH 2/3] consolidate logic to compute caption path to server-side, we don't need to do this client-side --- .../xmodule/js/src/video/display/video_caption.coffee | 5 +---- .../xmodule/xmodule/js/src/video/display/video_player.coffee | 1 - common/lib/xmodule/xmodule/video_module.py | 5 ++++- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee b/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee index 706971409b..20d388f6c0 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee @@ -10,10 +10,7 @@ class @VideoCaption extends Subview .bind('DOMMouseScroll', @onMovement) captionURL: -> - if @captionAssetPath != '' - "#{@captionAssetPath}/#{@youtubeId}.srt.sjson" - else - "/static/#{@captionDataDir}/subs/#{@youtubeId}.srt.sjson" + "#{@captionAssetPath}/#{@youtubeId}.srt.sjson" render: -> # TODO: make it so you can have a video with no captions. diff --git a/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee b/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee index 2f2f327ffc..b7c5bd8a89 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee @@ -31,7 +31,6 @@ class @VideoPlayer extends Subview el: @el youtubeId: @video.youtubeId('1.0') currentSpeed: @currentSpeed() - captionDataDir: @video.caption_data_dir captionAssetPath: @video.caption_asset_path unless onTouchBasedDevice() @volumeControl = new VideoVolumeControl el: @$('.secondary-controls') diff --git a/common/lib/xmodule/xmodule/video_module.py b/common/lib/xmodule/xmodule/video_module.py index 5e0639a883..30e385f284 100644 --- a/common/lib/xmodule/xmodule/video_module.py +++ b/common/lib/xmodule/xmodule/video_module.py @@ -96,9 +96,12 @@ class VideoModule(XModule): return self.youtube def get_html(self): - caption_asset_path = '' if isinstance(modulestore(), MongoModuleStore) : caption_asset_path = StaticContent.get_base_url_path_for_course_assets(self.location) + else: + # VS[compat] + # cdodge: filesystem static content support. + caption_asset_path = "/static/{0}/subs".format(self.metadata['data_dir']) return self.system.render_template('video.html', { 'streams': self.video_list(), From 6d45445aef1521b27ba09721c466927336a47807 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 14 Nov 2012 11:14:30 -0500 Subject: [PATCH 3/3] assume that users are putting caption information in /static/subs. We'll enforce this on the xlint utility --- .../xmodule/xmodule/js/src/video/display/video_caption.coffee | 2 +- common/lib/xmodule/xmodule/video_module.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee b/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee index 20d388f6c0..e840cd2a77 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee @@ -10,7 +10,7 @@ class @VideoCaption extends Subview .bind('DOMMouseScroll', @onMovement) captionURL: -> - "#{@captionAssetPath}/#{@youtubeId}.srt.sjson" + "#{@captionAssetPath}#{@youtubeId}.srt.sjson" render: -> # TODO: make it so you can have a video with no captions. diff --git a/common/lib/xmodule/xmodule/video_module.py b/common/lib/xmodule/xmodule/video_module.py index 30e385f284..0593b7f00e 100644 --- a/common/lib/xmodule/xmodule/video_module.py +++ b/common/lib/xmodule/xmodule/video_module.py @@ -97,11 +97,11 @@ class VideoModule(XModule): def get_html(self): if isinstance(modulestore(), MongoModuleStore) : - caption_asset_path = StaticContent.get_base_url_path_for_course_assets(self.location) + caption_asset_path = StaticContent.get_base_url_path_for_course_assets(self.location) + '/subs_' else: # VS[compat] # cdodge: filesystem static content support. - caption_asset_path = "/static/{0}/subs".format(self.metadata['data_dir']) + caption_asset_path = "/static/{0}/subs/".format(self.metadata['data_dir']) return self.system.render_template('video.html', { 'streams': self.video_list(),