Commit 1203eb58 by noraiz-anwar

Do not override Default Video URL with value from VAL

parent 56eee715
...@@ -722,7 +722,6 @@ class VideoDescriptor(VideoFields, VideoTranscriptsMixin, VideoStudioViewHandler ...@@ -722,7 +722,6 @@ class VideoDescriptor(VideoFields, VideoTranscriptsMixin, VideoStudioViewHandler
}) })
source_url = self.create_youtube_url(youtube_id_1_0['value']) source_url = self.create_youtube_url(youtube_id_1_0['value'])
# First try a lookup in VAL. If any video encoding is found given the video id then # First try a lookup in VAL. If any video encoding is found given the video id then
# override the source_url with it. # override the source_url with it.
if self.edx_video_id and edxval_api: if self.edx_video_id and edxval_api:
...@@ -734,15 +733,18 @@ class VideoDescriptor(VideoFields, VideoTranscriptsMixin, VideoStudioViewHandler ...@@ -734,15 +733,18 @@ class VideoDescriptor(VideoFields, VideoTranscriptsMixin, VideoStudioViewHandler
# Get video encodings for val profiles. # Get video encodings for val profiles.
val_video_encodings = edxval_api.get_urls_for_profiles(self.edx_video_id, 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. # VAL's youtube source has greater priority over external youtube source.
if val_video_encodings.get('youtube'): if val_video_encodings.get('youtube'):
source_url = self.create_youtube_url(val_video_encodings['youtube']) source_url = self.create_youtube_url(val_video_encodings['youtube'])
elif val_video_encodings.get('hls'):
source_url = val_video_encodings['hls'] # If no youtube source is provided externally or in VAl, update source_url in order: hls > mp4 and webm
elif val_video_encodings.get('desktop_mp4'): if not source_url:
source_url = val_video_encodings['desktop_mp4'] if val_video_encodings.get('hls'):
elif val_video_encodings.get('desktop_webm'): source_url = val_video_encodings['hls']
source_url = val_video_encodings['desktop_webm'] 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. # Only add if html5 sources do not already contain source_url.
if source_url and source_url not in video_url['value']: if source_url and source_url not in video_url['value']:
......
...@@ -1085,64 +1085,89 @@ class TestVideoDescriptorInitialization(BaseTestXmodule): ...@@ -1085,64 +1085,89 @@ class TestVideoDescriptorInitialization(BaseTestXmodule):
@ddt.data( @ddt.data(
( (
{ {
'desktop_webm': 'https://webm.com/dw.webm',
'hls': 'https://hls.com/hls.m3u8',
'youtube': 'v0TFmdO4ZP0', 'youtube': 'v0TFmdO4ZP0',
'desktop_mp4': 'https://mp4.com/dm.mp4' 'hls': 'https://hls.com/hls.m3u8',
'desktop_mp4': 'https://mp4.com/dm.mp4',
'desktop_webm': 'https://webm.com/dw.webm',
}, },
['https://www.youtube.com/watch?v=v0TFmdO4ZP0'] ['https://www.youtube.com/watch?v=v0TFmdO4ZP0']
), ),
( (
{ {
'desktop_webm': 'https://webm.com/dw.webm',
'hls': 'https://hls.com/hls.m3u8',
'youtube': None, 'youtube': None,
'desktop_mp4': 'https://mp4.com/dm.mp4' 'hls': 'https://hls.com/hls.m3u8',
'desktop_mp4': 'https://mp4.com/dm.mp4',
'desktop_webm': 'https://webm.com/dw.webm',
}, },
['https://hls.com/hls.m3u8'] ['https://www.youtube.com/watch?v=3_yD_cEKoCk']
), ),
( (
{ {
'desktop_webm': 'https://webm.com/dw.webm',
'hls': None,
'youtube': None, 'youtube': None,
'desktop_mp4': 'https://mp4.com/dm.mp4' 'hls': None,
'desktop_mp4': None,
'desktop_webm': None,
}, },
['https://mp4.com/dm.mp4'] ['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.
Accepted order of source priority is:
VAL's youtube source > external youtube source > hls > mp4 > webm.
Note that `https://www.youtube.com/watch?v=3_yD_cEKoCk` is the default youtube source with which
a video component is initialized. Current implementation considers this youtube source as a valid
external youtube source.
"""
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)
@ddt.data(
( (
{ {
'desktop_webm': 'https://webm.com/dw.webm',
'hls': None,
'youtube': None, 'youtube': None,
'desktop_mp4': None 'hls': 'https://hls.com/hls.m3u8',
'desktop_mp4': 'https://mp4.com/dm.mp4',
'desktop_webm': 'https://webm.com/dw.webm',
}, },
['https://webm.com/dw.webm'] ['https://hls.com/hls.m3u8']
), ),
( (
{ {
'desktop_webm': None, 'youtube': 'v0TFmdO4ZP0',
'hls': None, 'hls': 'https://hls.com/hls.m3u8',
'youtube': None, 'desktop_mp4': None,
'desktop_mp4': None 'desktop_webm': 'https://webm.com/dw.webm',
}, },
['https://www.youtube.com/watch?v=3_yD_cEKoCk'] ['https://www.youtube.com/watch?v=v0TFmdO4ZP0']
), ),
) )
@ddt.unpack @ddt.unpack
@patch('xmodule.video_module.video_module.HLSPlaybackEnabledFlag.feature_enabled', Mock(return_value=True)) @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): def test_val_encoding_in_context_without_external_youtube_source(self, val_video_encodings, video_url):
""" """
Tests that the val encodings correctly override the video url when the edx video id is set and Tests that the val encodings correctly override the video url when the edx video id is set and
one or more encodings are present. one or more encodings are present. In this scenerio no external youtube source is provided.
Accepted order of source priority is:
VAL's youtube source > external youtube source > hls > mp4 > webm.
""" """
with patch('xmodule.video_module.video_module.edxval_api.get_urls_for_profiles') as get_urls_for_profiles: 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 get_urls_for_profiles.return_value = val_video_encodings
self.initialize_module( self.initialize_module(
data='<video display_name="Video" download_video="true" edx_video_id="12345-67890">[]</video>' data='<video display_name="Video" youtube_id_1_0="" download_video="true" edx_video_id="12345-67890">[]</video>'
) )
context = self.item_descriptor.get_context() context = self.item_descriptor.get_context()
self.assertEqual(context['transcripts_basic_tab_metadata']['video_url']['value'], video_url) self.assertEqual(context['transcripts_basic_tab_metadata']['video_url']['value'], video_url)
@attr(shard=1) @attr(shard=1)
......
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