Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
0ff62e76
Commit
0ff62e76
authored
Mar 09, 2017
by
Qubad786
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prioritize youtube transcripts over html5 ones
parent
173e5922
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
31 deletions
+87
-31
cms/djangoapps/contentstore/views/tests/test_transcripts.py
+83
-30
common/lib/xmodule/xmodule/video_module/transcripts_utils.py
+4
-1
No files found.
cms/djangoapps/contentstore/views/tests/test_transcripts.py
View file @
0ff62e76
...
@@ -40,6 +40,20 @@ class BaseTranscripts(CourseTestCase):
...
@@ -40,6 +40,20 @@ class BaseTranscripts(CourseTestCase):
except
NotFoundError
:
except
NotFoundError
:
pass
pass
def
save_subs_to_store
(
self
,
subs
,
subs_id
):
"""
Save transcripts into `StaticContent`.
"""
filedata
=
json
.
dumps
(
subs
,
indent
=
2
)
mime_type
=
'application/json'
filename
=
'subs_{0}.srt.sjson'
.
format
(
subs_id
)
content_location
=
StaticContent
.
compute_location
(
self
.
course
.
id
,
filename
)
content
=
StaticContent
(
content_location
,
filename
,
mime_type
,
filedata
)
contentstore
()
.
save
(
content
)
del_cached_content
(
content_location
)
return
content_location
def
setUp
(
self
):
def
setUp
(
self
):
"""Create initial data."""
"""Create initial data."""
super
(
BaseTranscripts
,
self
)
.
setUp
()
super
(
BaseTranscripts
,
self
)
.
setUp
()
...
@@ -82,8 +96,9 @@ class BaseTranscripts(CourseTestCase):
...
@@ -82,8 +96,9 @@ class BaseTranscripts(CourseTestCase):
class
TestUploadTranscripts
(
BaseTranscripts
):
class
TestUploadTranscripts
(
BaseTranscripts
):
"""Tests for '/transcripts/upload' url."""
"""
Tests for '/transcripts/upload' url.
"""
def
setUp
(
self
):
def
setUp
(
self
):
"""Create initial data."""
"""Create initial data."""
super
(
TestUploadTranscripts
,
self
)
.
setUp
()
super
(
TestUploadTranscripts
,
self
)
.
setUp
()
...
@@ -347,20 +362,9 @@ class TestUploadTranscripts(BaseTranscripts):
...
@@ -347,20 +362,9 @@ class TestUploadTranscripts(BaseTranscripts):
class
TestDownloadTranscripts
(
BaseTranscripts
):
class
TestDownloadTranscripts
(
BaseTranscripts
):
"""Tests for '/transcripts/download' url."""
"""
Tests for '/transcripts/download' url.
def
save_subs_to_store
(
self
,
subs
,
subs_id
):
"""
"""Save transcripts into `StaticContent`."""
filedata
=
json
.
dumps
(
subs
,
indent
=
2
)
mime_type
=
'application/json'
filename
=
'subs_{0}.srt.sjson'
.
format
(
subs_id
)
content_location
=
StaticContent
.
compute_location
(
self
.
course
.
id
,
filename
)
content
=
StaticContent
(
content_location
,
filename
,
mime_type
,
filedata
)
contentstore
()
.
save
(
content
)
del_cached_content
(
content_location
)
return
content_location
def
test_success_download_youtube
(
self
):
def
test_success_download_youtube
(
self
):
self
.
item
.
data
=
'<video youtube="1:JMD_ifUUfsU" />'
self
.
item
.
data
=
'<video youtube="1:JMD_ifUUfsU" />'
modulestore
()
.
update_item
(
self
.
item
,
self
.
user
.
id
)
modulestore
()
.
update_item
(
self
.
item
,
self
.
user
.
id
)
...
@@ -523,20 +527,9 @@ class TestDownloadTranscripts(BaseTranscripts):
...
@@ -523,20 +527,9 @@ class TestDownloadTranscripts(BaseTranscripts):
class
TestCheckTranscripts
(
BaseTranscripts
):
class
TestCheckTranscripts
(
BaseTranscripts
):
"""Tests for '/transcripts/check' url."""
"""
Tests for '/transcripts/check' url.
def
save_subs_to_store
(
self
,
subs
,
subs_id
):
"""
"""Save transcripts into `StaticContent`."""
filedata
=
json
.
dumps
(
subs
,
indent
=
2
)
mime_type
=
'application/json'
filename
=
'subs_{0}.srt.sjson'
.
format
(
subs_id
)
content_location
=
StaticContent
.
compute_location
(
self
.
course
.
id
,
filename
)
content
=
StaticContent
(
content_location
,
filename
,
mime_type
,
filedata
)
contentstore
()
.
save
(
content
)
del_cached_content
(
content_location
)
return
content_location
def
test_success_download_nonyoutube
(
self
):
def
test_success_download_nonyoutube
(
self
):
subs_id
=
str
(
uuid4
())
subs_id
=
str
(
uuid4
())
self
.
item
.
data
=
textwrap
.
dedent
(
"""
self
.
item
.
data
=
textwrap
.
dedent
(
"""
...
@@ -766,3 +759,63 @@ class TestCheckTranscripts(BaseTranscripts):
...
@@ -766,3 +759,63 @@ class TestCheckTranscripts(BaseTranscripts):
resp
=
self
.
client
.
get
(
link
,
{
'data'
:
json
.
dumps
(
data
)})
resp
=
self
.
client
.
get
(
link
,
{
'data'
:
json
.
dumps
(
data
)})
self
.
assertEqual
(
resp
.
status_code
,
400
)
self
.
assertEqual
(
resp
.
status_code
,
400
)
self
.
assertEqual
(
json
.
loads
(
resp
.
content
)
.
get
(
'status'
),
'Transcripts are supported only for "video" modules.'
)
self
.
assertEqual
(
json
.
loads
(
resp
.
content
)
.
get
(
'status'
),
'Transcripts are supported only for "video" modules.'
)
class
TestSaveTranscripts
(
BaseTranscripts
):
"""
Tests for '/transcripts/save' url.
"""
def
assert_current_subs
(
self
,
expected_subs
):
"""
Asserts the current subtitles set on the video module.
Arguments:
expected_subs (String): Expected current subtitles for video.
"""
item
=
modulestore
()
.
get_item
(
self
.
video_usage_key
)
self
.
assertEqual
(
item
.
sub
,
expected_subs
)
def
test_prioritize_youtube_sub_on_save
(
self
):
"""
Test that the '/transcripts/save' endpoint prioritises youtube subtitles over html5 ones
while deciding the current subs for video module.
"""
# Update video module to contain 1 youtube and 2 html5 sources.
youtube_id
=
str
(
uuid4
())
self
.
item
.
data
=
textwrap
.
dedent
(
"""
<video youtube="1:{youtube_id}" sub="">
<source src="http://www.testvid.org/html5/videos/testvid.mp4"/>
<source src="http://www.testvid2.org/html5/videos/testvid2.webm"/>
</video>
"""
.
format
(
youtube_id
=
youtube_id
)
)
modulestore
()
.
update_item
(
self
.
item
,
self
.
user
.
id
)
self
.
assert_current_subs
(
expected_subs
=
''
)
# Save new subs in the content store.
subs
=
{
'start'
:
[
100
,
200
,
240
],
'end'
:
[
200
,
240
,
380
],
'text'
:
[
'subs #1'
,
'subs #2'
,
'subs #3'
]
}
self
.
save_subs_to_store
(
subs
,
youtube_id
)
# Now, make request to /transcripts/save endpoint with new subs.
data
=
{
'locator'
:
unicode
(
self
.
video_usage_key
),
'metadata'
:
{
'sub'
:
youtube_id
}
}
resp
=
self
.
client
.
get
(
reverse
(
'save_transcripts'
),
{
'data'
:
json
.
dumps
(
data
)})
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertEqual
(
json
.
loads
(
resp
.
content
),
{
"status"
:
"Success"
})
# Now check item.sub, it should be same as youtube id because /transcripts/save prioritize
# youtube subs over html5 ones.
self
.
assert_current_subs
(
expected_subs
=
youtube_id
)
common/lib/xmodule/xmodule/video_module/transcripts_utils.py
View file @
0ff62e76
...
@@ -338,7 +338,10 @@ def manage_video_subtitles_save(item, user, old_metadata=None, generate_translat
...
@@ -338,7 +338,10 @@ def manage_video_subtitles_save(item, user, old_metadata=None, generate_translat
# 1.
# 1.
html5_ids
=
get_html5_ids
(
item
.
html5_sources
)
html5_ids
=
get_html5_ids
(
item
.
html5_sources
)
possible_video_id_list
=
[
item
.
youtube_id_1_0
]
+
html5_ids
# Youtube transcript source should always have a higher priority than html5 sources. Appending
# `youtube_id_1_0` at the end helps achieve this when we read transcripts list.
possible_video_id_list
=
html5_ids
+
[
item
.
youtube_id_1_0
]
sub_name
=
item
.
sub
sub_name
=
item
.
sub
for
video_id
in
possible_video_id_list
:
for
video_id
in
possible_video_id_list
:
if
not
video_id
:
if
not
video_id
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment