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:
-
Prepare your request:
id
: The ID of the video you want to add subtitles tolanguage
: The 3-letter language code (ISO-639-2) for the subtitles
-
Set up your request headers:
Content-Type: multipart/form-data
Accept: application/json
Authorization: YOUR_API_KEY -
In the request body, include the following parameters:
ai_generated
: Set to "false" if you're uploading manually created subtitlespublished
: Set to "true" to make the subtitles immediately availablefile
: The subtitle file (typically in VTT format)
-
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" -
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:
-
Use the
GET /videos/{id}/captions/{language}
endpoint -
Replace
{id}
with the video ID and{language}
with the 3-letter language code -
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:
-
Use the
DELETE /videos/{id}/captions/{language}
endpoint -
Replace
{id}
with the video ID and{language}
with the 3-letter language code -
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
-
Language Support: The API supports multiple languages. Make sure to use the correct 3-letter language code when uploading or managing subtitles.
-
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.
-
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. -
Publishing: You can upload subtitles without immediately publishing them by setting
published
to "false". This allows for review before making them available to viewers. -
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.