Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
04bf165e
Unverified
Commit
04bf165e
authored
7 years ago
by
Muhammad Ammar
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #17696 from edx/ammar/update-transcripts-util
update get_transcript util
parents
82d5bef4
f6315483
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cms/djangoapps/contentstore/tests/test_transcripts_utils.py
+17
-19
17 additions, 19 deletions
cms/djangoapps/contentstore/tests/test_transcripts_utils.py
common/lib/xmodule/xmodule/video_module/transcripts_utils.py
+19
-14
19 additions, 14 deletions
common/lib/xmodule/xmodule/video_module/transcripts_utils.py
with
36 additions
and
33 deletions
cms/djangoapps/contentstore/tests/test_transcripts_utils.py
+
17
−
19
View file @
04bf165e
...
...
@@ -760,7 +760,11 @@ class TestGetTranscript(SharedModuleStoreTestCase):
self
.
user
=
UserFactory
.
create
()
self
.
vertical
=
ItemFactory
.
create
(
category
=
'
vertical
'
,
parent_location
=
self
.
course
.
location
)
self
.
video
=
ItemFactory
.
create
(
category
=
'
video
'
,
parent_location
=
self
.
vertical
.
location
)
self
.
video
=
ItemFactory
.
create
(
category
=
'
video
'
,
parent_location
=
self
.
vertical
.
location
,
edx_video_id
=
u
'
1234-5678-90
'
)
def
create_transcript
(
self
,
subs_id
,
language
=
u
'
en
'
,
filename
=
'
video.srt
'
):
"""
...
...
@@ -774,7 +778,8 @@ class TestGetTranscript(SharedModuleStoreTestCase):
category
=
'
video
'
,
parent_location
=
self
.
vertical
.
location
,
sub
=
subs_id
,
transcripts
=
transcripts
transcripts
=
transcripts
,
edx_video_id
=
u
'
1234-5678-90
'
)
if
subs_id
:
...
...
@@ -823,7 +828,10 @@ class TestGetTranscript(SharedModuleStoreTestCase):
Verify that `NotFoundError` exception is raised when transcript is not found in both the content store and val.
"""
with
self
.
assertRaises
(
NotFoundError
):
transcripts_utils
.
get_transcript
(
self
.
course
.
id
,
self
.
video
.
location
.
block_id
,
lang
=
lang
)
transcripts_utils
.
get_transcript
(
self
.
video
,
lang
=
lang
)
@ddt.data
(
{
...
...
@@ -845,8 +853,7 @@ class TestGetTranscript(SharedModuleStoreTestCase):
self
.
upload_file
(
self
.
create_srt_file
(
self
.
subs_srt
),
self
.
video
.
location
,
filename
)
self
.
create_transcript
(
subs_id
,
language
,
filename
)
content
,
filename
,
mimetype
=
transcripts_utils
.
get_transcript
(
self
.
course
.
id
,
self
.
video
.
location
.
block_id
,
self
.
video
,
language
)
...
...
@@ -861,8 +868,7 @@ class TestGetTranscript(SharedModuleStoreTestCase):
language
=
u
'
ur
'
self
.
create_transcript
(
self
.
subs_id
,
language
)
content
,
filename
,
mimetype
=
transcripts_utils
.
get_transcript
(
self
.
course
.
id
,
self
.
video
.
location
.
block_id
,
self
.
video
,
language
,
output_format
=
transcripts_utils
.
Transcript
.
SJSON
)
...
...
@@ -871,10 +877,6 @@ class TestGetTranscript(SharedModuleStoreTestCase):
self
.
assertEqual
(
filename
,
'
ur_video_101.sjson
'
)
self
.
assertEqual
(
mimetype
,
self
.
sjson_mime_type
)
@patch
(
'
openedx.core.djangoapps.video_config.models.VideoTranscriptEnabledFlag.feature_enabled
'
,
Mock
(
return_value
=
True
),
)
@patch
(
'
xmodule.video_module.transcripts_utils.get_video_transcript_content
'
)
def
test_get_transcript_from_val
(
self
,
mock_get_video_transcript_content
):
"""
...
...
@@ -886,8 +888,7 @@ class TestGetTranscript(SharedModuleStoreTestCase):
}
content
,
filename
,
mimetype
=
transcripts_utils
.
get_transcript
(
self
.
course
.
id
,
self
.
video
.
location
.
block_id
,
self
.
video
,
)
self
.
assertEqual
(
content
,
self
.
subs_srt
)
self
.
assertEqual
(
filename
,
'
edx.srt
'
)
...
...
@@ -899,8 +900,7 @@ class TestGetTranscript(SharedModuleStoreTestCase):
"""
with
self
.
assertRaises
(
NotFoundError
)
as
invalid_format_exception
:
transcripts_utils
.
get_transcript
(
self
.
course
.
id
,
self
.
video
.
location
.
block_id
,
self
.
video
,
'
ur
'
,
output_format
=
'
mpeg
'
)
...
...
@@ -917,8 +917,7 @@ class TestGetTranscript(SharedModuleStoreTestCase):
with
self
.
assertRaises
(
NotFoundError
)
as
no_content_exception
:
transcripts_utils
.
get_transcript
(
self
.
course
.
id
,
self
.
video
.
location
.
block_id
,
self
.
video
,
'
ur
'
)
...
...
@@ -933,8 +932,7 @@ class TestGetTranscript(SharedModuleStoreTestCase):
self
.
store
.
update_item
(
self
.
video
,
self
.
user
.
id
)
with
self
.
assertRaises
(
NotFoundError
)
as
no_en_transcript_exception
:
transcripts_utils
.
get_transcript
(
self
.
course
.
id
,
self
.
video
.
location
.
block_id
,
self
.
video
,
'
en
'
)
...
...
This diff is collapsed.
Click to expand it.
common/lib/xmodule/xmodule/video_module/transcripts_utils.py
+
19
−
14
View file @
04bf165e
...
...
@@ -904,6 +904,8 @@ def get_transcript_for_video(video_location, subs_id, file_name, language):
tuple containing transcript input_format, basename, content
"""
try
:
if
subs_id
is
None
:
raise
NotFoundError
content
=
Transcript
.
asset
(
video_location
,
subs_id
,
language
).
data
base_name
=
subs_id
input_format
=
Transcript
.
SJSON
...
...
@@ -915,7 +917,7 @@ def get_transcript_for_video(video_location, subs_id, file_name, language):
return
input_format
,
base_name
,
content
def
get_transcript_from_contentstore
(
video
,
language
,
output_format
,
youtube_id
=
None
,
is_bumper
=
Fals
e
):
def
get_transcript_from_contentstore
(
video
,
language
,
output_format
,
transcripts_info
,
youtube_id
=
Non
e
):
"""
Get video transcript from content store.
...
...
@@ -923,8 +925,8 @@ def get_transcript_from_contentstore(video, language, output_format, youtube_id=
video (Video Descriptor): Video descriptor
language (unicode): transcript language
output_format (unicode): transcript output format
transcripts_info (dict): transcript info for a video
youtube_id (unicode): youtube video id
is_bumper (bool): indicates bumper video
Returns:
tuple containing content, filename, mimetype
...
...
@@ -932,7 +934,6 @@ def get_transcript_from_contentstore(video, language, output_format, youtube_id=
if
output_format
not
in
(
Transcript
.
SRT
,
Transcript
.
SJSON
,
Transcript
.
TXT
):
raise
NotFoundError
(
'
Invalid transcript format `{output_format}`
'
.
format
(
output_format
=
output_format
))
transcripts_info
=
video
.
get_transcripts_info
(
is_bumper
=
is_bumper
)
sub
,
other_languages
=
transcripts_info
[
'
sub
'
],
transcripts_info
[
'
transcripts
'
]
transcripts
=
dict
(
other_languages
)
...
...
@@ -949,8 +950,8 @@ def get_transcript_from_contentstore(video, language, output_format, youtube_id=
try
:
input_format
,
base_name
,
transcript_content
=
get_transcript_for_video
(
video
.
location
,
subs_id
=
transcripts
[
'
en
'
]
,
file_name
=
language
and
transcripts
[
language
],
subs_id
=
transcripts
.
get
(
'
en
'
)
,
file_name
=
transcripts
[
language
],
language
=
language
)
except
KeyError
:
...
...
@@ -973,29 +974,33 @@ def get_transcript_from_contentstore(video, language, output_format, youtube_id=
return
transcript_content
,
transcript_name
,
Transcript
.
mime_types
[
output_format
]
def
get_transcript
(
course_id
,
block_id
,
lang
=
None
,
output_format
=
Transcript
.
SRT
,
is_bumper
=
Fals
e
):
def
get_transcript
(
video
,
lang
=
None
,
output_format
=
Transcript
.
SRT
,
youtube_id
=
Non
e
):
"""
Get video transcript from edx-val or content store.
Arguments:
course_id (CourseLocator): course identifier
block_id (unicode): a unique identifier for an item in modulestore
video (Video Descriptor): Video Descriptor
lang (unicode): transcript language
output_format (unicode): transcript output format
is_bumper (bool): indicates bumper
video
youtube_id (unicode): youtube
video
id
Returns:
tuple containing content, filename, mimetype
"""
usage_key
=
BlockUsageLocator
(
course_id
,
block_type
=
'
video
'
,
block_id
=
block_id
)
video_descriptor
=
modulestore
().
get_item
(
usage_key
)
transcripts_info
=
video
.
get_transcripts_info
()
if
not
lang
:
lang
=
video
.
get_default_transcript_language
(
transcripts_info
)
try
:
return
get_transcript_from_val
(
video_descriptor
.
edx_video_id
,
lang
,
output_format
)
edx_video_id
=
clean_video_id
(
video
.
edx_video_id
)
if
not
edx_video_id
:
raise
NotFoundError
return
get_transcript_from_val
(
edx_video_id
,
lang
,
output_format
)
except
NotFoundError
:
return
get_transcript_from_contentstore
(
video
_descriptor
,
video
,
lang
,
youtube_id
=
youtube_id
,
output_format
=
output_format
,
is_bumper
=
is_bumper
transcripts_info
=
transcripts_info
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment