本文整理汇总了Python中xmodule.video_module.transcripts_utils.save_subs_to_store函数的典型用法代码示例。如果您正苦于以下问题:Python save_subs_to_store函数的具体用法?Python save_subs_to_store怎么用?Python save_subs_to_store使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了save_subs_to_store函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_transcript
def create_transcript(self, subs_id, language=u'en', filename='video.srt', youtube_id_1_0='', html5_sources=None):
"""
create transcript.
"""
transcripts = {}
if language != u'en':
transcripts = {language: filename}
html5_sources = html5_sources or []
self.video = ItemFactory.create(
category='video',
parent_location=self.vertical.location,
sub=subs_id,
youtube_id_1_0=youtube_id_1_0,
transcripts=transcripts,
edx_video_id=u'1234-5678-90',
html5_sources=html5_sources
)
possible_subs = [subs_id, youtube_id_1_0] + transcripts_utils.get_html5_ids(html5_sources)
for possible_sub in possible_subs:
if possible_sub:
transcripts_utils.save_subs_to_store(
self.subs_sjson,
possible_sub,
self.video,
language=language,
)
示例2: _create_video_with_subs
def _create_video_with_subs(self, custom_subid=None):
"""
Creates and returns a video with stored subtitles.
"""
subid = custom_subid or uuid4().hex
transcripts_utils.save_subs_to_store(
{
'start': [100, 200, 240, 390, 1000],
'end': [200, 240, 380, 1000, 1500],
'text': [
'subs #1',
'subs #2',
'subs #3',
'subs #4',
'subs #5'
]
},
subid,
self.course)
return ItemFactory.create(
parent=self.unit,
category="video",
edx_video_id=self.edx_video_id,
display_name=u"test video omega \u03a9",
sub=subid
)
示例3: test_only_on_web
def test_only_on_web(self):
self.login_and_enroll()
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 0)
subid = uuid4().hex
transcripts_utils.save_subs_to_store({"start": [100], "end": [200], "text": ["subs #1"]}, subid, self.course)
ItemFactory.create(
parent=self.unit, category="video", display_name=u"test video", only_on_web=True, subid=subid
)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 1)
self.assertIsNone(course_outline[0]["summary"]["video_url"])
self.assertIsNone(course_outline[0]["summary"]["video_thumbnail_url"])
self.assertEqual(course_outline[0]["summary"]["duration"], 0)
self.assertEqual(course_outline[0]["summary"]["size"], 0)
self.assertEqual(course_outline[0]["summary"]["name"], "test video")
self.assertEqual(course_outline[0]["summary"]["transcripts"], {})
self.assertIsNone(course_outline[0]["summary"]["language"])
self.assertEqual(course_outline[0]["summary"]["category"], "video")
self.assertTrue(course_outline[0]["summary"]["only_on_web"])
示例4: test_save_unjsonable_subs_to_store
def test_save_unjsonable_subs_to_store(self):
"""
Assures that subs, that can't be dumped, can't be found later.
"""
with self.assertRaises(NotFoundError):
contentstore().find(self.content_location_unjsonable)
with self.assertRaises(TypeError):
transcripts_utils.save_subs_to_store(self.unjsonable_subs, self.unjsonable_subs_id, self.course)
with self.assertRaises(NotFoundError):
contentstore().find(self.content_location_unjsonable)
示例5: test_save_subs_to_store
def test_save_subs_to_store(self):
with self.assertRaises(NotFoundError):
contentstore().find(self.content_location)
result_location = transcripts_utils.save_subs_to_store(self.subs, self.subs_id, self.course)
self.assertTrue(contentstore().find(self.content_location))
self.assertEqual(result_location, self.content_location)
示例6: _create_video_with_subs
def _create_video_with_subs(self, custom_subid=None):
"""
Creates and returns a video with stored subtitles.
"""
subid = custom_subid or uuid4().hex
transcripts_utils.save_subs_to_store(
{
"start": [100, 200, 240, 390, 1000],
"end": [200, 240, 380, 1000, 1500],
"text": ["subs #1", "subs #2", "subs #3", "subs #4", "subs #5"],
},
subid,
self.course,
)
return ItemFactory.create(
parent=self.unit,
category="video",
edx_video_id=self.edx_video_id,
display_name=u"test video omega \u03a9",
sub=subid,
)
示例7: create_transcript
def create_transcript(self, subs_id, language=u'en', filename='video.srt'):
"""
create transcript.
"""
transcripts = {}
if language != u'en':
transcripts = {language: filename}
self.video = ItemFactory.create(
category='video',
parent_location=self.vertical.location,
sub=subs_id,
transcripts=transcripts,
edx_video_id=u'1234-5678-90'
)
if subs_id:
transcripts_utils.save_subs_to_store(
self.subs_sjson,
subs_id,
self.video,
language=language,
)
示例8: test_save_unicode_filename
def test_save_unicode_filename(self):
# Mock a video item
item = Mock(location=Mock(course_key=self.course.id))
transcripts_utils.save_subs_to_store(self.subs, self.subs_id, self.course)
transcripts_utils.copy_or_rename_transcript(self.subs_copied_id, self.subs_id, item)
self.assertTrue(contentstore().find(self.content_copied_location))
示例9: setUp
def setUp(self):
super(TestUpdateTranscripts, self).setUp()
# Course with 1 video item, the transcripts of which don't exist on local store
self.course = CourseFactory.create(
org='edX', course='001', display_name='Robot Super Course')
ItemFactory.create(
parent_location=self.course.location, category='video',
data={'data': '''
<video display_name="Test Video"
youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
show_captions="false"
from="00:00:01"
to="00:01:00">
<source src="http://www.example.com/file.mp4"/>
<track src="http://www.example.com/track"/>
</video>'''}
)
# Course with 1 video item, the transcripts of which already uploaded to local store
self.course2 = CourseFactory.create(
org='edX', course='002', display_name='Transcripts Already Exist Course')
ItemFactory.create(
parent_location=self.course2.location, category='video',
data={'data': '''
<video display_name="Test Video"
youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
show_captions="false"
from="00:00:01"
to="00:01:00">
<source src="http://www.example.com/file.mp4"/>
<track src="http://www.example.com/track"/>
</video>'''}
)
self.subs = {
'start': [100, 200, 240, 390, 1000],
'end': [200, 240, 380, 1000, 1500],
'text': [
'subs #1',
'subs #2',
'subs #3',
'subs #4',
'subs #5'
]
}
self.changed_subs = {
'start': [100],
'end': [200],
'text': ['subs #1']
}
subs_id = 'p2Q6BrNhdh8'
filename = 'subs_{0}.srt.sjson'.format(subs_id)
self.content_location = StaticContent.compute_location(self.course2.id, filename)
transcripts_utils.save_subs_to_store(self.subs, subs_id, self.course2)
# Ended course
past_end = datetime.now() - timedelta(days=12)
self.course3 = CourseFactory.create(
org='edX', course='003', display_name='Already Ended Course', end=past_end)
# patcher
patcher_conn = patch('contentstore.management.commands.update_transcripts.S3Connection')
self.mock_conn_class = patcher_conn.start()
self.mock_conn_class.return_value.get_bucket.return_value = None
self.addCleanup(patcher_conn.stop)
patcher_get_transcripts = patch('xmodule.video_module.transcripts_utils.get_transcripts_from_youtube')
self.mock_get_transcripts = patcher_get_transcripts.start()
self.mock_get_transcripts.return_value = self.subs
self.addCleanup(patcher_get_transcripts.stop)
patcher_logger_info = patch('contentstore.management.commands.update_transcripts.log.info')
self.logger_info = patcher_logger_info.start()
self.addCleanup(patcher_logger_info.stop)
self.addCleanup(ModuleStoreTestCase.drop_mongo_collections)
self.addCleanup(clear_existing_modulestores)