Skip to content

Commit

Permalink
fix: fix transcript replacement
Browse files Browse the repository at this point in the history
Fixed an issue where changing the transcript language code would
cause both the old and new transcript to be displayed.
But in this case, you won’t be able to download the transcript
from the old code, since the link is invalid.
  • Loading branch information
Dima Alipov authored and DmytroAlipov committed Apr 8, 2024
1 parent b706e60 commit d984947
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions xmodule/video_block/transcripts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,22 @@ def get_transcripts_info(self, is_bumper=False):
"transcripts": transcripts,
}

def add_or_update_transcripts(self, edx_video_id, language_code, new_language_code):
"""
Method to add or update transcripts for a specific video.
If a new transcript is added, then both new_language_code and
language_code fields will have the same value.
Arguments:
edx_video_id(unicode): edx-val's video identifier.
language_code(str): Current language code of the transcript.
new_language_code(str): New selected language code.
"""
if language_code != new_language_code:
self.transcripts.pop(language_code, None)
self.transcripts[new_language_code] = f'{edx_video_id}-{new_language_code}.srt'


@exception_decorator
def get_transcript_from_val(edx_video_id, lang=None, output_format=Transcript.SRT):
Expand Down
5 changes: 4 additions & 1 deletion xmodule/video_block/video_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ def validate_transcript_upload_data(self, data):

return error

# pylint: disable=too-many-statements
@XBlock.handler
def studio_transcript(self, request, dispatch):
"""
Expand Down Expand Up @@ -535,7 +536,9 @@ def studio_transcript(self, request, dispatch):
'edx_video_id': edx_video_id,
'language_code': new_language_code
}
self.transcripts[new_language_code] = f'{edx_video_id}-{new_language_code}.srt'
if language_code != new_language_code:
self.transcripts.pop(language_code, None)
self.add_or_update_transcripts(edx_video_id, language_code, new_language_code)
response = Response(json.dumps(payload), status=201)
except (TranscriptsGenerationException, UnicodeDecodeError):
response = Response(
Expand Down

0 comments on commit d984947

Please sign in to comment.