Esempio n. 1
0
    def test_migrated_transcripts_without_commit(self):
        """
        Test migrating transcripts as a dry-run
        """
        # check that transcripts do not exist
        languages = api.get_available_transcript_languages(
            self.video_descriptor.edx_video_id)
        self.assertEqual(len(languages), 0)
        self.assertFalse(
            api.is_transcript_available(self.video_descriptor.edx_video_id,
                                        'hr'))
        self.assertFalse(
            api.is_transcript_available(self.video_descriptor.edx_video_id,
                                        'ge'))

        # now call migrate_transcripts command and check the transcript availability
        call_command('migrate_transcripts', '--course-id',
                     unicode(self.course.id))

        # check that transcripts still do not exist
        languages = api.get_available_transcript_languages(
            self.video_descriptor.edx_video_id)
        self.assertEqual(len(languages), 0)
        self.assertFalse(
            api.is_transcript_available(self.video_descriptor.edx_video_id,
                                        'hr'))
        self.assertFalse(
            api.is_transcript_available(self.video_descriptor.edx_video_id,
                                        'ge'))
Esempio n. 2
0
    def test_migrated_transcripts_count_with_commit(self):
        """
        Test migrating transcripts with commit
        """
        # check that transcript does not exist
        languages = api.get_available_transcript_languages(
            self.video_descriptor.edx_video_id)
        self.assertEqual(len(languages), 0)
        self.assertFalse(
            api.is_transcript_available(self.video_descriptor.edx_video_id,
                                        'hr'))
        self.assertFalse(
            api.is_transcript_available(self.video_descriptor.edx_video_id,
                                        'ge'))

        # now call migrate_transcripts command and check the transcript availability
        call_command('migrate_transcripts', '--course-id',
                     unicode(self.course.id), '--commit')

        languages = api.get_available_transcript_languages(
            self.video_descriptor.edx_video_id)
        self.assertEqual(len(languages), 2)
        self.assertTrue(
            api.is_transcript_available(self.video_descriptor.edx_video_id,
                                        'hr'))
        self.assertTrue(
            api.is_transcript_available(self.video_descriptor.edx_video_id,
                                        'ge'))
Esempio n. 3
0
def _get_videos(course, pagination_conf=None):
    """
    Retrieves the list of videos from VAL corresponding to this course.
    """
    videos, pagination_context = get_videos_for_course(
        unicode(course.id),
        VideoSortField.created,
        SortDirection.desc,
        pagination_conf
    )
    videos = list(videos)

    # This is required to see if edx video pipeline is enabled while converting the video status.
    course_video_upload_token = course.video_upload_pipeline.get('course_video_upload_token')

    # convert VAL's status to studio's Video Upload feature status.
    for video in videos:
        # If we are using "new video workflow" and status is `transcription_in_progress` then video encodes are ready.
        # This is because Transcription starts once all the encodes are complete except for YT, but according to
        # "new video workflow" YT is disabled as well as deprecated. So, Its precise to say that the Transcription
        # starts once all the encodings are complete *for the new video workflow*.
        is_video_encodes_ready = not course_video_upload_token and video['status'] == 'transcription_in_progress'
        # Update with transcript languages
        video['transcripts'] = get_available_transcript_languages(video_id=video['edx_video_id'])
        # Transcription status should only be visible if 3rd party transcripts are pending.
        video['transcription_status'] = (
            StatusDisplayStrings.get(video['status'])
            if not video['transcripts'] and is_video_encodes_ready else
            ''
        )
        # Convert the video status.
        video['status'] = convert_video_status(video, is_video_encodes_ready)

    return videos, pagination_context
Esempio n. 4
0
def validate_transcript_upload_data(data, files):
    """
    Validates video transcript file.
    Arguments:
        data: A request's data part.
        files: A request's files part.
    Returns:
        None or String
        If there is error returns error message otherwise None.
    """
    error = None
    # Validate the must have attributes - this error is unlikely to be faced by common users.
    must_have_attrs = ['edx_video_id', 'language_code', 'new_language_code']
    missing = [attr for attr in must_have_attrs if attr not in data]
    if missing:
        error = _(u'The following parameters are required: {missing}.').format(missing=', '.join(missing))
    elif (
        data['language_code'] != data['new_language_code'] and
        data['new_language_code'] in get_available_transcript_languages(video_id=data['edx_video_id'])
    ):
        error = _(u'A transcript with the "{language_code}" language code already exists.'.format(
            language_code=data['new_language_code']
        ))
    elif 'file' not in files:
        error = _(u'A transcript file is required.')

    return error
Esempio n. 5
0
def validate_transcript_upload_data(data, files):
    """
    Validates video transcript file.
    Arguments:
        data: A request's data part.
        files: A request's files part.
    Returns:
        None or String
        If there is error returns error message otherwise None.
    """
    error = None
    # Validate the must have attributes - this error is unlikely to be faced by common users.
    must_have_attrs = ['edx_video_id', 'language_code', 'new_language_code']
    missing = [attr for attr in must_have_attrs if attr not in data]
    if missing:
        error = _(u'The following parameters are required: {missing}.').format(missing=', '.join(missing))
    elif (
        data['language_code'] != data['new_language_code'] and
        data['new_language_code'] in get_available_transcript_languages(video_id=data['edx_video_id'])
    ):
        error = _(u'A transcript with the "{language_code}" language code already exists.'.format(
            language_code=data['new_language_code']
        ))
    elif 'file' not in files:
        error = _(u'A transcript file is required.')

    return error
Esempio n. 6
0
def _get_videos(course):
    """
    Retrieves the list of videos from VAL corresponding to this course.
    """
    videos = list(get_videos_for_course(unicode(course.id), VideoSortField.created, SortDirection.desc))

    # This is required to see if edx video pipeline is enabled while converting the video status.
    course_video_upload_token = course.video_upload_pipeline.get('course_video_upload_token')

    # convert VAL's status to studio's Video Upload feature status.
    for video in videos:
        # If we are using "new video workflow" and status is `transcription_in_progress` then video encodes are ready.
        # This is because Transcription starts once all the encodes are complete except for YT, but according to
        # "new video workflow" YT is disabled as well as deprecated. So, Its precise to say that the Transcription
        # starts once all the encodings are complete *for the new video workflow*.
        is_video_encodes_ready = not course_video_upload_token and video['status'] == 'transcription_in_progress'
        # Update with transcript languages
        video['transcripts'] = get_available_transcript_languages(video_id=video['edx_video_id'])
        # Transcription status should only be visible if 3rd party transcripts are pending.
        video['transcription_status'] = (
            StatusDisplayStrings.get(video['status'])
            if not video['transcripts'] and is_video_encodes_ready else
            ''
        )
        # Convert the video status.
        video['status'] = convert_video_status(video, is_video_encodes_ready)

    return videos
    def test_migrated_transcripts_count_with_commit(self):
        """
        Test migrating transcripts with commit
        """
        # check that transcript does not exist
        languages = api.get_available_transcript_languages(self.video_descriptor.edx_video_id)
        self.assertEqual(len(languages), 0)
        self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'hr'))
        self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge'))

        # now call migrate_transcripts command and check the transcript availability
        call_command('migrate_transcripts', '--course-id', unicode(self.course.id), '--commit')

        languages = api.get_available_transcript_languages(self.video_descriptor.edx_video_id)
        self.assertEqual(len(languages), 2)
        self.assertTrue(api.is_transcript_available(self.video_descriptor.edx_video_id, 'hr'))
        self.assertTrue(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge'))
    def test_migrated_transcripts_without_commit(self):
        """
        Test migrating transcripts as a dry-run
        """
        # check that transcripts do not exist
        languages = api.get_available_transcript_languages(self.video_descriptor.edx_video_id)
        self.assertEqual(len(languages), 0)
        self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'hr'))
        self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge'))

        # now call migrate_transcripts command and check the transcript availability
        call_command('migrate_transcripts', '--course-id', unicode(self.course.id))

        # check that transcripts still do not exist
        languages = api.get_available_transcript_languages(self.video_descriptor.edx_video_id)
        self.assertEqual(len(languages), 0)
        self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'hr'))
        self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge'))
Esempio n. 9
0
def _get_videos(course):
    """
    Retrieves the list of videos from VAL corresponding to this course.
    """
    videos = list(get_videos_for_course(unicode(course.id), VideoSortField.created, SortDirection.desc))

    # convert VAL's status to studio's Video Upload feature status.
    for video in videos:
        video["status"] = convert_video_status(video)
        video['transcripts'] = get_available_transcript_languages(video_id=video['edx_video_id'])

    return videos
Esempio n. 10
0
def _get_videos(course):
    """
    Retrieves the list of videos from VAL corresponding to this course.
    """
    videos = list(get_videos_for_course(unicode(course.id), VideoSortField.created, SortDirection.desc))

    # convert VAL's status to studio's Video Upload feature status.
    for video in videos:
        video["status"] = convert_video_status(video)
        video['transcripts'] = get_available_transcript_languages(video_id=video['edx_video_id'])

    return videos
def get_available_transcript_languages(edx_video_id):
    """
    Gets available transcript languages for a video.

    Arguments:
        edx_video_id(unicode): edx-val's video identifier

    Returns:
        A list containing distinct transcript language codes against all the passed video ids.
    """
    available_languages = []
    edx_video_id = clean_video_id(edx_video_id)
    if edxval_api and edx_video_id:
        available_languages = edxval_api.get_available_transcript_languages(video_id=edx_video_id)

    return available_languages
Esempio n. 12
0
def get_available_transcript_languages(edx_video_id):
    """
    Gets available transcript languages for a video.

    Arguments:
        edx_video_id(unicode): edx-val's video identifier

    Returns:
        A list containing distinct transcript language codes against all the passed video ids.
    """
    available_languages = []
    edx_video_id = clean_video_id(edx_video_id)
    if edxval_api and edx_video_id:
        available_languages = edxval_api.get_available_transcript_languages(video_id=edx_video_id)

    return available_languages
Esempio n. 13
0
def get_available_transcript_languages(edx_video_id, youtube_id_1_0, html5_sources):
    """
    Gets available transcript languages from edx-val.

    Arguments:
        edx_video_id(unicode): edx-val's video identifier
        youtube_id_1_0(unicode): A youtube source identifier
        html5_sources(list): A list containing html5 sources

    Returns:
        A list containing distinct transcript language codes against all the passed video ids.
    """
    available_languages = []
    if edxval_api:
        __, video_candidate_ids = get_video_ids_info(edx_video_id, youtube_id_1_0, html5_sources)
        available_languages = edxval_api.get_available_transcript_languages(video_candidate_ids)

    return available_languages
Esempio n. 14
0
def get_available_transcript_languages(edx_video_id, youtube_id_1_0, html5_sources):
    """
    Gets available transcript languages from edx-val.

    Arguments:
        edx_video_id(unicode): edx-val's video identifier
        youtube_id_1_0(unicode): A youtube source identifier
        html5_sources(list): A list containing html5 sources

    Returns:
        A list containing distinct transcript language codes against all the passed video ids.
    """
    available_languages = []
    if edxval_api:
        __, video_candidate_ids = get_video_ids_info(edx_video_id, youtube_id_1_0, html5_sources)
        available_languages = edxval_api.get_available_transcript_languages(video_candidate_ids)

    return available_languages
Esempio n. 15
0
def _get_videos(course, pagination_conf=None):
    """
    Retrieves the list of videos from VAL corresponding to this course.
    """
    videos, pagination_context = get_videos_for_course(
        six.text_type(course.id),
        VideoSortField.created,
        SortDirection.desc,
        pagination_conf
    )
    videos = list(videos)

    # This is required to see if edx video pipeline is enabled while converting the video status.
    course_video_upload_token = course.video_upload_pipeline.get('course_video_upload_token')
    # TODO: add 'transcript_ready' when we have moved to VEM to keep transcript and encode status separate
    transcription_statuses = ['partial_failure', 'transcription_in_progress']

    # convert VAL's status to studio's Video Upload feature status.
    for video in videos:
        # If we are using "new video workflow" and status is `transcription_in_progress` then video encodes are ready.
        # This is because Transcription starts once all the encodes are complete except for YT, but according to
        # "new video workflow" YT is disabled as well as deprecated. So, Its precise to say that the Transcription
        # starts once all the encodings are complete *for the new video workflow*.
        # If the video status is 'partial_failure', it means during the transcription flow, some transcription jobs
        # failed. As mentioned, transcript jobs start only when the encodes have finished
        is_video_encodes_ready = not course_video_upload_token and (video['status'] in transcription_statuses)
        # Update with transcript languages
        video['transcripts'] = get_available_transcript_languages(video_id=video['edx_video_id'])
        # Transcription status should only be visible if 3rd party transcripts are pending.
        # TODO: change logic to separate transcript status from video status
        video['transcription_status'] = (
            StatusDisplayStrings.get(video['status'])
            if not video['transcripts'] and is_video_encodes_ready else
            ''
        )
        # Convert the video status.
        video['status'] = convert_video_status(video, is_video_encodes_ready)

    return videos, pagination_context
Esempio n. 16
0
def _get_videos(course):
    """
    Retrieves the list of videos from VAL corresponding to this course.
    """
    is_video_transcript_enabled = VideoTranscriptEnabledFlag.feature_enabled(
        course.id)
    videos = list(
        get_videos_for_course(unicode(course.id), VideoSortField.created,
                              SortDirection.desc))

    # convert VAL's status to studio's Video Upload feature status.
    for video in videos:
        video["status"] = convert_video_status(video)

        if is_video_transcript_enabled:
            all_languages = get_all_transcript_languages()
            video['transcripts'] = {
                lang_code: all_languages[lang_code]
                for lang_code in get_available_transcript_languages(
                    [video['edx_video_id']])
            }

    return videos