refactor: Update VideoConfigService get_transcript method (#37809)
Update VideoConfigService get_transcript method Update method for the bumper videos
This commit is contained in:
committed by
GitHub
parent
9d2bbb1797
commit
b94ccde7b4
@@ -123,6 +123,7 @@ class VideoConfigService:
|
||||
lang: str | None = None,
|
||||
output_format: str = 'srt',
|
||||
youtube_id: str | None = None,
|
||||
is_bumper=False,
|
||||
) -> tuple[bytes, str, str]:
|
||||
"""
|
||||
Retrieve a transcript from the runtime's storage.
|
||||
@@ -135,7 +136,7 @@ class VideoConfigService:
|
||||
TranscriptNotFoundError: If the transcript cannot be found or retrieved
|
||||
"""
|
||||
try:
|
||||
return get_transcript(video_block, lang, output_format, youtube_id)
|
||||
return get_transcript(video_block, lang, output_format, youtube_id, is_bumper)
|
||||
except NotFoundError as exc:
|
||||
raise TranscriptNotFoundError(
|
||||
f"Failed to get transcript: {exc}"
|
||||
|
||||
@@ -1049,7 +1049,7 @@ def get_transcript_from_learning_core(video_block, language, output_format, tran
|
||||
return output_transcript, output_filename, Transcript.mime_types[output_format]
|
||||
|
||||
|
||||
def get_transcript(video, lang=None, output_format=Transcript.SRT, youtube_id=None):
|
||||
def get_transcript(video, lang=None, output_format=Transcript.SRT, youtube_id=None, is_bumper=False):
|
||||
"""
|
||||
Get video transcript from edx-val or content store.
|
||||
|
||||
@@ -1062,7 +1062,14 @@ def get_transcript(video, lang=None, output_format=Transcript.SRT, youtube_id=No
|
||||
Returns:
|
||||
tuple containing content, filename, mimetype
|
||||
"""
|
||||
transcripts_info = video.get_transcripts_info()
|
||||
transcripts_info = video.get_transcripts_info(is_bumper)
|
||||
if is_bumper:
|
||||
return get_transcript_from_contentstore(
|
||||
video,
|
||||
lang,
|
||||
Transcript.SJSON,
|
||||
transcripts_info
|
||||
)
|
||||
if not lang:
|
||||
lang = video.get_default_transcript_language(transcripts_info)
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ from xmodule.fields import RelativeTime
|
||||
from openedx.core.djangoapps.video_config.transcripts_utils import (
|
||||
Transcript,
|
||||
clean_video_id,
|
||||
get_transcript_from_contentstore,
|
||||
subs_filename,
|
||||
)
|
||||
from xblocks_contrib.video.exceptions import (
|
||||
@@ -38,6 +37,7 @@ def get_transcript(
|
||||
lang: str | None = None,
|
||||
output_format: str = 'srt',
|
||||
youtube_id: str | None = None,
|
||||
is_bumper: bool = False,
|
||||
) -> tuple[bytes, str, str]:
|
||||
"""
|
||||
Retrieve a transcript using a video block's configuration service.
|
||||
@@ -51,7 +51,7 @@ def get_transcript(
|
||||
video_config_service = video_block.runtime.service(video_block, 'video_config')
|
||||
if not video_config_service:
|
||||
raise Exception("Video config service not found")
|
||||
return video_config_service.get_transcript(video_block, lang, output_format, youtube_id)
|
||||
return video_config_service.get_transcript(video_block, lang, output_format, youtube_id, is_bumper)
|
||||
|
||||
|
||||
# Disable no-member warning:
|
||||
@@ -276,21 +276,14 @@ class VideoStudentViewHandlers:
|
||||
self.transcript_language = language
|
||||
|
||||
try:
|
||||
if is_bumper:
|
||||
content, filename, mimetype = get_transcript_from_contentstore(
|
||||
self,
|
||||
self.transcript_language,
|
||||
Transcript.SJSON,
|
||||
transcripts
|
||||
)
|
||||
else:
|
||||
content, filename, mimetype = get_transcript(
|
||||
self,
|
||||
lang=self.transcript_language,
|
||||
output_format=Transcript.SJSON,
|
||||
youtube_id=request.GET.get('videoId'),
|
||||
)
|
||||
|
||||
youtube_id = None if is_bumper else request.GET.get('videoId')
|
||||
content, filename, mimetype = get_transcript(
|
||||
self,
|
||||
lang=self.transcript_language,
|
||||
output_format=Transcript.SJSON,
|
||||
youtube_id=youtube_id,
|
||||
is_bumper=is_bumper
|
||||
)
|
||||
response = self.make_transcript_http_response(
|
||||
content,
|
||||
filename,
|
||||
@@ -298,7 +291,7 @@ class VideoStudentViewHandlers:
|
||||
mimetype,
|
||||
add_attachment_header=False
|
||||
)
|
||||
except (NotFoundError, TranscriptNotFoundError) as exc:
|
||||
except TranscriptNotFoundError as exc:
|
||||
edx_video_id = clean_video_id(self.edx_video_id)
|
||||
log.warning(
|
||||
'[Translation Dispatch] %s: %s',
|
||||
|
||||
Reference in New Issue
Block a user