Commit 4c074f11 by Qubad786

Override video url with edx val encodings

parent 74f9858b
......@@ -701,10 +701,32 @@ class VideoDescriptor(VideoFields, VideoTranscriptsMixin, VideoStudioViewHandler
'default_value': [get_youtube_link(youtube_id_1_0['default_value'])]
})
youtube_id_1_0_value = get_youtube_link(youtube_id_1_0['value'])
source_url = self.create_youtube_url(youtube_id_1_0['value'])
if youtube_id_1_0_value:
video_url['value'].insert(0, youtube_id_1_0_value)
# First try a lookup in VAL. If any video encoding is found given the video id then
# override the source_url with it.
if self.edx_video_id and edxval_api:
val_profiles = ['youtube', 'desktop_webm', 'desktop_mp4']
if HLSPlaybackEnabledFlag.feature_enabled(self.runtime.course_id.for_branch(None)):
val_profiles.append('hls')
# Get video encodings for val profiles.
val_video_encodings = edxval_api.get_urls_for_profiles(self.edx_video_id, val_profiles)
# If multiple encodings are there in val, the priority will be: youtube > hls > mp4 and webm.
if val_video_encodings.get('youtube'):
source_url = self.create_youtube_url(val_video_encodings['youtube'])
elif val_video_encodings.get('hls'):
source_url = val_video_encodings['hls']
elif val_video_encodings.get('desktop_mp4'):
source_url = val_video_encodings['desktop_mp4']
elif val_video_encodings.get('desktop_webm'):
source_url = val_video_encodings['desktop_webm']
# Only add if html5 sources do not already contain source_url.
if source_url and source_url not in video_url['value']:
video_url['value'].insert(0, source_url)
metadata = {
'display_name': display_name,
......
......@@ -982,6 +982,7 @@ class TestVideoCDNRewriting(BaseTestXmodule):
@attr(shard=1)
@ddt.ddt
class TestVideoDescriptorInitialization(BaseTestXmodule):
"""
Make sure that module initialization works correctly.
......@@ -1051,6 +1052,68 @@ class TestVideoDescriptorInitialization(BaseTestXmodule):
self.assertNotIn('source', fields)
self.assertFalse(self.item_descriptor.download_video)
@ddt.data(
(
{
'desktop_webm': 'https://webm.com/dw.webm',
'hls': 'https://hls.com/hls.m3u8',
'youtube': 'v0TFmdO4ZP0',
'desktop_mp4': 'https://mp4.com/dm.mp4'
},
['https://www.youtube.com/watch?v=v0TFmdO4ZP0']
),
(
{
'desktop_webm': 'https://webm.com/dw.webm',
'hls': 'https://hls.com/hls.m3u8',
'youtube': None,
'desktop_mp4': 'https://mp4.com/dm.mp4'
},
['https://hls.com/hls.m3u8']
),
(
{
'desktop_webm': 'https://webm.com/dw.webm',
'hls': None,
'youtube': None,
'desktop_mp4': 'https://mp4.com/dm.mp4'
},
['https://mp4.com/dm.mp4']
),
(
{
'desktop_webm': 'https://webm.com/dw.webm',
'hls': None,
'youtube': None,
'desktop_mp4': None
},
['https://webm.com/dw.webm']
),
(
{
'desktop_webm': None,
'hls': None,
'youtube': None,
'desktop_mp4': None
},
['https://www.youtube.com/watch?v=3_yD_cEKoCk']
),
)
@ddt.unpack
@patch('xmodule.video_module.video_module.HLSPlaybackEnabledFlag.feature_enabled', Mock(return_value=True))
def test_val_encoding_in_context(self, val_video_encodings, video_url):
"""
Tests that the val encodings correctly override the video url when the edx video id is set and
one or more encodings are present.
"""
with patch('xmodule.video_module.video_module.edxval_api.get_urls_for_profiles') as get_urls_for_profiles:
get_urls_for_profiles.return_value = val_video_encodings
self.initialize_module(
data='<video display_name="Video" download_video="true" edx_video_id="12345-67890">[]</video>'
)
context = self.item_descriptor.get_context()
self.assertEqual(context['transcripts_basic_tab_metadata']['video_url']['value'], video_url)
@attr(shard=1)
@ddt.ddt
......
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