Skip to content

Commit b94ccde

Browse files
authored
refactor: Update VideoConfigService get_transcript method (#37809)
Update VideoConfigService get_transcript method Update method for the bumper videos
1 parent 9d2bbb1 commit b94ccde

3 files changed

Lines changed: 22 additions & 21 deletions

File tree

openedx/core/djangoapps/video_config/services.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def get_transcript(
123123
lang: str | None = None,
124124
output_format: str = 'srt',
125125
youtube_id: str | None = None,
126+
is_bumper=False,
126127
) -> tuple[bytes, str, str]:
127128
"""
128129
Retrieve a transcript from the runtime's storage.
@@ -135,7 +136,7 @@ def get_transcript(
135136
TranscriptNotFoundError: If the transcript cannot be found or retrieved
136137
"""
137138
try:
138-
return get_transcript(video_block, lang, output_format, youtube_id)
139+
return get_transcript(video_block, lang, output_format, youtube_id, is_bumper)
139140
except NotFoundError as exc:
140141
raise TranscriptNotFoundError(
141142
f"Failed to get transcript: {exc}"

openedx/core/djangoapps/video_config/transcripts_utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ def get_transcript_from_learning_core(video_block, language, output_format, tran
10491049
return output_transcript, output_filename, Transcript.mime_types[output_format]
10501050

10511051

1052-
def get_transcript(video, lang=None, output_format=Transcript.SRT, youtube_id=None):
1052+
def get_transcript(video, lang=None, output_format=Transcript.SRT, youtube_id=None, is_bumper=False):
10531053
"""
10541054
Get video transcript from edx-val or content store.
10551055
@@ -1062,7 +1062,14 @@ def get_transcript(video, lang=None, output_format=Transcript.SRT, youtube_id=No
10621062
Returns:
10631063
tuple containing content, filename, mimetype
10641064
"""
1065-
transcripts_info = video.get_transcripts_info()
1065+
transcripts_info = video.get_transcripts_info(is_bumper)
1066+
if is_bumper:
1067+
return get_transcript_from_contentstore(
1068+
video,
1069+
lang,
1070+
Transcript.SJSON,
1071+
transcripts_info
1072+
)
10661073
if not lang:
10671074
lang = video.get_default_transcript_language(transcripts_info)
10681075

xmodule/video_block/video_handlers.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from openedx.core.djangoapps.video_config.transcripts_utils import (
2323
Transcript,
2424
clean_video_id,
25-
get_transcript_from_contentstore,
2625
subs_filename,
2726
)
2827
from xblocks_contrib.video.exceptions import (
@@ -38,6 +37,7 @@ def get_transcript(
3837
lang: str | None = None,
3938
output_format: str = 'srt',
4039
youtube_id: str | None = None,
40+
is_bumper: bool = False,
4141
) -> tuple[bytes, str, str]:
4242
"""
4343
Retrieve a transcript using a video block's configuration service.
@@ -51,7 +51,7 @@ def get_transcript(
5151
video_config_service = video_block.runtime.service(video_block, 'video_config')
5252
if not video_config_service:
5353
raise Exception("Video config service not found")
54-
return video_config_service.get_transcript(video_block, lang, output_format, youtube_id)
54+
return video_config_service.get_transcript(video_block, lang, output_format, youtube_id, is_bumper)
5555

5656

5757
# Disable no-member warning:
@@ -276,29 +276,22 @@ def transcript(self, request, dispatch):
276276
self.transcript_language = language
277277

278278
try:
279-
if is_bumper:
280-
content, filename, mimetype = get_transcript_from_contentstore(
281-
self,
282-
self.transcript_language,
283-
Transcript.SJSON,
284-
transcripts
285-
)
286-
else:
287-
content, filename, mimetype = get_transcript(
288-
self,
289-
lang=self.transcript_language,
290-
output_format=Transcript.SJSON,
291-
youtube_id=request.GET.get('videoId'),
292-
)
293-
279+
youtube_id = None if is_bumper else request.GET.get('videoId')
280+
content, filename, mimetype = get_transcript(
281+
self,
282+
lang=self.transcript_language,
283+
output_format=Transcript.SJSON,
284+
youtube_id=youtube_id,
285+
is_bumper=is_bumper
286+
)
294287
response = self.make_transcript_http_response(
295288
content,
296289
filename,
297290
self.transcript_language,
298291
mimetype,
299292
add_attachment_header=False
300293
)
301-
except (NotFoundError, TranscriptNotFoundError) as exc:
294+
except TranscriptNotFoundError as exc:
302295
edx_video_id = clean_video_id(self.edx_video_id)
303296
log.warning(
304297
'[Translation Dispatch] %s: %s',

0 commit comments

Comments
 (0)