diff --git a/common/lib/xmodule/xmodule/video_module/video_module.py b/common/lib/xmodule/xmodule/video_module/video_module.py index 0a359370d9..c05cf4ec16 100644 --- a/common/lib/xmodule/xmodule/video_module/video_module.py +++ b/common/lib/xmodule/xmodule/video_module/video_module.py @@ -184,20 +184,26 @@ class VideoModule(VideoFields, VideoTranscriptsMixin, VideoStudentViewHandlers, # stream. if self.edx_video_id and edxval_api: try: - val_video_urls = edxval_api.get_urls_for_profiles( - self.edx_video_id, ["desktop_mp4", "youtube"] - ) + val_profiles = ["youtube", "desktop_webm", "desktop_mp4"] + val_video_urls = edxval_api.get_urls_for_profiles(self.edx_video_id, val_profiles) + # VAL will always give us the keys for the profiles we asked for, but # if it doesn't have an encoded video entry for that Video + Profile, the # value will map to `None` - if val_video_urls["desktop_mp4"]: - if self.download_video: - download_video_link = val_video_urls["desktop_mp4"] - # add the desktop_mp4 profile to the list of alternative sources - if val_video_urls["desktop_mp4"] not in sources: - sources.append(val_video_urls["desktop_mp4"]) + + # add the non-youtube urls to the list of alternative sources + # use the last non-None non-youtube url as the link to download the video + for url in [val_video_urls[p] for p in val_profiles if p != "youtube"]: + if url: + if url not in sources: + sources.append(url) + if self.download_video: + download_video_link = url + + # set the youtube url if val_video_urls["youtube"]: youtube_streams = "1.00:{}".format(val_video_urls["youtube"]) + except edxval_api.ValInternalError: # VAL raises this exception if it can't find data for the edx video ID. This can happen if the # course data is ported to a machine that does not have the VAL data. So for now, pass on this diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py index d00ee89aec..b4d65b2435 100644 --- a/lms/djangoapps/courseware/tests/test_video_mongo.py +++ b/lms/djangoapps/courseware/tests/test_video_mongo.py @@ -512,28 +512,33 @@ class TestGetHtmlMethod(BaseTestXmodule): ) def test_get_html_with_existing_edx_video_id(self): - result = create_profile( - dict( - profile_name="desktop_mp4", - extension="mp4", - width=200, - height=2001 + # create test profiles and their encodings + encoded_videos = [] + for profile, extension in [("desktop_webm", "webm"), ("desktop_mp4", "mp4")]: + result = create_profile( + dict( + profile_name=profile, + extension=extension, + width=200, + height=2001 + ) ) - ) - self.assertEqual(result, "desktop_mp4") + self.assertEqual(result, profile) + encoded_videos.append( + dict( + url=u"http://fake-video.edx.org/thundercats.{}".format(extension), + file_size=9000, + bitrate=42, + profile=profile, + ) + ) + result = create_video( dict( client_video_id="Thunder Cats", duration=111, edx_video_id="thundercats", - encoded_videos=[ - dict( - url=u"http://fake-video.edx.org/thundercats.mp4", - file_size=9000, - bitrate=42, - profile="desktop_mp4", - ) - ] + encoded_videos=encoded_videos ) ) self.assertEqual(result, "thundercats") @@ -549,6 +554,7 @@ class TestGetHtmlMethod(BaseTestXmodule): {sources} """ + data = { 'download_video': 'true', 'source': 'example_source.mp4', @@ -559,8 +565,11 @@ class TestGetHtmlMethod(BaseTestXmodule): 'edx_video_id': "thundercats", 'result': { 'download_video_link': u'http://fake-video.edx.org/thundercats.mp4', - # make sure the desktop_mp4 url is included as part of the alternative sources. - 'sources': json.dumps([u'example.mp4', u'example.webm', u"http://fake-video.edx.org/thundercats.mp4"]), + # make sure the urls for the various encodings are included as part of the alternative sources. + 'sources': json.dumps( + [u'example.mp4', u'example.webm'] + + [video['url'] for video in encoded_videos] + ), } }