diff --git a/lms/djangoapps/courseware/tests/test_video_handlers.py b/lms/djangoapps/courseware/tests/test_video_handlers.py index 2e2f615ee919..8f136c75fd0b 100644 --- a/lms/djangoapps/courseware/tests/test_video_handlers.py +++ b/lms/djangoapps/courseware/tests/test_video_handlers.py @@ -815,7 +815,6 @@ def _set_static_asset_path(self): store.update_item(self.course, self.user.id) @patch('openedx.core.djangoapps.video_config.transcripts_utils.edxval_api.get_video_transcript_data') - @patch('xmodule.video_block.VideoBlock.translation', Mock(side_effect=NotFoundError)) @patch('xmodule.video_block.VideoBlock.get_static_transcript', Mock(return_value=Response(status=404))) def test_translation_fallback_transcript(self, mock_get_video_transcript_data): """ @@ -848,7 +847,6 @@ def test_translation_fallback_transcript(self, mock_get_video_transcript_data): for attribute, value in expected_headers.items(): assert response.headers[attribute] == value - @patch('xmodule.video_block.VideoBlock.translation', Mock(side_effect=NotFoundError)) @patch('xmodule.video_block.VideoBlock.get_static_transcript', Mock(return_value=Response(status=404))) def test_translation_fallback_transcript_feature_disabled(self): """ diff --git a/openedx/core/djangoapps/video_config/transcripts_utils.py b/openedx/core/djangoapps/video_config/transcripts_utils.py index be86324cd6e4..4a1e53e902d0 100644 --- a/openedx/core/djangoapps/video_config/transcripts_utils.py +++ b/openedx/core/djangoapps/video_config/transcripts_utils.py @@ -561,31 +561,6 @@ def generate_sjson_for_all_speeds(block, user_filename, result_subs_dict, lang): ) -def get_or_create_sjson(block, transcripts): - """ - Get sjson if already exists, otherwise generate it. - - Generate sjson with subs_id name, from user uploaded srt. - Subs_id is extracted from srt filename, which was set by user. - - Args: - transcipts (dict): dictionary of (language: file) pairs. - - Raises: - TranscriptException: when srt subtitles do not exist, - and exceptions from generate_subs_from_source. - """ - user_filename = transcripts[block.transcript_language] - user_subs_id = os.path.splitext(user_filename)[0] - source_subs_id, result_subs_dict = user_subs_id, {1.0: user_subs_id} - try: - sjson_transcript = Transcript.asset(block.location, source_subs_id, block.transcript_language).data - except NotFoundError: # generating sjson from srt - generate_sjson_for_all_speeds(block, user_filename, result_subs_dict, block.transcript_language) - sjson_transcript = Transcript.asset(block.location, source_subs_id, block.transcript_language).data - return sjson_transcript - - def get_video_ids_info(edx_video_id, youtube_id_1_0, html5_sources): """ Returns list internal or external video ids. diff --git a/xmodule/video_block/video_handlers.py b/xmodule/video_block/video_handlers.py index ef65f905481e..ce9603e5cd27 100644 --- a/xmodule/video_block/video_handlers.py +++ b/xmodule/video_block/video_handlers.py @@ -24,15 +24,11 @@ from openedx.core.djangoapps.video_config.transcripts_utils import ( Transcript, - TranscriptException, clean_video_id, - generate_sjson_for_all_speeds, get_html5_ids, - get_or_create_sjson, get_transcript_from_contentstore, remove_subs_from_store, subs_filename, - youtube_speed_dict ) from xblocks_contrib.video.exceptions import ( TranscriptsGenerationException, @@ -132,78 +128,6 @@ def handle_ajax(self, dispatch, data): raise NotFoundError('Unexpected dispatch type') - def translation(self, youtube_id, transcripts): - """ - This is called to get transcript file for specific language. - - youtube_id: str: must be one of youtube_ids or None if HTML video - transcripts (dict): A dict with all transcripts and a sub. - - Logic flow: - - If youtube_id doesn't exist, we have a video in HTML5 mode. Otherwise, - video in Youtube or Flash modes. - - if youtube: - If english -> give back youtube_id subtitles: - Return what we have in contentstore for given youtube_id. - If non-english: - a) extract youtube_id from srt file name. - b) try to find sjson by youtube_id and return if successful. - c) generate sjson from srt for all youtube speeds. - if non-youtube: - If english -> give back `sub` subtitles: - Return what we have in contentstore for given subs_if that is stored in self.sub. - If non-english: - a) try to find previously generated sjson. - b) otherwise generate sjson from srt and return it. - - Filenames naming: - en: subs_videoid.srt.sjson - non_en: uk_subs_videoid.srt.sjson - - Raises: - NotFoundError if for 'en' subtitles no asset is uploaded. - NotFoundError if youtube_id does not exist / invalid youtube_id - """ - sub, other_lang = transcripts["sub"], transcripts["transcripts"] - if youtube_id: - # Youtube case: - if self.transcript_language == 'en': - return Transcript.asset(self.location, youtube_id).data - - youtube_ids = youtube_speed_dict(self) - if youtube_id not in youtube_ids: - log.info("Youtube_id %s does not exist", youtube_id) - raise NotFoundError - - try: - sjson_transcript = Transcript.asset(self.location, youtube_id, self.transcript_language).data - except NotFoundError: - log.info("Can't find content in storage for %s transcript: generating.", youtube_id) - generate_sjson_for_all_speeds( - self, - other_lang[self.transcript_language], - {speed: youtube_id for youtube_id, speed in youtube_ids.items()}, - self.transcript_language - ) - sjson_transcript = Transcript.asset(self.location, youtube_id, self.transcript_language).data - - return sjson_transcript - else: - # HTML5 case - if self.transcript_language == 'en': - if '.srt' not in sub: # not bumper case - return Transcript.asset(self.location, sub).data - try: - return get_or_create_sjson(self, {'en': sub}) - except TranscriptException: - pass # to raise NotFoundError and try to get data in get_static_transcript - elif other_lang: - return get_or_create_sjson(self, other_lang) - - raise NotFoundError - def get_static_transcript(self, request, transcripts): """ Courses that are imported with the --nostatic flag do not show