avoid video url rewrite for third party videos
This commit is contained in:
@@ -225,6 +225,7 @@ class VideoModule(VideoFields, VideoTranscriptsMixin, VideoStudentViewHandlers,
|
|||||||
branding_info = None
|
branding_info = None
|
||||||
youtube_streams = ""
|
youtube_streams = ""
|
||||||
video_duration = None
|
video_duration = None
|
||||||
|
video_status = None
|
||||||
|
|
||||||
# Determine if there is an alternative source for this video
|
# Determine if there is an alternative source for this video
|
||||||
# based on user locale. This exists to support cases where
|
# based on user locale. This exists to support cases where
|
||||||
@@ -271,6 +272,7 @@ class VideoModule(VideoFields, VideoTranscriptsMixin, VideoStudentViewHandlers,
|
|||||||
# get video duration
|
# get video duration
|
||||||
video_data = edxval_api.get_video_info(self.edx_video_id.strip())
|
video_data = edxval_api.get_video_info(self.edx_video_id.strip())
|
||||||
video_duration = video_data.get('duration')
|
video_duration = video_data.get('duration')
|
||||||
|
video_status = video_data.get('status')
|
||||||
|
|
||||||
except (edxval_api.ValInternalError, edxval_api.ValVideoNotFoundError):
|
except (edxval_api.ValInternalError, edxval_api.ValVideoNotFoundError):
|
||||||
# VAL raises this exception if it can't find data for the edx video ID. This can happen if the
|
# VAL raises this exception if it can't find data for the edx video ID. This can happen if the
|
||||||
@@ -285,7 +287,7 @@ class VideoModule(VideoFields, VideoTranscriptsMixin, VideoStudentViewHandlers,
|
|||||||
if getattr(self, 'video_speed_optimizations', True) and cdn_url:
|
if getattr(self, 'video_speed_optimizations', True) and cdn_url:
|
||||||
branding_info = BrandingInfoConfig.get_config().get(self.system.user_location)
|
branding_info = BrandingInfoConfig.get_config().get(self.system.user_location)
|
||||||
|
|
||||||
if self.edx_video_id and edxval_api:
|
if self.edx_video_id and edxval_api and video_status != u'external':
|
||||||
for index, source_url in enumerate(sources):
|
for index, source_url in enumerate(sources):
|
||||||
new_url = rewrite_video_url(cdn_url, source_url)
|
new_url = rewrite_video_url(cdn_url, source_url)
|
||||||
if new_url:
|
if new_url:
|
||||||
|
|||||||
@@ -903,6 +903,109 @@ class TestGetHtmlMethod(BaseTestXmodule):
|
|||||||
self.item_descriptor.xmodule_runtime.render_template('video.html', expected_context)
|
self.item_descriptor.xmodule_runtime.render_template('video.html', expected_context)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# pylint: disable=invalid-name
|
||||||
|
def test_get_html_cdn_source_external_video(self):
|
||||||
|
"""
|
||||||
|
Test that video from an external source loads successfully.
|
||||||
|
|
||||||
|
For a video from a third part, which has 'external' status
|
||||||
|
in the VAL, the url-rewrite will not happen and URL will
|
||||||
|
remain unchanged in the get_html() method.
|
||||||
|
"""
|
||||||
|
|
||||||
|
source_xml = u"""
|
||||||
|
<video show_captions="true"
|
||||||
|
display_name="A Name"
|
||||||
|
sub="a_sub_file.srt.sjson" source="{source}"
|
||||||
|
download_video="{download_video}"
|
||||||
|
edx_video_id="{edx_video_id}"
|
||||||
|
start_time="01:00:03" end_time="01:00:10"
|
||||||
|
>
|
||||||
|
{sources}
|
||||||
|
</video>
|
||||||
|
"""
|
||||||
|
|
||||||
|
case_data = {
|
||||||
|
'download_video': 'true',
|
||||||
|
'source': 'example_source.mp4',
|
||||||
|
'sources': """
|
||||||
|
<source src="http://example.com/example.mp4"/>
|
||||||
|
""",
|
||||||
|
'result': {
|
||||||
|
'download_video_link': u'example_source.mp4',
|
||||||
|
'sources': [
|
||||||
|
u'http://example.com/example.mp4',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cases = [
|
||||||
|
dict(case_data, edx_video_id="vid-v1:12345"),
|
||||||
|
]
|
||||||
|
|
||||||
|
initial_context = {
|
||||||
|
'autoadvance_enabled': False,
|
||||||
|
'branding_info': None,
|
||||||
|
'license': None,
|
||||||
|
'bumper_metadata': 'null',
|
||||||
|
'cdn_eval': False,
|
||||||
|
'cdn_exp_group': None,
|
||||||
|
'display_name': u'A Name',
|
||||||
|
'download_video_link': None,
|
||||||
|
'handout': None,
|
||||||
|
'id': None,
|
||||||
|
'metadata': self.default_metadata_dict,
|
||||||
|
'track': None,
|
||||||
|
'transcript_download_format': u'srt',
|
||||||
|
'transcript_download_formats_list': [
|
||||||
|
{'display_name': 'SubRip (.srt) file', 'value': 'srt'},
|
||||||
|
{'display_name': 'Text (.txt) file', 'value': 'txt'}
|
||||||
|
],
|
||||||
|
'poster': 'null',
|
||||||
|
}
|
||||||
|
initial_context['metadata']['duration'] = None
|
||||||
|
|
||||||
|
for data in cases:
|
||||||
|
DATA = source_xml.format(
|
||||||
|
download_video=data['download_video'],
|
||||||
|
source=data['source'],
|
||||||
|
sources=data['sources'],
|
||||||
|
edx_video_id=data['edx_video_id'],
|
||||||
|
)
|
||||||
|
self.initialize_module(data=DATA)
|
||||||
|
|
||||||
|
# Mocking the edxval API call because if not done,
|
||||||
|
# the method throws exception as no VAL entry is found
|
||||||
|
# for the corresponding edx-video-id
|
||||||
|
with patch('edxval.api.get_video_info') as mock_get_video_info:
|
||||||
|
mock_get_video_info.return_value = {
|
||||||
|
'url': 'http://example.com/example.mp4',
|
||||||
|
'edx_video_id': u'vid-v1:12345',
|
||||||
|
'status': u'external',
|
||||||
|
'duration': None,
|
||||||
|
'client_video_id': u'external video',
|
||||||
|
'encoded_videos': {}
|
||||||
|
}
|
||||||
|
context = self.item_descriptor.render(STUDENT_VIEW).content
|
||||||
|
expected_context = dict(initial_context)
|
||||||
|
expected_context['metadata'].update({
|
||||||
|
'transcriptTranslationUrl': self.get_handler_url('transcript', 'translation/__lang__'),
|
||||||
|
'transcriptAvailableTranslationsUrl': self.get_handler_url('transcript', 'available_translations'),
|
||||||
|
'publishCompletionUrl': self.get_handler_url('publish_completion', ''),
|
||||||
|
'saveStateUrl': self.item_descriptor.xmodule_runtime.ajax_url + '/save_user_state',
|
||||||
|
'sources': data['result'].get('sources', []),
|
||||||
|
})
|
||||||
|
expected_context.update({
|
||||||
|
'id': self.item_descriptor.location.html_id(),
|
||||||
|
'download_video_link': data['result'].get('download_video_link'),
|
||||||
|
'metadata': json.dumps(expected_context['metadata'])
|
||||||
|
})
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
context,
|
||||||
|
self.item_descriptor.xmodule_runtime.render_template('video.html', expected_context)
|
||||||
|
)
|
||||||
|
|
||||||
@ddt.data(
|
@ddt.data(
|
||||||
(True, ['youtube', 'desktop_webm', 'desktop_mp4', 'hls']),
|
(True, ['youtube', 'desktop_webm', 'desktop_mp4', 'hls']),
|
||||||
(False, ['youtube', 'desktop_webm', 'desktop_mp4'])
|
(False, ['youtube', 'desktop_webm', 'desktop_mp4'])
|
||||||
|
|||||||
Reference in New Issue
Block a user