openedx.core.djangoapps.video_config package#
Submodules#
openedx.core.djangoapps.video_config.forms module#
Defines a form for providing validation of HLS Playback course-specific configuration.
- class openedx.core.djangoapps.video_config.forms.CourseHLSPlaybackFlagAdminForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)#
Bases:
CourseSpecificFlagAdminBaseFormForm for course-specific HLS Playback configuration.
- class Meta#
Bases:
object- fields = '__all__'#
- model#
alias of
CourseHLSPlaybackEnabledFlag
- base_fields = {'course_id': <django.forms.fields.CharField object>, 'enabled': <django.forms.fields.BooleanField object>}#
- declared_fields = {}#
- property media#
Return all media required to render the widgets on this form.
- class openedx.core.djangoapps.video_config.forms.CourseSpecificFlagAdminBaseForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)#
Bases:
ModelFormForm for course-specific feature configuration.
- base_fields = {}#
- clean_course_id()#
Validate the course id
- declared_fields = {}#
- property media#
Return all media required to render the widgets on this form.
- class openedx.core.djangoapps.video_config.forms.CourseVideoTranscriptFlagAdminForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)#
Bases:
CourseSpecificFlagAdminBaseFormForm for course-specific Video Transcript configuration.
- class Meta#
Bases:
object- fields = '__all__'#
- model#
alias of
CourseVideoTranscriptEnabledFlag
- base_fields = {'course_id': <django.forms.fields.CharField object>, 'enabled': <django.forms.fields.BooleanField object>}#
- declared_fields = {}#
- property media#
Return all media required to render the widgets on this form.
- class openedx.core.djangoapps.video_config.forms.CourseYoutubeBlockedFlagAdminForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)#
Bases:
CourseSpecificFlagAdminBaseFormForm for course-specific youtube blocking configuration.
- class Meta#
Bases:
object- fields = '__all__'#
- model#
alias of
CourseYoutubeBlockedFlag
- base_fields = {'course_id': <django.forms.fields.CharField object>, 'enabled': <django.forms.fields.BooleanField object>}#
- declared_fields = {}#
- property media#
Return all media required to render the widgets on this form.
openedx.core.djangoapps.video_config.models module#
Configuration models for Video XModule
- class openedx.core.djangoapps.video_config.models.CourseHLSPlaybackEnabledFlag(*args, **kwargs)#
Bases:
ConfigurationModelEnables HLS Playback for a specific course. Global feature must be enabled for this to take effect.
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- KEY_FIELDS = ('course_id',)#
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- change_date#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- changed_by#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- changed_by_id#
- course_id#
DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!
A placeholder class that provides a way to set the attribute on the model.
- enabled#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
- get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class openedx.core.djangoapps.video_config.models.CourseVideoTranscriptEnabledFlag(*args, **kwargs)#
Bases:
ConfigurationModelEnables Video Transcript for a specific course. Global feature must be enabled for this to take effect. When this feature is enabled, 3rd party transcript integration functionality would be available for the specific course and S3 video transcript would be served (currently as a fallback).
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- KEY_FIELDS = ('course_id',)#
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- change_date#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- changed_by#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- changed_by_id#
- course_id#
DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!
A placeholder class that provides a way to set the attribute on the model.
- enabled#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
- get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class openedx.core.djangoapps.video_config.models.CourseYoutubeBlockedFlag(*args, **kwargs)#
Bases:
ConfigurationModelDisables the playback of youtube videos for a given course. If the flag is present for the course, and set to “enabled”, then youtube is disabled for that course.
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- KEY_FIELDS = ('course_id',)#
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- change_date#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- changed_by#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- changed_by_id#
- course_id#
DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!
A placeholder class that provides a way to set the attribute on the model.
- enabled#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- classmethod feature_enabled(course_id)#
Determine if the youtube blocking feature is enabled for the specified course id. Argument:
course_id (CourseKey): course id for whom feature will be checked
- get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
- get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class openedx.core.djangoapps.video_config.models.HLSPlaybackEnabledFlag(*args, **kwargs)#
Bases:
ConfigurationModelEnables HLS Playback across the platform. When this feature flag is set to true, individual courses must also have HLS Playback enabled for this feature to take effect.
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- change_date#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- changed_by#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- changed_by_id#
- enabled#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- enabled_for_all_courses#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- classmethod feature_enabled(course_id)#
Looks at the currently active configuration model to determine whether the HLS Playback feature is available.
If the feature flag is not enabled, the feature is not available. If the flag is enabled for all the courses, feature is available. If the flag is enabled and the provided course_id is for an course
with HLS Playback enabled, the feature is available.
- Parameters:
course_id (CourseKey) – course id for whom feature will be checked.
- get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
- get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class openedx.core.djangoapps.video_config.models.MigrationEnqueuedCourse(*args, **kwargs)#
Bases:
TimeStampedModelTemporary model to persist the course IDs who has been enqueued for transcripts migration to S3.
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- command_run#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- course_id#
DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!
A placeholder class that provides a way to set the attribute on the model.
- created#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
- get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
- get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
- get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
- modified#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- class openedx.core.djangoapps.video_config.models.TranscriptMigrationSetting(*args, **kwargs)#
Bases:
ConfigurationModelArguments for the Transcript Migration management command
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- all_courses#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- batch_size#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- change_date#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- changed_by#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- changed_by_id#
- command_run#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- commit#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- course_ids#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- enabled#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- force_update#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
- get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- increment_run()#
Increments the run which indicates how many time the mgmt. command has run.
- class openedx.core.djangoapps.video_config.models.UpdatedCourseVideos(*args, **kwargs)#
Bases:
TimeStampedModelTemporary model to persist the course videos which have been enqueued to update video thumbnails.
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- command_run#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- course_id#
DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!
A placeholder class that provides a way to set the attribute on the model.
- created#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- edx_video_id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
- get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
- get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
- get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- modified#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- class openedx.core.djangoapps.video_config.models.VideoThumbnailSetting(*args, **kwargs)#
Bases:
ConfigurationModelArguments for the Video Thumbnail management command
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- all_course_videos#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- batch_size#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- change_date#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- changed_by#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- changed_by_id#
- command_run#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- commit#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- course_ids#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- enabled#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
- get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- increment_run()#
Increments the run which indicates the management command run count.
- offset#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- update_offset()#
- videos_per_task#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class openedx.core.djangoapps.video_config.models.VideoTranscriptEnabledFlag(*args, **kwargs)#
Bases:
ConfigurationModelEnables Video Transcript across the platform. When this feature flag is set to true, individual courses must also have Video Transcript enabled for this feature to take effect. When this feature is enabled, 3rd party transcript integration functionality would be available accross all courses or some specific courses and S3 video transcript would be served (currently as a fallback).
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- change_date#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- changed_by#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- changed_by_id#
- enabled#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- enabled_for_all_courses#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- classmethod feature_enabled(course_id)#
Looks at the currently active configuration model to determine whether the Video Transcript feature is available.
If the feature flag is not enabled, the feature is not available. If the flag is enabled for all the courses, feature is available. If the flag is enabled and the provided course_id is for an course
with Video Transcript enabled, the feature is available.
- Parameters:
course_id (CourseKey) – course id for whom feature will be checked.
- get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
- get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
openedx.core.djangoapps.video_config.services module#
Video Configuration Service for XBlock runtime.
This service provides video-related configuration and feature flags that are specific to the edx-platform implementation for the extracted video block in xblocks-contrib repository.
- class openedx.core.djangoapps.video_config.services.VideoConfigService#
Bases:
objectService for providing video-related configuration and feature flags.
This service abstracts away edx-platform specific functionality that the Video XBlock needs, allowing the Video XBlock to be extracted to a separate repository.
TODO: This service could be improved in a few ways: openedx/edx-platform#37656
- available_translations(video_block, transcripts: dict[str, Any], verify_assets: bool | None = None, is_bumper: bool = False) list[str]#
Return a list of language codes for which we have transcripts.
- Parameters:
video_block – The video XBlock instance
transcripts (dict) – A dict with all transcripts and a sub.
verify_assets (boolean) –
If True, checks to ensure that the transcripts really exist in the contentstore. If False, we just look at the VideoBlock fields and do not query the contentstore. One reason we might do this is to avoid slamming contentstore() with queries when trying to make a listing of videos and their languages.
Defaults to not FALLBACK_TO_ENGLISH_TRANSCRIPTS.
is_bumper (boolean) – If True, indicates this is a bumper video.
- Returns:
List of language codes for available transcripts.
- Return type:
list[str]
- delete_transcript(*, video_block, edx_video_id: str | None, language_code: str) None#
Delete a transcript from the runtime’s storage.
- get_public_sharing_context(video_block, course_key: CourseKey) dict#
Get the complete public sharing context for a video.
- Parameters:
video_block – The video XBlock instance
course_key – The course identifier
- Returns:
Context dictionary with sharing information, empty if sharing is disabled
- Return type:
dict
- get_public_video_url(usage_id: UsageKey) str#
Returns the public video url
- get_transcript(video_block, 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.
- Returns:
transcript content, filename, and mimetype.
- Return type:
tuple(bytes, str, str)
- Raises:
TranscriptsGenerationException – If the transcript cannot be found or retrieved
TranscriptNotFoundError – If the transcript cannot be found or retrieved
- handle_editor_saved(video_block, user_id: int, old_metadata: dict | None)#
Handle video block editor save operations. Used to update video values during save method from CMS.
- is_hls_playback_enabled(course_id: CourseKey) bool#
Check if HLS playback is enabled for the course.
- is_transcript_feedback_enabled(course_id: CourseKey) bool#
Check if transcript feedback is enabled for the course.
- is_youtube_blocked_for_course(course_id: CourseKey) bool#
Check if YouTube is blocked for the course.
- is_youtube_deprecated(course_id: CourseKey) bool#
Check if YouTube is deprecated for the course.
- upload_transcript(*, video_block, language_code: str, new_language_code: str | None, transcript_file: File, edx_video_id: str | None) None#
Store a transcript, however the runtime prefers to.
Mutates: * video_block.transcripts * video_block.edx_video_id, iff a new video is created in edx-val.
Can raise: * UnicodeDecodeError * TranscriptsGenerationException
openedx.core.djangoapps.video_config.sharing module#
Provides utility methods for video sharing functionality.
- openedx.core.djangoapps.video_config.sharing.get_course_video_sharing_override(usage_key: UsageKey) str | None#
Return course video sharing options override
- openedx.core.djangoapps.video_config.sharing.get_public_video_url(usage_id: UsageKey) str#
Returns the public video url
- openedx.core.djangoapps.video_config.sharing.is_public_sharing_enabled(usage_key: UsageKey, public_access: bool) bool#
Check if public sharing is enabled for a video.
- Parameters:
usage_key – The usage key of the video block
public_access – Whether the video block has public access enabled
openedx.core.djangoapps.video_config.sharing_sites module#
Defines the sharing sites for different social media platforms
- class openedx.core.djangoapps.video_config.sharing_sites.SharingSiteConfig(name, fa_icon_name, url_param_name, base_share_url, additional_site_params)#
Bases:
tuple- additional_site_params#
Alias for field number 4
Alias for field number 3
- fa_icon_name#
Alias for field number 1
- name#
Alias for field number 0
- url_param_name#
Alias for field number 2
Generate the text we will pre-populate when sharing a post to social media.
NOTE: Most of the time, we will have all info of these, but have provided reasonable fallbacks in case some are missing.
- openedx.core.djangoapps.video_config.sharing_sites.sharing_sites_info_for_video(video_public_url, organization=None)#
Returns a list of dicts, each containing the name, fa_icon_name, and sharing_url
- openedx.core.djangoapps.video_config.sharing_sites.sharing_url(video_public_url, sharing_site_config, organization=None)#
Returns the sharing url with the appropriate parameters
openedx.core.djangoapps.video_config.toggles module#
Video config toggles
- openedx.core.djangoapps.video_config.toggles.use_xpert_translations_component(course_key)#
Returns a boolean if xpert translations ui component is enabled
openedx.core.djangoapps.video_config.transcripts_utils module#
Utility functions for transcripts.#
- exception openedx.core.djangoapps.video_config.transcripts_utils.GetTranscriptsFromYouTubeException#
Bases:
Exception
- class openedx.core.djangoapps.video_config.transcripts_utils.Transcript#
Bases:
objectContainer for transcript methods.
- SJSON = 'sjson'#
- SRT = 'srt'#
- TXT = 'txt'#
- static asset(location, subs_id, lang='en', filename=None)#
Get asset from contentstore, asset location is built from subs_id and lang.
location is block location.
- static asset_location(location, filename)#
Return asset location. location is block location.
- static convert(content, input_format, output_format)#
Convert transcript content from input_format to output_format.
Accepted input formats: sjson, srt. Accepted output format: srt, txt, sjson.
- Raises:
TranscriptsGenerationException – On parsing the invalid srt content during conversion from srt to sjson.
- static delete_asset(location, filename)#
Delete asset by location and filename.
- static get_asset(location, filename)#
Return asset by location and filename.
- mime_types = {'sjson': 'application/json', 'srt': 'application/x-subrip; charset=utf-8', 'txt': 'text/plain; charset=utf-8'}#
- exception openedx.core.djangoapps.video_config.transcripts_utils.TranscriptException#
Bases:
Exception
- exception openedx.core.djangoapps.video_config.transcripts_utils.TranscriptsRequestValidationException#
Bases:
Exception
- class openedx.core.djangoapps.video_config.transcripts_utils.VideoTranscriptsMixin#
Bases:
objectMixin class for transcript functionality.
This is necessary for VideoBlock.
- get_default_transcript_language(transcripts, dest_lang=None)#
Returns the default transcript language for this video block.
- Parameters:
transcripts (dict) – A dict with all transcripts and a sub.
dest_lang (unicode) – language coming from unit translation language selector.
- get_transcripts_info(is_bumper=False)#
Returns a transcript dictionary for the video.
- Parameters:
is_bumper (bool) – If True, the request is for the bumper transcripts
include_val_transcripts (bool) – If True, include edx-val transcripts as well
- openedx.core.djangoapps.video_config.transcripts_utils.build_components_import_path(usage_key, file_path)#
Build components import path
- openedx.core.djangoapps.video_config.transcripts_utils.clean_video_id(edx_video_id)#
Cleans an edx video ID.
- Parameters:
edx_video_id (unicode) – edx-val’s video identifier
- openedx.core.djangoapps.video_config.transcripts_utils.clear_transcripts(block)#
Deletes all transcripts of a video block from VAL
- openedx.core.djangoapps.video_config.transcripts_utils.convert_video_transcript(file_name, content, output_format)#
Convert video transcript into desired format
- Parameters:
file_name – name of transcript file along with its extension
content – transcript content stream
output_format – the format in which transcript will be converted
- Returns:
A dict containing the new transcript filename and the content converted into desired format.
- openedx.core.djangoapps.video_config.transcripts_utils.download_youtube_subs(youtube_id, video_block, settings)#
Download transcripts from Youtube.
- Parameters:
youtube_id – str, actual youtube_id of the video.
video_block – video block instance.
We save transcripts for 1.0 speed, as for other speed conversion is done on front-end.
- Returns:
Serialized sjson transcript content, if transcripts were successfully downloaded and saved.
- Raises:
GetTranscriptsFromYouTubeException, if fails. –
- openedx.core.djangoapps.video_config.transcripts_utils.exception_decorator(func)#
Generate NotFoundError for TranscriptsGenerationException, UnicodeDecodeError.
Args: func: Input function
Returns: ‘wrapper’: Decorated function
- openedx.core.djangoapps.video_config.transcripts_utils.generate_sjson_for_all_speeds(block, user_filename, result_subs_dict, lang)#
Generates sjson from srt for given lang.
- openedx.core.djangoapps.video_config.transcripts_utils.generate_sjson_from_srt(srt_subs)#
Generate transcripts from sjson to SubRip (*.srt).
- Parameters:
srt_subs (SubRip) – “SRT” subs object
- Returns:
Subs converted to “SJSON” format.
- openedx.core.djangoapps.video_config.transcripts_utils.generate_srt_from_sjson(sjson_subs, speed)#
Generate transcripts with speed = 1.0 from sjson to SubRip (*.srt).
- Parameters:
sjson_subs – “sjson” subs.
speed – speed of sjson_subs.
- Returns:
“srt” subs.
- openedx.core.djangoapps.video_config.transcripts_utils.generate_subs(speed, source_speed, source_subs)#
Generate transcripts from one speed to another speed.
Args: speed: float, for this speed subtitles will be generated, source_speed: float, speed of source_subs source_subs: dict, existing subtitles for speed source_speed.
Returns: subs: dict, actual subtitles.
- openedx.core.djangoapps.video_config.transcripts_utils.generate_subs_from_source(speed_subs, subs_type, subs_filedata, block, language='en')#
Generate transcripts from source files (like SubRip format, etc.) and save them to assets for item module. We expect, that speed of source subs equal to 1
- Parameters:
speed_subs – dictionary {speed: sub_id, …}
subs_type – type of source subs: “srt”, …
:param subs_filedata:unicode, content of source subs. :param block: course or block. :param language: str, language of translation of transcripts :returns: True, if all subs are generated and saved successfully.
- openedx.core.djangoapps.video_config.transcripts_utils.get_available_transcript_languages(edx_video_id)#
Gets available transcript languages for a video.
- Parameters:
edx_video_id (unicode) – edx-val’s video identifier
- Returns:
A list containing distinct transcript language codes against all the passed video ids.
- openedx.core.djangoapps.video_config.transcripts_utils.get_endonym_or_label(language_code)#
Given a language code, attempt to look up the endonym, or local name, for that language
- openedx.core.djangoapps.video_config.transcripts_utils.get_html5_ids(html5_sources)#
Helper method to parse out an HTML5 source into the ideas NOTE: This assumes that ‘/’ are not in the filename
- openedx.core.djangoapps.video_config.transcripts_utils.get_transcript(video, lang=None, output_format='srt', youtube_id=None, is_bumper=False)#
Get video transcript from edx-val or content store.
- Parameters:
video (Video block) – Video block
lang (unicode) – transcript language
output_format (unicode) – transcript output format
youtube_id (unicode) – youtube video id
- Returns:
tuple containing content, filename, mimetype
- openedx.core.djangoapps.video_config.transcripts_utils.get_transcript_for_video(video_location, subs_id, file_name, language)#
Get video transcript from content store. This is a lower level function and is used by get_transcript_from_contentstore. Prefer that function instead where possible. If you need to support getting transcripts from VAL or openedx_content as well, use the get_transcript function instead.
NOTE: Transcripts can be searched from content store by two ways: 1. by an id(a.k.a subs_id) which will be used to construct transcript filename 2. by providing transcript filename
- Parameters:
video_location (Locator) – Video location
subs_id (unicode) – id for a transcript in content store
file_name (unicode) – file_name for a transcript in content store
language (unicode) – transcript language
- Returns:
tuple containing transcript input_format, basename, content
- openedx.core.djangoapps.video_config.transcripts_utils.get_transcript_from_contentstore(video, language, output_format, transcripts_info, youtube_id=None)#
Get video transcript from content store.
- Parameters:
video (Video block) – Video block
language (unicode) – transcript language
output_format (unicode) – transcript output format
transcripts_info (dict) – transcript info for a video
youtube_id (unicode) – youtube video id
- Returns:
tuple containing content, filename, mimetype
- openedx.core.djangoapps.video_config.transcripts_utils.get_transcript_from_openedx_content(video_block, language, output_format, transcripts_info)#
Get video transcript from the openedx_content API.
Limitation: This is only going to grab from the Draft version.
openedx_content models a VideoBlock’s data in a more generic thing it calls a Component. Each Component has its own virtual space for file-like data. The OLX for the VideoBlock itself is stored at the root of that space, as
block.xml. Static assets that are meant to be user-downloadable are placed in a static/ directory for that Component, and this is where we expect to store transcript files.So if there is a
video1-en.srtfile for a particular VideoBlock, we expect that to be stored asstatic/video1-en.srtin the Component. Any other downloadable files would be here as well, such as thumbnails.Video XBlocks in Blockstore must set the ‘transcripts’ XBlock field to a JSON dictionary listing the filename of the transcript for each language:
- <video
youtube_id_1_0=”3_yD_cEKoCk” transcripts=’{“en”: “3_yD_cEKoCk-en.srt”}’ display_name=”Welcome Video with Transcript” download_track=”true”
/>
This method is tested in openedx/core/djangoapps/content_libraries/tests/test_static_assets.py
- Parameters:
video_block (Video XBlock) – The video XBlock
language (str) – transcript language
output_format (str) – transcript output format
transcripts_info (dict) – transcript info for a video, from video_block.get_transcripts_info()
- Returns:
tuple containing content, filename, mimetype
- openedx.core.djangoapps.video_config.transcripts_utils.get_transcript_from_val(edx_video_id, lang=None, output_format='srt')#
Get video transcript from edx-val. :param edx_video_id: video identifier :type edx_video_id: unicode :param lang: transcript language :type lang: unicode :param output_format: transcript output format :type output_format: unicode
- Returns:
tuple containing content, filename, mimetype
- openedx.core.djangoapps.video_config.transcripts_utils.get_transcript_from_youtube(link, youtube_id, i18n)#
Gets transcripts from youtube for youtube_id.
Parses only utf-8 encoded transcripts. Other encodings are not supported at the moment.
Returns (status, transcripts): bool, dict.
- openedx.core.djangoapps.video_config.transcripts_utils.get_transcript_link_from_youtube(youtube_id)#
Get the link for YouTube transcript by parsing the source of the YouTube webpage. Inside the webpage, the details of the transcripts are located in a JSON object. After prettifying the object, it looks like:
- “captions”: {
- “playerCaptionsTracklistRenderer”: {
- “captionTracks”: [
- {
“baseUrl”: “…”, “name”: {
“simpleText”: “(Japanese in local language)”
}, “vssId”: “.ja”, “languageCode”: “ja”, “isTranslatable”: true
}, {
“baseUrl”: “…”, “name”: {
“simpleText”: “(French in local language)”
}, “vssId”: “.fr”, “languageCode”: “fr”, “isTranslatable”: true
}, {
“baseUrl”: “…”, “name”: {
“simpleText”: “(English in local language)”
}, “vssId”: “.en”, “languageCode”: “en”, “isTranslatable”: true
], “audioTracks”: […] “translationLanguages”: …
}
So we use a regex to find the captionTracks JavaScript array, and then convert it to a Python dict and return the link for en caption
- openedx.core.djangoapps.video_config.transcripts_utils.get_transcript_links_from_youtube(youtube_id, settings, i18n, youtube_transcript_name='')#
Gets transcripts from youtube for youtube_id.
Parses only utf-8 encoded transcripts. Other encodings are not supported at the moment.
Returns (status, transcripts): bool, dict.
- openedx.core.djangoapps.video_config.transcripts_utils.get_video_ids_info(edx_video_id, youtube_id_1_0, html5_sources)#
Returns list internal or external video ids.
- Parameters:
edx_video_id (unicode) – edx_video_id
youtube_id_1_0 (unicode) – youtube id
html5_sources (list) – html5 video ids
- Returns:
external or internal, video ids list
- Return type:
tuple
- openedx.core.djangoapps.video_config.transcripts_utils.get_video_transcript_content(edx_video_id, language_code)#
Gets video transcript content, only if the corresponding feature flag is enabled for the given course_id.
- Parameters:
language_code (unicode) – Language code of the requested transcript
edx_video_id (unicode) – edx-val’s video identifier
- Returns:
A dict containing transcript’s file name and its sjson content.
- openedx.core.djangoapps.video_config.transcripts_utils.manage_video_subtitles_save(item, user_id, old_metadata=None, generate_translation=False)#
Does some specific things, that can be done only on save.
Video player item has some video fields: HTML5 ones and Youtube one.
If value of sub field of new_item is cleared, transcripts should be removed.
item is video block instance with updated values of fields, but actually have not been saved to store yet.
old_metadata contains old values of XFields.
# 1. convert /static/filename.srt to filename.srt in self.transcripts. (it is done to allow user to enter both /static/filename.srt and filename.srt)
# 2. Generate transcripts translation only when user clicks save button, not while switching tabs. a) delete sjson translation for those languages, which were removed from item.transcripts.
Note: we are not deleting old SRT files to give user more flexibility.
- For all SRT files in`item.transcripts` regenerate new SJSON files.
(To avoid confusing situation if you attempt to correct a translation by uploading a new version of the SRT file with same name).
- openedx.core.djangoapps.video_config.transcripts_utils.remove_subs_from_store(subs_id, item, lang='en')#
Remove from store, if transcripts content exists.
- openedx.core.djangoapps.video_config.transcripts_utils.resolve_language_code_to_transcript_code(transcripts, dest_lang)#
Attempts to match the requested dest lang with the existing transcript languages
- openedx.core.djangoapps.video_config.transcripts_utils.save_subs_to_store(subs, subs_id, item, language='en')#
Save transcripts into StaticContent.
Args: subs_id: str, subtitles id item: video block instance language: two chars str (‘uk’), language of translation of transcripts
Returns: location of saved subtitles.
- openedx.core.djangoapps.video_config.transcripts_utils.save_to_store(content, name, mime_type, location)#
Save named content to store by location.
Returns location of saved content.
- openedx.core.djangoapps.video_config.transcripts_utils.subs_filename(subs_id, lang='en')#
Generate proper filename for storage.
- openedx.core.djangoapps.video_config.transcripts_utils.youtube_speed_dict(item)#
Returns {speed: youtube_ids, …} dict for existing youtube_ids