-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat: Video editor supports transcripts [FC-0076] #36058
Open
ChrisChV
wants to merge
37
commits into
openedx:master
Choose a base branch
from
open-craft:chris/FAL-3989-video-transcripts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+533
−178
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
9cdf45f
feat: Updates to support save video with transcript in library home
ChrisChV 3885dd1
style: Fix lint
ChrisChV a723e96
feat: Updated code to get english transcript from filename
ChrisChV 1c2a575
style: Fix lint
ChrisChV 74f027f
feat: Upload transcript file as static asset in Learning Core in libr…
ChrisChV 2adacee
style: Fix lint
ChrisChV 0393829
feat: Updates to support download transcripts from youtube in vlibrar…
ChrisChV e27221e
style: Fix lint
ChrisChV 05067f6
test: Add test for download youtube transcripts in library content
ChrisChV 2f53a75
style: Fix lint
ChrisChV 5c6819a
feat: Support copy transcripts from a library
ChrisChV 95b51e8
refactor: Allow use edx_video_id (edxval) in new runtime
ChrisChV c42e223
refactor: Adds new edx_video_id when copy to course
ChrisChV 4bf3af3
refactor: Remove unnevessary code
ChrisChV 1de1d4e
feat: Support delete transcripts in library
ChrisChV a59898d
style: Fix lint
ChrisChV 9173ed8
Merge branch 'master' into chris/FAL-3989-video-transcripts
ChrisChV 590a5cd
style: Nits on the code
ChrisChV 0e54450
refactor: Update replace_transcript to verify transcript
ChrisChV 5685f16
refactor: Verify LibraryLocatorV2 in manage_video_subtitles_save to a…
ChrisChV e4f7c72
style: Add comment in transcripts_ajax.py
ChrisChV b478ac5
refactor: _get_item to avoid return isLibraryContent
ChrisChV 173a0af
refactor: studio_transcript to separate methods in separated functions
ChrisChV 4532a2a
refactor: Update code in video_handlers to avoid "static/None"
ChrisChV bb10d18
style: Fix nit
ChrisChV 0203dac
chore: Fix merge conflicts
ChrisChV a254fe4
refactor: Use usage_key in some places of the code
ChrisChV 34e5cbc
refactor: _import_transcripts created in helpers.py
ChrisChV c73f82c
refactor: save_video_transcript_in_learning_core created
ChrisChV ddb6953
refactor: _studio_transcript_upload in video_handlers
ChrisChV 46aa8ca
refactor: transcripts_ajax to avoid use edx_video_id in filenames in …
ChrisChV 5bb426f
refactor: Update _get_item in transcripts_ajax to use check_permissio…
ChrisChV 5dda777
refactor: Delete lib_permissions from content_libraries/api.py
ChrisChV 53f42fa
style: Fix typos in comments in video_handlers.py
ChrisChV 9c7e4e8
style: Update comment of test_export_to_xml_without_video_id
ChrisChV 8c6a3dd
fix: Fix tests and lint
ChrisChV 0745f09
fix: Sync transcripts in video blocks from library to course
ChrisChV File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import re | ||
|
||
from attrs import frozen, Factory | ||
from django.core.files.base import ContentFile | ||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.utils.translation import gettext as _ | ||
|
@@ -23,6 +24,12 @@ | |
from xmodule.exceptions import NotFoundError | ||
from xmodule.modulestore.django import modulestore | ||
from xmodule.xml_block import XmlMixin | ||
from xmodule.video_block.transcripts_utils import Transcript, build_components_import_path | ||
from edxval.api import ( | ||
create_external_video, | ||
create_or_update_video_transcript, | ||
delete_video_transcript, | ||
) | ||
|
||
from cms.djangoapps.models.settings.course_grading import CourseGradingModel | ||
from cms.lib.xblock.upstream_sync import UpstreamLink, UpstreamLinkException, fetch_customizable_fields | ||
|
@@ -274,8 +281,14 @@ def _insert_static_files_into_downstream_xblock( | |
course_key=downstream_xblock.context_key, | ||
staged_content_id=staged_content_id, | ||
static_files=static_files, | ||
usage_key=downstream_xblock.scope_ids.usage_id, | ||
usage_key=downstream_xblock.usage_key, | ||
) | ||
if downstream_xblock.usage_key.block_type == 'video': | ||
_import_transcripts( | ||
downstream_xblock, | ||
staged_content_id=staged_content_id, | ||
static_files=static_files, | ||
) | ||
|
||
# Rewrite the OLX's static asset references to point to the new | ||
# locations for those assets. See _import_files_into_course for more | ||
|
@@ -331,6 +344,13 @@ def import_staged_content_from_user_clipboard(parent_key: UsageKey, request) -> | |
tags=user_clipboard.content.tags, | ||
) | ||
|
||
usage_key = new_xblock.usage_key | ||
if usage_key.block_type == 'video': | ||
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. 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. Since that PR merged first, does this one need to be updated? |
||
# The edx_video_id must always be new so as not | ||
# to interfere with the data of the copied block | ||
new_xblock.edx_video_id = create_external_video(display_name='external video') | ||
store.update_item(new_xblock, request.user.id) | ||
|
||
notices = _insert_static_files_into_downstream_xblock(new_xblock, user_clipboard.content.id, request) | ||
|
||
return new_xblock, notices | ||
|
@@ -630,8 +650,8 @@ def _import_file_into_course( | |
# we're not going to attempt to change. | ||
if clipboard_file_path.startswith('static/'): | ||
# If it's in this form, it came from a library and assumes component-local assets | ||
file_path = clipboard_file_path.lstrip('static/') | ||
import_path = f"components/{usage_key.block_type}/{usage_key.block_id}/{file_path}" | ||
file_path = clipboard_file_path.removeprefix('static/') | ||
import_path = build_components_import_path(usage_key, file_path) | ||
filename = pathlib.Path(file_path).name | ||
new_key = course_key.make_asset_key("asset", import_path.replace("/", "_")) | ||
else: | ||
|
@@ -672,6 +692,62 @@ def _import_file_into_course( | |
return False, {} | ||
|
||
|
||
def _import_transcripts( | ||
block: XBlock, | ||
staged_content_id: int, | ||
static_files: list[content_staging_api.StagedContentFileData], | ||
): | ||
""" | ||
Adds transcripts to VAL using the new edx_video_id. | ||
""" | ||
for file_data_obj in static_files: | ||
clipboard_file_path = file_data_obj.filename | ||
data = content_staging_api.get_staged_content_static_file_data( | ||
staged_content_id, | ||
clipboard_file_path | ||
) | ||
if data is None: | ||
raise NotFoundError(file_data_obj.source_key) | ||
|
||
if clipboard_file_path.startswith('static/'): | ||
# If it's in this form, it came from a library and assumes component-local assets | ||
file_path = clipboard_file_path.removeprefix('static/') | ||
else: | ||
# Otherwise it came from a course... | ||
file_path = clipboard_file_path | ||
|
||
filename = pathlib.Path(file_path).name | ||
|
||
language_code = next((k for k, v in block.transcripts.items() if v == filename), None) | ||
if language_code: | ||
sjson_subs = Transcript.convert( | ||
content=data, | ||
input_format=Transcript.SRT, | ||
output_format=Transcript.SJSON | ||
).encode() | ||
create_or_update_video_transcript( | ||
video_id=block.edx_video_id, | ||
language_code=language_code, | ||
metadata={ | ||
'file_format': Transcript.SJSON, | ||
'language_code': language_code | ||
}, | ||
file_data=ContentFile(sjson_subs), | ||
) | ||
|
||
|
||
def clear_transcripts(block: XBlock): | ||
""" | ||
Deletes all transcripts of a video block | ||
""" | ||
for language_code in block.transcripts.keys(): | ||
delete_video_transcript( | ||
video_id=block.edx_video_id, | ||
language_code=language_code, | ||
) | ||
block.transcripts = {} | ||
|
||
|
||
def is_item_in_course_tree(item): | ||
""" | ||
Check that the item is in the course tree. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm seeing a bug when I sync a LibraryBlock video with transcripts from an upstream video.
Steps to reproduce:
Note that the transcripts are displaying fine here.
Note that the upstream video preview shows its transcripts fine, but the downstream (course) video preview doesn't show its transcripts anymore.
Note that the course video no longer shows its transcripts, but if you edit it, you can see they're still there.
Syncing.upstream.video.breaks.transcripts.mp4
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.
I think this is related to openedx/modular-learning#246
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.
@ChrisChV That could very well be.. however I don't think it's resolved by @DanielVZ96 's #36173, but it's also possible that I didn't merge conflicts accurately. cf my merged branch.
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.
@pomegranited To be safe, I will wait until #36173 is ready to fix this bug.
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.
No worries @ChrisChV , thank you for keeping an eye on this issue.
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.
Now that that other PR is merged, any update on this?
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.
@bradenmacdonald @pomegranited I fixed this on 0745f09. I need to add tests, but you can test the fix