Ejemplo n.º 1
0
def rename_transcripts(request):
    """
    Copies existing transcript on video component's `sub`(from contentstore) into the
    DS for a video.

    Returns:
        status `Success` and resulted `edx_video_id` value
        Or error in case of validation failures.
    """
    error, validated_data = validate_transcripts_request(request)
    if error:
        response = error_response({}, error)
    else:
        # 1. Retrieve transcript file for `video.sub` from contentstore.
        try:
            video = validated_data['video']
            input_format, __, transcript_content = get_transcript_for_video(
                video.location,
                subs_id=video.sub,
                file_name=video.sub,
                language=u'en')
        except NotFoundError:
            return error_response({}, _('No such transcript.'))

        # 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 the retrieved transcript to DS for the linked video ID.
        success = save_video_transcript(edx_video_id,
                                        input_format,
                                        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 existing transcript file. Please upload a different file.'
                  ))

    return response
Ejemplo n.º 2
0
def choose_transcripts(request):
    """
    Create/Update edx transcript in DS with chosen html5 subtitles from contentstore.

    Returns:
        status `Success` and resulted `edx_video_id` value
        Or error in case of validation failures.
    """
    error, validated_data = validate_transcripts_request(request,
                                                         include_html5=True)
    if error:
        response = error_response({}, error)
    else:
        # 1. Retrieve transcript file for `chosen_html5_id` from contentstore.
        try:
            video = validated_data['video']
            chosen_html5_id = validated_data['chosen_html5_id']
            input_format, __, transcript_content = get_transcript_for_video(
                video.location,
                subs_id=chosen_html5_id,
                file_name=chosen_html5_id,
                language=u'en')
        except NotFoundError:
            return error_response({}, _('No such transcript.'))

        # 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 the retrieved transcript to DS for the linked video ID.
        success = save_video_transcript(edx_video_id,
                                        input_format,
                                        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 chosen transcript file.'))

    return response
Ejemplo n.º 3
0
def rename_transcripts(request):
    """
    Copies existing transcript on video component's `sub`(from contentstore) into the
    DS for a video.

    Returns:
        status `Success` and resulted `edx_video_id` value
        Or error in case of validation failures.
    """
    error, validated_data = validate_transcripts_request(request)
    if error:
        response = error_response({}, error)
    else:
        # 1. Retrieve transcript file for `video.sub` from contentstore.
        try:
            video = validated_data['video']
            input_format, __, transcript_content = get_transcript_for_video(
                video.location,
                subs_id=video.sub,
                file_name=video.sub,
                language=u'en'
            )
        except NotFoundError:
            return error_response({}, _('No such transcript.'))

        # 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 the retrieved transcript to DS for the linked video ID.
        success = save_video_transcript(edx_video_id, input_format, 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 existing transcript file. Please upload a different file.')
            )

    return response
Ejemplo n.º 4
0
def choose_transcripts(request):
    """
    Create/Update edx transcript in DS with chosen html5 subtitles from contentstore.

    Returns:
        status `Success` and resulted `edx_video_id` value
        Or error in case of validation failures.
    """
    error, validated_data = validate_transcripts_request(request, include_html5=True)
    if error:
        response = error_response({}, error)
    else:
        # 1. Retrieve transcript file for `chosen_html5_id` from contentstore.
        try:
            video = validated_data['video']
            chosen_html5_id = validated_data['chosen_html5_id']
            input_format, __, transcript_content = get_transcript_for_video(
                video.location,
                subs_id=chosen_html5_id,
                file_name=chosen_html5_id,
                language=u'en'
            )
        except NotFoundError:
            return error_response({}, _('No such transcript.'))

        # 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 the retrieved transcript to DS for the linked video ID.
        success = save_video_transcript(edx_video_id, input_format, 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 chosen transcript file.'))

    return response