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, )
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"])
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 )
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)
def test_save_unjsonable_subs_to_store(self): """ Ensures 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)
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)
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)
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)
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, )
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, )
def test_video_with_subs_and_transcript_index_dictionary(self): """ Test index dictionary of a video module with YouTube subtitles and German transcript uploaded by a user. """ xml_data_sub_transcript = ''' <video display_name="Test Video" youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8" show_captions="false" download_track="false" sub="OEoXaMPEzfM" start_time="00:00:01" download_video="false" end_time="00:01:00"> <source src="http://www.example.com/source.mp4"/> <track src="http://www.example.com/track"/> <handout src="http://www.example.com/handout"/> <transcript language="ge" src="subs_grmtran1.srt" /> </video> ''' yt_subs_id = 'OEoXaMPEzfM' url = 'http://video.google.com/timedtext?lang=en&v={}'.format(yt_subs_id) httpretty.register_uri( method=httpretty.GET, uri=url, body=MOCKED_YOUTUBE_TRANSCRIPT_API_RESPONSE, content_type='application/xml' ) descriptor = instantiate_descriptor(data=xml_data_sub_transcript) subs = download_youtube_subs(yt_subs_id, descriptor, settings) save_subs_to_store(json.loads(subs), yt_subs_id, descriptor) save_to_store(SRT_FILEDATA, "subs_grmtran1.srt", 'text/srt', descriptor.location) self.assertEqual(descriptor.index_dictionary(), { "content": { "display_name": "Test Video", "transcript_en": YOUTUBE_SUBTITLES, "transcript_ge": "sprechen sie deutsch? Ja, ich spreche Deutsch", }, "content_type": "Video" })
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"])
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, )
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))
def setUp(self): super(TestVideoOutline, self).setUp() self.user = UserFactory.create() self.course = CourseFactory.create(mobile_available=True) section = ItemFactory.create( parent_location=self.course.location, category="chapter", display_name=u"test factory section omega \u03a9", ) self.sub_section = ItemFactory.create( parent_location=section.location, category="sequential", display_name=u"test subsection omega \u03a9", ) self.unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={'graded': True, 'format': 'Homework'}, display_name=u"test unit omega \u03a9", ) self.other_unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={'graded': True, 'format': 'Homework'}, display_name=u"test unit omega 2 \u03a9", ) self.edx_video_id = 'testing-123' self.video_url = 'http://val.edx.org/val/video.mp4' self.html5_video_url = 'http://video.edx.org/html5/video.mp4' api.create_profile({ 'profile_name': 'youtube', 'extension': 'mp4', 'width': 1280, 'height': 720 }) api.create_profile({ 'profile_name': 'mobile_low', 'extension': 'mp4', 'width': 640, 'height': 480 }) # create the video in VAL api.create_video({ 'edx_video_id': self.edx_video_id, 'client_video_id': u"test video omega \u03a9", 'duration': 12, 'courses': [unicode(self.course.id)], 'encoded_videos': [ { 'profile': 'youtube', 'url': 'xyz123', 'file_size': 0, 'bitrate': 1500 }, { 'profile': 'mobile_low', 'url': self.video_url, 'file_size': 12345, 'bitrate': 250 } ]}) subid = uuid4().hex self.video = ItemFactory.create( parent_location=self.unit.location, category="video", edx_video_id=self.edx_video_id, display_name=u"test video omega \u03a9", sub=subid ) 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) self.client.login(username=self.user.username, password='******')
def setUp(self): super(TestVideoOutline, self).setUp() self.user = UserFactory.create() self.course = CourseFactory.create(mobile_available=True) section = ItemFactory.create( parent_location=self.course.location, category="chapter", display_name=u"test factory section omega \u03a9", ) self.sub_section = ItemFactory.create( parent_location=section.location, category="sequential", display_name=u"test subsection omega \u03a9", ) self.unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={'graded': True, 'format': 'Homework'}, display_name=u"test unit omega \u03a9", ) self.other_unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={'graded': True, 'format': 'Homework'}, display_name=u"test unit omega 2 \u03a9", ) self.edx_video_id = 'testing-123' self.video_url = 'http://val.edx.org/val/video.mp4' self.html5_video_url = 'http://video.edx.org/html5/video.mp4' api.create_profile({ 'profile_name': 'youtube', 'extension': 'mp4', 'width': 1280, 'height': 720 }) api.create_profile({ 'profile_name': 'mobile_low', 'extension': 'mp4', 'width': 640, 'height': 480 }) val_video = api.create_video({ 'edx_video_id': self.edx_video_id, 'client_video_id': u"test video omega \u03a9", 'duration': 12, 'courses': [unicode(self.course.id)], 'encoded_videos': [ { 'profile': 'youtube', 'url': 'xyz123', 'file_size': 0, 'bitrate': 1500 }, { 'profile': 'mobile_low', 'url': self.video_url, 'file_size': 12345, 'bitrate': 250 } ]}) subid = uuid4().hex self.video = ItemFactory.create( parent_location=self.unit.location, category="video", edx_video_id=self.edx_video_id, display_name=u"test video omega \u03a9", sub=subid ) result_location = 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) self.client.login(username=self.user.username, password='******')
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)
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)