-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Use singular transcript util to retrieve transcripts from contentstore #17851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| get_or_create_sjson, | ||
| generate_sjson_for_all_speeds, | ||
| get_video_transcript_content, | ||
| get_transcript_from_contentstore, | ||
| save_to_store, | ||
| subs_filename, | ||
| Transcript, | ||
|
|
@@ -288,11 +289,14 @@ def transcript(self, request, dispatch): | |
| self.transcript_language = language | ||
|
|
||
| try: | ||
| transcript = self.translation(request.GET.get('videoId', None), transcripts) | ||
| except (TypeError, TranscriptException, NotFoundError) as ex: | ||
| # Catching `TranscriptException` because its also getting raised at places | ||
| # when transcript is not found in contentstore. | ||
| log.debug(six.text_type(ex)) | ||
| transcript_content, __, mime_type = get_transcript_from_contentstore( | ||
| video=self, | ||
| language=language, | ||
| output_format=Transcript.SJSON, | ||
| transcripts_info=transcripts, | ||
| youtube_id=request.GET.get('videoId', None) | ||
| ) | ||
| except (TranscriptsGenerationException, UnicodeDecodeError, NotFoundError): | ||
| # Try to return static URL redirection as last resort | ||
| # if no translation is required | ||
| response = self.get_static_transcript(request, transcripts) | ||
|
|
@@ -314,25 +318,28 @@ def transcript(self, request, dispatch): | |
| log.info(six.text_type(ex)) | ||
| response = Response(status=404) | ||
| else: | ||
| response = Response(transcript, headerlist=[('Content-Language', language)]) | ||
| response.content_type = Transcript.mime_types['sjson'] | ||
| response = Response(transcript_content, headerlist=[('Content-Language', language)]) | ||
| response.content_type = mime_type | ||
|
|
||
| elif dispatch == 'download': | ||
|
|
||
| lang = request.GET.get('lang', None) | ||
| # Make sure the language is set. | ||
| if not lang: | ||
| lang = self.get_default_transcript_language(transcripts) | ||
|
|
||
| try: | ||
| transcript_content, transcript_filename, transcript_mime_type = self.get_transcript( | ||
| transcripts, transcript_format=self.transcript_download_format, lang=lang | ||
| output_format = self.transcript_download_format if self.transcript_download_format else Transcript.SRT | ||
| transcript_content, filename, mime_type = get_transcript_from_contentstore( | ||
| video=self, | ||
| language=lang, | ||
| output_format=output_format, | ||
| transcripts_info=transcripts | ||
| ) | ||
| except (KeyError, UnicodeDecodeError): | ||
| return Response(status=404) | ||
| except (ValueError, NotFoundError): | ||
| except (TranscriptsGenerationException, UnicodeDecodeError, NotFoundError): | ||
| response = Response(status=404) | ||
| # Check for transcripts in edx-val as a last resort if corresponding feature is enabled. | ||
| if feature_enabled: | ||
| # Make sure the language is set. | ||
| if not lang: | ||
| lang = self.get_default_transcript_language(transcripts) | ||
|
|
||
| transcript = get_video_transcript_content(edx_video_id=self.edx_video_id, language_code=lang) | ||
| if transcript: | ||
| transcript_conversion_props = dict(transcript, output_format=self.transcript_download_format) | ||
|
|
@@ -354,12 +361,12 @@ def transcript(self, request, dispatch): | |
| response = Response( | ||
| transcript_content, | ||
| headerlist=[ | ||
| ('Content-Disposition', 'attachment; filename="{}"'.format(transcript_filename.encode('utf8'))), | ||
| ('Content-Language', self.transcript_language), | ||
| ('Content-Disposition', 'attachment; filename="{}"'.format(filename.encode('utf8'))), | ||
| ('Content-Language', lang), | ||
| ], | ||
| charset='utf8' | ||
| ) | ||
| response.content_type = transcript_mime_type | ||
| response.content_type = mime_type | ||
|
|
||
| elif dispatch.startswith('available_translations'): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes in this file are different from what we did in https://github.com/edx/edx-platform/pull/17718. Is this intentionally? Changes in the https://github.com/edx/edx-platform/pull/17718 are final and should be used.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @muhammad-ammar this is temporary just to make sure that our contentstore part of the interface works as smooth as it should be! :) |
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we need to use
get_transcriptinstead ofget_transcript_from_contentstore?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I am only aiming for contentstore part of the interface. So that we may find some further unseen scenario(i.e. not covered by our util).