Skip to main content

How to add subtitles

How to add subtitles

Managing Subtitles with Teyuto API

Subtitles play a crucial role in making video content accessible to a wider audience. This guide will walk you through the process of uploading and managing subtitles using the Teyuto API.

Uploading Subtitles

To add subtitles to a video, you'll use the POST /videos/{id}/captions/{language} endpoint. Here's how to do it:

  1. Prepare your request:

    • id: The ID of the video you want to add subtitles to
    • language: The 3-letter language code (ISO-639-2) for the subtitles
  2. Set up your request headers:

    Content-Type: multipart/form-data
    Accept: application/json
    Authorization: YOUR_API_KEY
  3. In the request body, include the following parameters:

    • ai_generated: Set to "false" if you're uploading manually created subtitles
    • published: Set to "true" to make the subtitles immediately available
    • file: The subtitle file (typically in VTT format)
  4. Send a POST request to the endpoint. Here's an example using cURL:

    curl -X POST "https://api.teyuto.tv/v2/videos/12345/captions/eng" \
    -H "Content-Type: multipart/form-data" \
    -H "Accept: application/json" \
    -H "Authorization: YOUR_API_KEY" \
    -F "ai_generated=false" \
    -F "published=true" \
    -F "file=@/path/to/your/subtitle_file.vtt"
  5. If successful, you'll receive a response with details about the uploaded subtitles, including the id_caption which you'll need for future operations.

Retrieving Subtitles

To get information about the subtitles for a specific video:

  1. Use the GET /videos/{id}/captions/{language} endpoint

  2. Replace {id} with the video ID and {language} with the 3-letter language code

  3. Send a GET request. Example:

    curl -X GET "https://api.teyuto.tv/v2/videos/12345/captions/eng" \
    -H "Accept: application/json" \
    -H "Authorization: YOUR_API_KEY"

This will return details about the subtitle, including its content (vtt) and status.

Deleting Subtitles

To remove subtitles from a video:

  1. Use the DELETE /videos/{id}/captions/{language} endpoint

  2. Replace {id} with the video ID and {language} with the 3-letter language code

  3. Send a DELETE request. Example:

    curl -X DELETE "https://api.teyuto.tv/v2/videos/12345/captions/eng" \
    -H "Accept: application/json" \
    -H "Authorization: YOUR_API_KEY"

Best Practices

  1. Language Support: The API supports multiple languages. Make sure to use the correct 3-letter language code when uploading or managing subtitles.

  2. File Format: Although not explicitly mentioned in the API spec, it's best to use the VTT (Web Video Text Tracks) format for subtitles, as it's widely supported.

  3. AI-Generated Subtitles: The API allows for both manual and AI-generated subtitles. If you're using an AI service to generate subtitles, set ai_generated to "true" when uploading.

  4. Publishing: You can upload subtitles without immediately publishing them by setting published to "false". This allows for review before making them available to viewers.

  5. Error Handling: Always check the response status and handle potential errors, such as 400 (Bad Request) or 401 (Unauthorized).

By following these guidelines, you can effectively manage subtitles for your videos using the Teyuto API, enhancing the accessibility and reach of your content.