Skip to content

Commit

Permalink
feat: Updates to support save video with transcript in library home
Browse files Browse the repository at this point in the history
* Add error handler on save video to avoid create sjson
* Support transcripts without edx_video_id in definition_to_xml
  • Loading branch information
ChrisChV committed Dec 25, 2024
1 parent 85f4128 commit 9cdf45f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
42 changes: 42 additions & 0 deletions xmodule/tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,48 @@ def test_export_to_xml(self, mock_val_api):
course_id=self.block.scope_ids.usage_id.context_key,
)

def test_export_to_xml_without_video_id(self):
"""
Test that we write the correct XML without video_id on export.
"""
self.block.youtube_id_0_75 = 'izygArpw-Qo'
self.block.youtube_id_1_0 = 'p2Q6BrNhdh8'
self.block.youtube_id_1_25 = '1EeWXzPdhSA'
self.block.youtube_id_1_5 = 'rABDYkeK0x8'
self.block.show_captions = False
self.block.start_time = datetime.timedelta(seconds=1.0)
self.block.end_time = datetime.timedelta(seconds=60)
self.block.track = 'http://www.example.com/track'
self.block.handout = 'http://www.example.com/handout'
self.block.download_track = True
self.block.html5_sources = ['http://www.example.com/source.mp4', 'http://www.example.com/source1.ogg']
self.block.download_video = True
self.block.transcripts = {'ua': 'ukrainian_translation.srt', 'ge': 'german_translation.srt'}

xml = self.block.definition_to_xml(self.file_system)
parser = etree.XMLParser(remove_blank_text=True)
xml_string = '''\
<video
url_name="SampleProblem"
start_time="0:00:01"
show_captions="false"
end_time="0:01:00"
download_video="true"
download_track="true"
youtube="0.75:izygArpw-Qo,1.00:p2Q6BrNhdh8,1.25:1EeWXzPdhSA,1.50:rABDYkeK0x8"
transcripts='{"ge": "german_translation.srt", "ua": "ukrainian_translation.srt"}'
>
<source src="http://www.example.com/source.mp4"/>
<source src="http://www.example.com/source1.ogg"/>
<track src="http://www.example.com/track"/>
<handout src="http://www.example.com/handout"/>
<transcript language="ge" src="german_translation.srt" />
<transcript language="ua" src="ukrainian_translation.srt" />
</video>
'''
expected = etree.XML(xml_string, parser=parser)
self.assertXmlEqual(expected, xml)

@patch('xmodule.video_block.video_block.edxval_api')
def test_export_to_xml_val_error(self, mock_val_api):
# Export should succeed without VAL data if video does not exist
Expand Down
2 changes: 2 additions & 0 deletions xmodule/video_block/transcripts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ def manage_video_subtitles_save(item, user, old_metadata=None, generate_translat
)
except TranscriptException:
pass
except AttributeError:
pass
if reraised_message:
item.save_with_metadata(user)
raise TranscriptException(reraised_message)
Expand Down
10 changes: 7 additions & 3 deletions xmodule/video_block/video_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,15 @@ def definition_to_xml(self, resource_fs): # lint-amnesty, pylint: disable=too-m
if new_transcripts.get('en'):
xml.set('sub', '')

# Update `transcripts` attribute in the xml
xml.set('transcripts', json.dumps(transcripts, sort_keys=True))

except edxval_api.ValVideoNotFoundError:
pass
else:
if transcripts.get('en'):
xml.set('sub', '')

if transcripts:
# Update `transcripts` attribute in the xml
xml.set('transcripts', json.dumps(transcripts, sort_keys=True))

# Sorting transcripts for easy testing of resulting xml
for transcript_language in sorted(transcripts.keys()):
Expand Down

0 comments on commit 9cdf45f

Please sign in to comment.