Esempio n. 1
0
def save_transcript_to_storage(command_run, edx_video_id, language_code,
                               transcript_content, file_format, force_update):
    """
    Pushes a given transcript's data to django storage.

    Arguments:
        command_run: A positive integer indicating the current run
        edx_video_id: video ID
        language_code: language code
        transcript_content: content of the transcript
        file_format: format of the transcript file
        force_update: tells whether it needs to perform force update in
        case of an existing transcript for the given video.
    """
    transcript_present = is_transcript_available(video_id=edx_video_id,
                                                 language_code=language_code)
    if transcript_present and force_update:
        create_or_update_video_transcript(edx_video_id, language_code,
                                          dict({'file_format': file_format}),
                                          ContentFile(transcript_content))
    elif not transcript_present:
        create_video_transcript(edx_video_id, language_code, file_format,
                                ContentFile(transcript_content))
    else:
        LOGGER.info(
            "[%s] [run=%s] [do-not-override-existing-transcript] [edx_video_id=%s] [language_code=%s]",
            MIGRATION_LOGS_PREFIX, command_run, edx_video_id, language_code)
Esempio n. 2
0
    def test_translation_delete_w_edx_video_id(self):
        """
        Verify that DELETE dispatch works as expected when video has edx_video_id
        """
        request_body = json.dumps({'lang': self.LANGUAGE_CODE_UK, 'edx_video_id': self.EDX_VIDEO_ID})
        api.create_video({
            'edx_video_id': self.EDX_VIDEO_ID,
            'status': 'upload',
            'client_video_id': 'awesome.mp4',
            'duration': 0,
            'encoded_videos': [],
            'courses': [unicode(self.course.id)]
        })
        api.create_video_transcript(
            video_id=self.EDX_VIDEO_ID,
            language_code=self.LANGUAGE_CODE_UK,
            file_format='srt',
            content=ContentFile(SRT_content)
        )

        # verify that a video transcript exists for expected data
        self.assertTrue(api.get_video_transcript_data(video_id=self.EDX_VIDEO_ID, language_code=self.LANGUAGE_CODE_UK))

        request = Request(self.REQUEST_META, body=request_body)
        self.item_descriptor.edx_video_id = self.EDX_VIDEO_ID
        response = self.item_descriptor.studio_transcript(request=request, dispatch='translation')
        self.assertEqual(response.status_code, 200)

        # verify that a video transcript dose not exist for expected data
        self.assertFalse(api.get_video_transcript_data(video_id=self.EDX_VIDEO_ID, language_code=self.LANGUAGE_CODE_UK))
Esempio n. 3
0
def save_transcript_to_storage(command_run, edx_video_id, language_code, transcript_content, file_format, force_update):
    """
    Pushes a given transcript's data to django storage.

    Arguments:
        command_run: A positive integer indicating the current run
        edx_video_id: video ID
        language_code: language code
        transcript_content: content of the transcript
        file_format: format of the transcript file
        force_update: tells whether it needs to perform force update in
        case of an existing transcript for the given video.
    """
    transcript_present = is_transcript_available(video_id=edx_video_id, language_code=language_code)
    if transcript_present and force_update:
        create_or_update_video_transcript(
            edx_video_id,
            language_code,
            dict({'file_format': file_format}),
            ContentFile(transcript_content)
        )
    elif not transcript_present:
        create_video_transcript(
            edx_video_id,
            language_code,
            file_format,
            ContentFile(transcript_content)
        )
    else:
        LOGGER.info(
            "[%s] [run=%s] [do-not-override-existing-transcript] [edx_video_id=%s] [language_code=%s]",
            MIGRATION_LOGS_PREFIX, command_run, edx_video_id, language_code
        )
Esempio n. 4
0
def save_transcript_to_storage(edx_video_id, language_code, transcript_content, file_format, force_update):
    """
    Pushes a given transcript's data to django storage.

    Arguments:
        edx_video_id: video ID
        language_code: language code
        transcript_content: content of the transcript
        file_format: format of the transcript file
        force_update: tells whether it needs to perform force update in
        case of an existing transcript for the given video.
    """
    transcript_present = is_transcript_available(video_id=edx_video_id, language_code=language_code)
    if transcript_present and force_update:
        create_or_update_video_transcript(
            edx_video_id,
            language_code,
            dict({'file_format': file_format}),
            ContentFile(transcript_content)
        )
    elif not transcript_present:
        create_video_transcript(
            edx_video_id,
            language_code,
            file_format,
            ContentFile(transcript_content)
        )
Esempio n. 5
0
def save_transcript_to_storage(edx_video_id,
                               language_code,
                               transcript_content,
                               file_format=Transcript.SJSON,
                               force_update=False):
    """
    Pushes a given transcript's data to django storage.
    """
    try:
        result = None
        edx_video_id = clean_video_id(edx_video_id)
        if force_update:
            result = create_or_update_video_transcript(
                edx_video_id, language_code, dict({'file_format':
                                                   file_format}),
                ContentFile(transcript_content))
            LOGGER.info(
                "[Transcript migration] save_transcript_to_storage %s for %s with create_or_update method",
                True if result else False, edx_video_id)
        else:
            result = create_video_transcript(edx_video_id, language_code,
                                             file_format,
                                             ContentFile(transcript_content))
            LOGGER.info(
                "[Transcript migration] save_transcript_to_storage %s for %s with create method",
                result, edx_video_id)
        return result
    except ValCannotCreateError as err:
        LOGGER.exception(
            "[Transcript migration] save_transcript_to_storage_failed: %s",
            err)
        raise
    def setUp(self):
        super(TestCourseMixin, self).setUp()

        with modulestore().default_store(ModuleStoreEnum.Type.split):
            self.course = SampleCourseFactory.create(
                block_info_tree=TEST_COURSE)
        # And upload the course static asssets:
        asset_key = StaticContent.compute_location(self.course.id,
                                                   'sample_handout.txt')
        content = StaticContent(asset_key, "Fake asset", "application/text",
                                "test".encode('utf8'))
        contentstore().save(content)

        asset_key = StaticContent.compute_location(self.course.id, 'edx.svg')
        content = StaticContent(
            asset_key, "Fake image", "image/svg+xml", """
            <svg viewBox="0 0 403 403" version="1.1"
                xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
            >
                <title>edX</title>
                <desc>
                    the edX logo is comprised of a red letter e, grey d, and blue uppercase X, all slightly overlapping
                    each other.  The d is slightly transparent.
                </desc>
                <g transform="translate(0,100)">
                    <path id="e-path" stroke-width="1" stroke="none" fill="rgb(185, 0, 88)" fill-rule="evenodd"
                        d="M32.1,127 H141.9 A71,71.5 0 1,0 137.3,143 H103 A42,42 0 0,1 32.1,127 M32.1,102.5 H112 A42,42
                        0 0,0 32.1,102.5"/>
                    <path id="x-path" stroke-width="1" stroke="none" fill="rgb(0, 162, 228)" fill-rule="evenodd"
                        d="M228,1 H302 V31 H286 L315,67 L344,31 H328 V1 H401.5 V31 H385 L335.2,92.4 L387.5,156.8 H401.5
                        V187 H328 V156.8 H346.5 L315,117.4 L283,156.8 H302.0 V187 H228.5 V156.8 H243 L294.3,92.4
                        L244,30.5 H228 V1"/>
                    <path id="d-path" stroke-width="1" stroke="none" fill="rgb(55, 55, 60)" fill-rule="evenodd"
                        opacity="0.55" d="M198.5,1 L248,1 V156.5 H269.8 V187 H217.5 V174 A71.7,71.7 0 1,1 218,55.5
                        V30.5 H198.5 V1 M218,114 A41,41.5 0 1,1 136.1,114 A40.5,40.5 0 1,1 218,114"/>
                </g>
            </svg>
        """.strip().encode('utf8'))
        contentstore().save(content)
        # And the video data + transcript must also be stored in edx-val for the video export to work:
        edxval_api.create_video(VIDEO_B_VAL_DATA)
        edxval_api.create_video_transcript(**VIDEO_B_SRT_TRANSCRIPT_DATA)
Esempio n. 7
0
def save_transcript_to_storage(
        edx_video_id,
        language_code,
        transcript_content,
        file_format=Transcript.SJSON,
        force_update=False
):
    """
    Pushes a given transcript's data to django storage.
    """
    try:
        result = None
        edx_video_id = clean_video_id(edx_video_id)
        if force_update:
            result = create_or_update_video_transcript(
                edx_video_id,
                language_code,
                dict({'file_format': file_format}),
                ContentFile(transcript_content)
            )
            LOGGER.info("[Transcript migration] save_transcript_to_storage %s for %s with create_or_update method",
                        True if result else False, edx_video_id)
        else:
            result = create_video_transcript(
                edx_video_id,
                language_code,
                file_format,
                ContentFile(transcript_content)
            )
            LOGGER.info(
                "[Transcript migration] save_transcript_to_storage %s for %s with create method",
                result,
                edx_video_id
            )
        return result
    except ValCannotCreateError as err:
        LOGGER.exception("[Transcript migration] save_transcript_to_storage_failed: %s", err)
        raise