Beispiel #1
0
def create_video_transcript(video_id,
                            language_code,
                            file_format,
                            content,
                            provider=TranscriptProviderType.CUSTOM):
    """
    Create a video transcript.

    Arguments:
        video_id(unicode): An Id identifying the Video data model object.
        language_code(unicode): A language code.
        file_format(unicode): Transcript file format.
        content(InMemoryUploadedFile): Transcript content.
        provider(unicode): Transcript provider (it will be 'custom' by default if not selected).
    """
    transcript_serializer = TranscriptSerializer(
        data=dict(provider=provider,
                  language_code=language_code,
                  file_format=file_format),
        context=dict(video_id=video_id),
    )
    if transcript_serializer.is_valid():
        transcript_serializer.save(content=content)
        return transcript_serializer.data

    raise ValCannotCreateError(transcript_serializer.errors)
Beispiel #2
0
def get_video_transcript(video_id, language_code):
    """
    Get video transcript info

    Arguments:
        video_id(unicode): A video id, it can be an edx_video_id or an external video id extracted from
        external sources of a video component.
        language_code(unicode): it will be the language code of the requested transcript.
    """
    transcript = VideoTranscript.get_or_none(video_id=video_id, language_code=language_code)
    return TranscriptSerializer(transcript).data if transcript else None
Beispiel #3
0
def create_video_transcript(video_id, language_code, file_format, content, provider=TranscriptProviderType.CUSTOM):
    """
    Create a video transcript.

    Arguments:
        video_id(unicode): An Id identifying the Video data model object.
        language_code(unicode): A language code.
        file_format(unicode): Transcript file format.
        content(InMemoryUploadedFile): Transcript content.
        provider(unicode): Transcript provider (it will be 'custom' by default if not selected).
    """
    transcript_serializer = TranscriptSerializer(
        data=dict(provider=provider, language_code=language_code, file_format=file_format),
        context=dict(video_id=video_id),
    )
    if transcript_serializer.is_valid():
        transcript_serializer.save(content=content)
        return transcript_serializer.data
    else:
        raise ValCannotCreateError(transcript_serializer.errors)
Beispiel #4
0
    def test_create_transcript(self):
        """
        Tests POSTing transcript successfully.
        """
        post_transcript_data = dict(self.transcript_data)
        post_transcript_data['name'] = post_transcript_data.pop('transcript')

        response = self.client.post(self.url, post_transcript_data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        serialized_data = TranscriptSerializer(VideoTranscript.objects.first()).data
        post_transcript_data['url'] = post_transcript_data.pop('name')
        self.assertEqual(serialized_data, post_transcript_data)
Beispiel #5
0
def get_video_transcripts(video_id):
    """
    Get a video's transcripts

    Arguments:
        video_id: it can be an edx_video_id or an external_id extracted from external sources in a video component.
    """
    transcripts_set = VideoTranscript.objects.filter(video_id=video_id)

    transcripts = []
    if transcripts_set.exists():
        transcripts = TranscriptSerializer(transcripts_set, many=True).data

    return transcripts