def test_success_downloading_subs(self):

        response = textwrap.dedent("""<?xml version="1.0" encoding="utf-8" ?>
                <transcript>
                    <text start="0" dur="0.27"></text>
                    <text start="0.27" dur="2.45">Test text 1.</text>
                    <text start="2.72">Test text 2.</text>
                    <text start="5.43" dur="1.73">Test text 3.</text>
                </transcript>
        """)
        good_youtube_sub = 'good_id_2'
        self.clear_sub_content(good_youtube_sub)

        with patch('xmodule.video_module.transcripts_utils.requests.get') as mock_get:
            mock_get.return_value = Mock(status_code=200, text=response, content=response)
            # Check transcripts_utils.GetTranscriptsFromYouTubeException not thrown
            transcripts_utils.download_youtube_subs(good_youtube_sub, self.course, settings)

        mock_get.assert_any_call('http://video.google.com/timedtext', params={'lang': 'en', 'v': 'good_id_2'})

        # Check asset status after import of transcript.
        filename = 'subs_{0}.srt.sjson'.format(good_youtube_sub)
        content_location = StaticContent.compute_location(self.course.id, filename)
        self.assertTrue(contentstore().find(content_location))

        self.clear_sub_content(good_youtube_sub)
Example #2
0
    def test_video_with_youtube_subs_index_dictionary(self):
        """
        Test index dictionary of a video module with YouTube subtitles.
        """
        xml_data_sub = '''
            <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"/>
            </video>
        '''

        descriptor = instantiate_descriptor(data=xml_data_sub)
        download_youtube_subs('OEoXaMPEzfM', descriptor, settings)
        self.assertEqual(descriptor.index_dictionary(), {
            "content": {
                "display_name": "Test Video",
                "transcript_en": YOUTUBE_SUBTITLES
            },
            "content_type": "Video"
        })
Example #3
0
    def test_success_downloading_subs(self):

        response = textwrap.dedent("""<?xml version="1.0" encoding="utf-8" ?>
                <transcript>
                    <text start="0" dur="0.27"></text>
                    <text start="0.27" dur="2.45">Test text 1.</text>
                    <text start="2.72">Test text 2.</text>
                    <text start="5.43" dur="1.73">Test text 3.</text>
                </transcript>
        """)
        good_youtube_sub = 'good_id_2'
        self.clear_sub_content(good_youtube_sub)

        with patch('xmodule.video_module.transcripts_utils.requests.get'
                   ) as mock_get:
            mock_get.return_value = Mock(status_code=200,
                                         text=response,
                                         content=response.encode('utf-8'))
            # Check transcripts_utils.GetTranscriptsFromYouTubeException not thrown
            transcripts_utils.download_youtube_subs(good_youtube_sub,
                                                    self.course, settings)

        mock_get.assert_any_call('http://video.google.com/timedtext',
                                 params={
                                     'lang': 'en',
                                     'v': 'good_id_2'
                                 })
Example #4
0
    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>
        '''

        descriptor = instantiate_descriptor(data=xml_data_sub_transcript)
        download_youtube_subs('OEoXaMPEzfM', descriptor, settings)
        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"
        })
Example #5
0
    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>
        '''

        descriptor = instantiate_descriptor(data=xml_data_sub_transcript)
        download_youtube_subs('OEoXaMPEzfM', descriptor, settings)
        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"
        })
Example #6
0
    def test_video_with_youtube_subs_index_dictionary(self):
        """
        Test index dictionary of a video module with YouTube subtitles.
        """
        xml_data_sub = '''
            <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"/>
            </video>
        '''

        descriptor = instantiate_descriptor(data=xml_data_sub)
        download_youtube_subs('OEoXaMPEzfM', descriptor, settings)
        self.assertEqual(
            descriptor.index_dictionary(), {
                "content": {
                    "display_name": "Test Video",
                    "transcript_en": YOUTUBE_SUBTITLES
                },
                "content_type": "Video"
            })
Example #7
0
    def test_success_downloading_subs(self):

        response = textwrap.dedent("""<?xml version="1.0" encoding="utf-8" ?>
                <transcript>
                    <text start="0" dur="0.27"></text>
                    <text start="0.27" dur="2.45">Test text 1.</text>
                    <text start="2.72">Test text 2.</text>
                    <text start="5.43" dur="1.73">Test text 3.</text>
                </transcript>
        """)
        good_youtube_sub = 'good_id_2'
        self.clear_sub_content(good_youtube_sub)

        with patch('xmodule.video_module.transcripts_utils.requests.get'
                   ) as mock_get:
            mock_get.return_value = Mock(status_code=200,
                                         text=response,
                                         content=response)
            # Check transcripts_utils.GetTranscriptsFromYouTubeException not thrown
            transcripts_utils.download_youtube_subs(good_youtube_sub,
                                                    self.course, settings)

        mock_get.assert_any_call('http://video.google.com/timedtext',
                                 params={
                                     'lang': 'en',
                                     'v': 'good_id_2'
                                 })

        # Check asset status after import of transcript.
        filename = 'subs_{0}.srt.sjson'.format(good_youtube_sub)
        content_location = StaticContent.compute_location(
            self.course.id, filename)
        self.assertTrue(contentstore().find(content_location))

        self.clear_sub_content(good_youtube_sub)
Example #8
0
def replace_transcripts(request):
    """
    Replaces all transcripts with youtube ones.

    Downloads subtitles from youtube and replaces all transcripts with downloaded ones.

    Returns: status `Success` and resulted item.sub value or status `Error` and HTTP 400.
    """
    response = {'status': 'Error', 'subs': ''}

    try:
        __, videos, item = _validate_transcripts_data(request)
    except TranscriptsRequestValidationException as e:
        return error_response(response, e.message)

    youtube_id = videos['youtube']
    if not youtube_id:
        return error_response(response, 'YouTube id {} is not presented in request data.'.format(youtube_id))

    try:
        download_youtube_subs({1.0: youtube_id}, item, settings)
    except GetTranscriptsFromYouTubeException as e:
        return error_response(response, e.message)

    item.sub = youtube_id
    item.save_with_metadata(request.user)
    response = {'status': 'Success',  'subs': item.sub}
    return JsonResponse(response)
Example #9
0
    def test_fail_downloading_subs(self, mock_get):

        mock_get.return_value = Mock(status_code=404, text='Error 404')

        bad_youtube_sub = 'BAD_YOUTUBE_ID2'
        self.clear_sub_content(bad_youtube_sub)

        with self.assertRaises(transcripts_utils.GetTranscriptsFromYouTubeException):
            transcripts_utils.download_youtube_subs(bad_youtube_sub, self.course, settings)
    def test_fail_downloading_subs(self, mock_get):

        mock_get.return_value = Mock(status_code=404, text='Error 404')

        bad_youtube_sub = 'BAD_YOUTUBE_ID2'
        self.clear_sub_content(bad_youtube_sub)

        with self.assertRaises(transcripts_utils.GetTranscriptsFromYouTubeException):
            transcripts_utils.download_youtube_subs(bad_youtube_sub, self.course, settings)
Example #11
0
    def test_downloading_subs_using_transcript_name(self, mock_get):
        """
        Download transcript using transcript name in url
        """
        good_youtube_sub = 'good_id_2'
        self.clear_sub_content(good_youtube_sub)

        transcripts_utils.download_youtube_subs(good_youtube_sub, self.course, settings)
        mock_get.assert_any_call(
            'http://video.google.com/timedtext',
            params={'lang': 'en', 'v': 'good_id_2', 'name': 'Custom'}
        )
    def test_downloading_subs_using_transcript_name(self, mock_get):
        """
        Download transcript using transcript name in url
        """
        good_youtube_sub = 'good_id_2'
        self.clear_sub_content(good_youtube_sub)

        transcripts_utils.download_youtube_subs(good_youtube_sub, self.course, settings)
        mock_get.assert_any_call(
            'http://video.google.com/timedtext',
            params={'lang': 'en', 'v': 'good_id_2', 'name': 'Custom'}
        )
def replace_transcripts(request):
    """
    Downloads subtitles from youtube and replaces edx transcripts in DS with youtube ones.

    Returns:
        status `Success` and resulted `edx_video_id` value
        Or error on validation failures.
    """
    error, validated_data = validate_transcripts_request(request, include_yt=True)
    youtube_id = validated_data['youtube']
    if error:
        response = error_response({}, error)
    elif not youtube_id:
        response = error_response({}, _(u'YouTube ID is required.'))
    else:
        # 1. Download transcript from YouTube.
        try:
            video = validated_data['video']
            transcript_content = download_youtube_subs(youtube_id, video, settings)
        except GetTranscriptsFromYouTubeException as e:
            return error_response({}, text_type(e))

        # 2. Link a video to video component if its not already linked to one.
        edx_video_id = link_video_to_component(video, request.user)

        # 3. Upload YT transcript to DS for the linked video ID.
        success = save_video_transcript(edx_video_id, Transcript.SJSON, transcript_content, language_code=u'en')
        if success:
            response = JsonResponse({'edx_video_id': edx_video_id, 'status': 'Success'}, status=200)
        else:
            response = error_response({}, _('There is a problem with the YouTube transcript file.'))

    return response
def replace_transcripts(request):
    """
    Downloads subtitles from youtube and replaces edx transcripts in DS with youtube ones.

    Returns:
        status `Success` and resulted `edx_video_id` value
        Or error on validation failures.
    """
    error, validated_data = validate_transcripts_request(request, include_yt=True)
    youtube_id = validated_data['youtube']
    if error:
        response = error_response({}, error)
    elif not youtube_id:
        response = error_response({}, _(u'YouTube ID is required.'))
    else:
        # 1. Download transcript from YouTube.
        try:
            video = validated_data['video']
            transcript_content = download_youtube_subs(youtube_id, video, settings)
        except GetTranscriptsFromYouTubeException as e:
            return error_response({}, text_type(e))

        # 2. Link a video to video component if its not already linked to one.
        edx_video_id = link_video_to_component(video, request.user)

        # 3. Upload YT transcript to DS for the linked video ID.
        success = save_video_transcript(edx_video_id, Transcript.SJSON, transcript_content, language_code=u'en')
        if success:
            response = JsonResponse({'edx_video_id': edx_video_id, 'status': 'Success'}, status=200)
        else:
            response = error_response({}, _('There is a problem with the YouTube transcript file.'))

    return response
    def test_fail_downloading_subs(self, mock_get):

        mock_get.return_value = Mock(status_code=404, text="Error 404")

        bad_youtube_sub = "BAD_YOUTUBE_ID2"
        self.clear_sub_content(bad_youtube_sub)

        with self.assertRaises(transcripts_utils.GetTranscriptsFromYouTubeException):
            transcripts_utils.download_youtube_subs(bad_youtube_sub, self.course, settings)

        # Check asset status after import of transcript.
        filename = "subs_{0}.srt.sjson".format(bad_youtube_sub)
        content_location = StaticContent.compute_location(self.course.id, filename)
        with self.assertRaises(NotFoundError):
            contentstore().find(content_location)

        self.clear_sub_content(bad_youtube_sub)
    def test_downloading_subs_using_transcript_name(self, mock_get):
        """
        Download transcript using transcript name in url
        """
        good_youtube_sub = "good_id_2"
        self.clear_sub_content(good_youtube_sub)

        transcripts_utils.download_youtube_subs(good_youtube_sub, self.course, settings)
        mock_get.assert_any_call(
            "http://video.google.com/timedtext", params={"lang": "en", "v": "good_id_2", "name": "Custom"}
        )

        # Check asset status after import of transcript.
        filename = "subs_{0}.srt.sjson".format(good_youtube_sub)
        content_location = StaticContent.compute_location(self.course.id, filename)
        self.assertTrue(contentstore().find(content_location))

        self.clear_sub_content(good_youtube_sub)
Example #17
0
    def test_downloading_subs_using_transcript_name(self, mock_get):
        """
        Download transcript using transcript name in url
        """
        good_youtube_sub = 'good_id_2'
        self.clear_sub_content(good_youtube_sub)

        transcripts_utils.download_youtube_subs(good_youtube_sub, self.course, settings)
        mock_get.assert_any_call(
            'http://video.google.com/timedtext',
            params={'lang': 'en', 'v': 'good_id_2', 'name': 'Custom'}
        )

        # Check asset status after import of transcript.
        filename = 'subs_{0}.srt.sjson'.format(good_youtube_sub)
        content_location = StaticContent.compute_location(self.course.id, filename)
        self.assertTrue(contentstore().find(content_location))

        self.clear_sub_content(good_youtube_sub)
Example #18
0
    def test_fail_downloading_subs(self, mock_get):

        mock_get.return_value = Mock(status_code=404, text='Error 404')

        bad_youtube_sub = 'BAD_YOUTUBE_ID2'
        self.clear_sub_content(bad_youtube_sub)

        with self.assertRaises(transcripts_utils.GetTranscriptsFromYouTubeException):
            transcripts_utils.download_youtube_subs(bad_youtube_sub, self.course, settings)

        # Check asset status after import of transcript.
        filename = 'subs_{0}.srt.sjson'.format(bad_youtube_sub)
        content_location = StaticContent.compute_location(
            self.course.id, filename
        )
        with self.assertRaises(NotFoundError):
            contentstore().find(content_location)

        self.clear_sub_content(bad_youtube_sub)
    def test_downloading_subs_using_transcript_name(self, mock_get):
        """
        Download transcript using transcript name in url
        """
        good_youtube_sub = 'good_id_2'
        self.clear_sub_content(good_youtube_sub)

        transcripts_utils.download_youtube_subs(good_youtube_sub, self.course, settings)
        mock_get.assert_any_call(
            'http://video.google.com/timedtext',
            params={'lang': 'en', 'v': 'good_id_2', 'name': 'Custom'}
        )

        # Check asset status after import of transcript.
        filename = 'subs_{0}.srt.sjson'.format(good_youtube_sub)
        content_location = StaticContent.compute_location(self.course.id, filename)
        self.assertTrue(contentstore().find(content_location))

        self.clear_sub_content(good_youtube_sub)
    def test_success_downloading_chinese_transcripts(self):

        # Disabled 11/14/13
        # This test is flakey because it performs an HTTP request on an external service
        # Re-enable when `requests.get` is patched using `mock.patch`
        raise SkipTest

        good_youtube_sub = "j_jEn79vS3g"  # Chinese, utf-8
        self.clear_sub_content(good_youtube_sub)

        # Check transcripts_utils.GetTranscriptsFromYouTubeException not thrown
        transcripts_utils.download_youtube_subs(good_youtube_sub, self.course, settings)

        # Check assets status after importing subtitles.
        for subs_id in good_youtube_subs.values():
            filename = "subs_{0}.srt.sjson".format(subs_id)
            content_location = StaticContent.compute_location(self.course.id, filename)
            self.assertTrue(contentstore().find(content_location))

        self.clear_sub_content(good_youtube_sub)
Example #21
0
    def test_success_downloading_chinese_transcripts(self):

        # Disabled 11/14/13
        # This test is flakey because it performs an HTTP request on an external service
        # Re-enable when `requests.get` is patched using `mock.patch`
        raise SkipTest

        good_youtube_sub = 'j_jEn79vS3g'  # Chinese, utf-8
        self.clear_sub_content(good_youtube_sub)

        # Check transcripts_utils.GetTranscriptsFromYouTubeException not thrown
        transcripts_utils.download_youtube_subs(good_youtube_sub, self.course,
                                                settings)

        # Check assets status after importing subtitles.
        for subs_id in good_youtube_subs.values():
            filename = 'subs_{0}.srt.sjson'.format(subs_id)
            content_location = StaticContent.compute_location(
                self.course.id, filename)
            self.assertTrue(contentstore().find(content_location))

        self.clear_sub_content(good_youtube_sub)
    def test_fail_downloading_subs(self, mock_get):

        mock_get.return_value = Mock(status_code=404, text='Error 404')

        bad_youtube_subs = {
            0.5: 'BAD_YOUTUBE_ID1',
            1.0: 'BAD_YOUTUBE_ID2',
            2.0: 'BAD_YOUTUBE_ID3'
        }
        self.clear_subs_content(bad_youtube_subs)
        with self.assertRaises(transcripts_utils.GetTranscriptsFromYouTubeException):
            transcripts_utils.download_youtube_subs(bad_youtube_subs, self.course, settings)

        # Check assets status after importing subtitles.
        for subs_id in bad_youtube_subs.values():
            filename = 'subs_{0}.srt.sjson'.format(subs_id)
            content_location = StaticContent.compute_location(
                self.org, self.number, filename
            )
            with self.assertRaises(NotFoundError):
                contentstore().find(content_location)

        self.clear_subs_content(bad_youtube_subs)
Example #23
0
def json_update_videos(request, locations):
    """
    Updates the captions of a given list of videos and returns the status of the
    videos in json format

    request: the incoming request to update the videos
    locations: list of locations of videos to be updated
    """
    results = []
    for key_string in locations:
        key = UsageKey.from_string(key_string)
        try:
            #update transcripts
            item = modulestore().get_item(key)
            download_youtube_subs(item.youtube_id_1_0, item, settings)

            # Once transcripts downloaded, show subs are present from youtube
            item.sub = item.youtube_id_1_0
            manage_video_subtitles_save(item, request.user)

            #get new status
            videos = {'youtube': item.youtube_id_1_0}
            html5 = {}
            for url in item.html5_sources:
                name = os.path.splitext(url.split('/')[-1])[0]
                html5[name] = 'html5'
            videos['html5'] = html5
            captions_dict = get_transcripts_presence(videos, item)
            captions_dict.update({'location': key_string})
            results.append(captions_dict)

        except GetTranscriptsFromYouTubeException as e:
            log.debug(e)
            results.append({'location': key_string, 'command': e})

    return JsonResponse(results)
Example #24
0
    def test_fail_downloading_subs(self, mock_get):

        mock_get.return_value = Mock(status_code=404, text='Error 404')

        bad_youtube_subs = {
            0.5: 'BAD_YOUTUBE_ID1',
            1.0: 'BAD_YOUTUBE_ID2',
            2.0: 'BAD_YOUTUBE_ID3'
        }
        self.clear_subs_content(bad_youtube_subs)
        with self.assertRaises(
                transcripts_utils.GetTranscriptsFromYouTubeException):
            transcripts_utils.download_youtube_subs(bad_youtube_subs,
                                                    self.course, settings)

        # Check assets status after importing subtitles.
        for subs_id in bad_youtube_subs.values():
            filename = 'subs_{0}.srt.sjson'.format(subs_id)
            content_location = StaticContent.compute_location(
                self.org, self.number, filename)
            with self.assertRaises(NotFoundError):
                contentstore().find(content_location)

        self.clear_subs_content(bad_youtube_subs)
Example #25
0
def json_update_videos(request, locations):
    """
    Updates the captions of a given list of videos and returns the status of the
    videos in json format

    request: the incoming request to update the videos
    locations: list of locations of videos to be updated
    """
    results = []
    for key_string in locations:
        key = UsageKey.from_string(key_string)
        try:
            #update transcripts
            item = modulestore().get_item(key)
            download_youtube_subs(item.youtube_id_1_0, item, settings)

            # Once transcripts downloaded, show subs are present from youtube
            item.sub = item.youtube_id_1_0
            manage_video_subtitles_save(item, request.user)

            #get new status
            videos = {'youtube': item.youtube_id_1_0}
            html5 = {}
            for url in item.html5_sources:
                name = os.path.splitext(url.split('/')[-1])[0]
                html5[name] = 'html5'
            videos['html5'] = html5
            captions_dict = get_transcripts_presence(videos, item)
            captions_dict.update({'location': key_string})
            results.append(captions_dict)

        except GetTranscriptsFromYouTubeException as e:
            log.debug(e)
            results.append({'location': key_string, 'command': e})

    return JsonResponse(results)
Example #26
0
 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"
     })
Example #27
0
    def test_index_dictionary(self):
        xml_data = '''
            <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"
                   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"/>
            </video>
        '''
        descriptor = instantiate_descriptor(data=xml_data)
        self.assertEqual(descriptor.index_dictionary(), {
            "content": {
                "display_name": "Test Video"
            },
            "content_type": "Video"
        })

        xml_data_sub = '''
            <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"/>
            </video>
        '''

        descriptor = instantiate_descriptor(data=xml_data_sub)
        download_youtube_subs('OEoXaMPEzfM', descriptor, settings)
        self.assertEqual(
            descriptor.index_dictionary(), {
                "content": {
                    "display_name":
                    "Test Video",
                    "transcript_en":
                    ("LILA FISHER: Hi, welcome to Edx. I'm Lila Fisher, an Edx fellow helping to put together these"
                     "courses. As you know, our courses are entirely online. So before we start learning about the"
                     "subjects that brought you here, let's learn about the tools that you will use to navigate through"
                     "the course material. Let's start with what is on your screen right now. You are watching a video"
                     "of me talking. You have several tools associated with these videos. Some of them are standard"
                     "video buttons, like the play Pause Button on the bottom left. Like most video players, you can see"
                     "how far you are into this particular video segment and how long the entire video segment is."
                     "Something that you might not be used to is the speed option. While you are going through the"
                     "videos, you can speed up or slow down the video player with these buttons. Go ahead and try that"
                     "now. Make me talk faster and slower. If you ever get frustrated by the pace of speech, you can"
                     "adjust it this way. Another great feature is the transcript on the side. This will follow along"
                     "with everything that I am saying as I am saying it, so you can read along if you like. You can"
                     "also click on any of the words, and you will notice that the video jumps to that word. The video"
                     "slider at the bottom of the video will let you navigate through the video quickly. If you ever"
                     "find the transcript distracting, you can toggle the captioning button in order to make it go away"
                     "or reappear. Now that you know about the video player, I want to point out the sequence navigator."
                     "Right now you're in a lecture sequence, which interweaves many videos and practice exercises. You"
                     "can see how far you are in a particular sequence by observing which tab you're on. You can"
                     "navigate directly to any video or exercise by clicking on the appropriate tab. You can also"
                     "progress to the next element by pressing the Arrow button, or by clicking on the next tab. Try"
                     "that now. The tutorial will continue in the next video.")
                },
                "content_type": "Video"
            })

        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>
        '''

        descriptor = instantiate_descriptor(data=xml_data_sub_transcript)
        save_to_store(SRT_FILEDATA, "subs_grmtran1.srt", 'text/srt',
                      descriptor.location)
        self.assertEqual(
            descriptor.index_dictionary(), {
                "content": {
                    "display_name":
                    "Test Video",
                    "transcript_en":
                    ("LILA FISHER: Hi, welcome to Edx. I'm Lila Fisher, an Edx fellow helping to put together these"
                     "courses. As you know, our courses are entirely online. So before we start learning about the"
                     "subjects that brought you here, let's learn about the tools that you will use to navigate through"
                     "the course material. Let's start with what is on your screen right now. You are watching a video"
                     "of me talking. You have several tools associated with these videos. Some of them are standard"
                     "video buttons, like the play Pause Button on the bottom left. Like most video players, you can see"
                     "how far you are into this particular video segment and how long the entire video segment is."
                     "Something that you might not be used to is the speed option. While you are going through the"
                     "videos, you can speed up or slow down the video player with these buttons. Go ahead and try that"
                     "now. Make me talk faster and slower. If you ever get frustrated by the pace of speech, you can"
                     "adjust it this way. Another great feature is the transcript on the side. This will follow along"
                     "with everything that I am saying as I am saying it, so you can read along if you like. You can"
                     "also click on any of the words, and you will notice that the video jumps to that word. The video"
                     "slider at the bottom of the video will let you navigate through the video quickly. If you ever"
                     "find the transcript distracting, you can toggle the captioning button in order to make it go away"
                     "or reappear. Now that you know about the video player, I want to point out the sequence navigator."
                     "Right now you're in a lecture sequence, which interweaves many videos and practice exercises. You"
                     "can see how far you are in a particular sequence by observing which tab you're on. You can"
                     "navigate directly to any video or exercise by clicking on the appropriate tab. You can also"
                     "progress to the next element by pressing the Arrow button, or by clicking on the next tab. Try"
                     "that now. The tutorial will continue in the next video."
                     ),
                    "transcript_ge":
                    "sprechen sie deutsch? Ja, ich spreche Deutsch"
                },
                "content_type": "Video"
            })

        xml_data_transcripts = '''
            <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"
                   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" />
              <transcript language="hr" src="subs_croatian1.srt" />
            </video>
        '''

        descriptor = instantiate_descriptor(data=xml_data_transcripts)
        save_to_store(SRT_FILEDATA, "subs_grmtran1.srt", 'text/srt',
                      descriptor.location)
        save_to_store(CRO_SRT_FILEDATA, "subs_croatian1.srt", 'text/srt',
                      descriptor.location)
        self.assertEqual(
            descriptor.index_dictionary(), {
                "content": {
                    "display_name": "Test Video",
                    "transcript_ge":
                    "sprechen sie deutsch? Ja, ich spreche Deutsch",
                    "transcript_hr": "Dobar dan! Kako ste danas?"
                },
                "content_type": "Video"
            })
Example #28
0
    def test_index_dictionary(self):
        xml_data = '''
            <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"
                   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"/>
            </video>
        '''
        descriptor = instantiate_descriptor(data=xml_data)
        self.assertEqual(descriptor.index_dictionary(), {
            "content": {"display_name": "Test Video"},
            "content_type": "Video"
        })

        xml_data_sub = '''
            <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"/>
            </video>
        '''

        descriptor = instantiate_descriptor(data=xml_data_sub)
        download_youtube_subs('OEoXaMPEzfM', descriptor, settings)
        self.assertEqual(descriptor.index_dictionary(), {
            "content": {
                "display_name": "Test Video",
                "transcript_en": (
                    "LILA FISHER: Hi, welcome to Edx. I'm Lila Fisher, an Edx fellow helping to put together these"
                    "courses. As you know, our courses are entirely online. So before we start learning about the"
                    "subjects that brought you here, let's learn about the tools that you will use to navigate through"
                    "the course material. Let's start with what is on your screen right now. You are watching a video"
                    "of me talking. You have several tools associated with these videos. Some of them are standard"
                    "video buttons, like the play Pause Button on the bottom left. Like most video players, you can see"
                    "how far you are into this particular video segment and how long the entire video segment is."
                    "Something that you might not be used to is the speed option. While you are going through the"
                    "videos, you can speed up or slow down the video player with these buttons. Go ahead and try that"
                    "now. Make me talk faster and slower. If you ever get frustrated by the pace of speech, you can"
                    "adjust it this way. Another great feature is the transcript on the side. This will follow along"
                    "with everything that I am saying as I am saying it, so you can read along if you like. You can"
                    "also click on any of the words, and you will notice that the video jumps to that word. The video"
                    "slider at the bottom of the video will let you navigate through the video quickly. If you ever"
                    "find the transcript distracting, you can toggle the captioning button in order to make it go away"
                    "or reappear. Now that you know about the video player, I want to point out the sequence navigator."
                    "Right now you're in a lecture sequence, which interweaves many videos and practice exercises. You"
                    "can see how far you are in a particular sequence by observing which tab you're on. You can"
                    "navigate directly to any video or exercise by clicking on the appropriate tab. You can also"
                    "progress to the next element by pressing the Arrow button, or by clicking on the next tab. Try"
                    "that now. The tutorial will continue in the next video."
                )
            },
            "content_type": "Video"
        })

        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>
        '''

        descriptor = instantiate_descriptor(data=xml_data_sub_transcript)
        save_to_store(SRT_FILEDATA, "subs_grmtran1.srt", 'text/srt', descriptor.location)
        self.assertEqual(descriptor.index_dictionary(), {
            "content": {
                "display_name": "Test Video",
                "transcript_en": (
                    "LILA FISHER: Hi, welcome to Edx. I'm Lila Fisher, an Edx fellow helping to put together these"
                    "courses. As you know, our courses are entirely online. So before we start learning about the"
                    "subjects that brought you here, let's learn about the tools that you will use to navigate through"
                    "the course material. Let's start with what is on your screen right now. You are watching a video"
                    "of me talking. You have several tools associated with these videos. Some of them are standard"
                    "video buttons, like the play Pause Button on the bottom left. Like most video players, you can see"
                    "how far you are into this particular video segment and how long the entire video segment is."
                    "Something that you might not be used to is the speed option. While you are going through the"
                    "videos, you can speed up or slow down the video player with these buttons. Go ahead and try that"
                    "now. Make me talk faster and slower. If you ever get frustrated by the pace of speech, you can"
                    "adjust it this way. Another great feature is the transcript on the side. This will follow along"
                    "with everything that I am saying as I am saying it, so you can read along if you like. You can"
                    "also click on any of the words, and you will notice that the video jumps to that word. The video"
                    "slider at the bottom of the video will let you navigate through the video quickly. If you ever"
                    "find the transcript distracting, you can toggle the captioning button in order to make it go away"
                    "or reappear. Now that you know about the video player, I want to point out the sequence navigator."
                    "Right now you're in a lecture sequence, which interweaves many videos and practice exercises. You"
                    "can see how far you are in a particular sequence by observing which tab you're on. You can"
                    "navigate directly to any video or exercise by clicking on the appropriate tab. You can also"
                    "progress to the next element by pressing the Arrow button, or by clicking on the next tab. Try"
                    "that now. The tutorial will continue in the next video."
                ),
                "transcript_ge": "sprechen sie deutsch? Ja, ich spreche Deutsch"
            },
            "content_type": "Video"
        })

        xml_data_transcripts = '''
            <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"
                   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" />
              <transcript language="hr" src="subs_croatian1.srt" />
            </video>
        '''

        descriptor = instantiate_descriptor(data=xml_data_transcripts)
        save_to_store(SRT_FILEDATA, "subs_grmtran1.srt", 'text/srt', descriptor.location)
        save_to_store(CRO_SRT_FILEDATA, "subs_croatian1.srt", 'text/srt', descriptor.location)
        self.assertEqual(descriptor.index_dictionary(), {
            "content": {
                "display_name": "Test Video",
                "transcript_ge": "sprechen sie deutsch? Ja, ich spreche Deutsch",
                "transcript_hr": "Dobar dan! Kako ste danas?"
            },
            "content_type": "Video"
        })