@@ -116,34 +116,36 @@ def upload_transcript(
116116 self ,
117117 * ,
118118 video_block : VideoBlock ,
119- edx_video_id : str | None ,
120- transcript_file : File ,
121119 language_code : str ,
122- new_language_code : str ,
120+ new_language_code : str | None ,
121+ transcript_file : File ,
122+ edx_video_id : str | None ,
123123 ) -> None :
124124 """
125125 Store a transcript, however the runtime prefers to.
126126
127+ Mutates:
128+ * video_block.transcripts
129+ * video_block.edx_video_id, iff a new video is created in edx-val.
130+
127131 Can raise:
128132 * UnicodeDecodeError
129133 * TranscriptsGenerationException
130134 """
131- edx_video_id = clean_video_id (edx_video_id )
132135 is_library = isinstance (video_block .usage_key .context_key , LibraryLocatorV2 )
136+ content : bytes = transcript_file .read ()
133137 if is_library :
138+ # Save transcript as static asset in Learning Core if is a library component
134139 filename = f'transcript-{ new_language_code } .srt'
140+ add_library_block_static_asset_file (video_block .usage_key , f"static/{ filename } " , content )
135141 else :
142+ edx_video_id = clean_video_id (edx_video_id )
136143 if not edx_video_id :
137144 # Back-populate the video ID for an external video.
138145 # pylint: disable=attribute-defined-outside-init
139- video_block .edx_video_id = edx_video_id = create_external_video (display_name = 'external video' )
146+ edx_video_id = create_external_video (display_name = 'external video' )
147+ video_block .edx_video_id = edx_video_id
140148 filename = f'{ edx_video_id } -{ new_language_code } .srt'
141-
142- content = transcript_file .read ()
143- if is_library :
144- # Save transcript as static asset in Learning Core if is a library component
145- add_library_block_static_asset_file (video_block .usage_key , f"static/{ filename } " , content )
146- else :
147149 # Convert SRT transcript into an SJSON format and upload it to S3 if a course component
148150 sjson_subs = Transcript .convert (
149151 content = content .decode ('utf-8' ),
@@ -155,7 +157,7 @@ def upload_transcript(
155157 language_code = language_code ,
156158 metadata = {
157159 'file_format' : Transcript .SJSON ,
158- 'language_code' : new_language_code
160+ 'language_code' : new_language_code ,
159161 },
160162 file_data = ContentFile (sjson_subs ),
161163 )
0 commit comments