YouTube Transcripts API
YouTube Transcripts API allows you to get the transcript/subtitles for a given YouTube video. It uses /api/v1/search?engine=youtube_transcripts
API endpoint to scrape real-time search results.
API Parameters
Search Query
-
- Name
-
video_id
- Required
- Required
- Description
-
Parameter defines the video_id you want to search. You can find these values in JSON responses in YouTube engine or in YouTube page that appears in URL:
https://www.youtube.com/watch?v=video_id
.
Localization
-
- Name
-
lang
- Required
- Optional
- Description
-
The parameter
en
sets the default language for transcripts. While a variety of languages are supported, often only a few are available. Review the list of known supported YouTube Transcript languages.
Filters
-
- Name
-
transcript_type
- Required
- Optional
- Description
-
Defines the transcript preference when both auto-generated and manually uploaded transcripts are available.
auto
- Prioritize YouTube's auto-generated transcript.manual
- Prioritize user-uploaded transcript.
Engine
-
- Name
-
engine
- Required
- Required
- Description
-
Parameter defines an engine that will be used to retrieve real-time data. Current engine -
youtube_transcripts
.
API key
-
- Name
-
api_key
- Required
- Required
- Description
-
The
api_key
authenticates your requests. Use it as a query parameter (https://www.searchapi.io/api/v1/search?api_key=YOUR_API_KEY
) or in the Authorization header (Bearer YOUR_API_KEY
).
API Examples
Full Response
https://www.searchapi.io/api/v1/search?engine=youtube_transcripts&video_id=0e3GPea1Tyg
- Python
- Node
- Ruby
- Java
- Go
- PHP
- Bash
- R
- Kotlin
- Swift
- C#
- C
- C++
- requests
import requests
url = "https://www.searchapi.io/api/v1/search"
params = {
"engine": "youtube_transcripts",
"video_id": "0e3GPea1Tyg"
}
response = requests.get(url, params=params)
print(response.text)
{
"search_metadata": {
"id": "search_xRvzEGkNolVqF6MLpj4Q9WJb",
"status": "Success",
"created_at": "2023-09-15T13:59:31Z",
"request_time_taken": 1.79,
"parsing_time_taken": 0.01,
"total_time_taken": 1.8,
"request_url": "https://www.youtube.com/watch?v=0e3GPea1Tyg",
"html_url": "https://www.searchapi.io/api/v1/searches/search_xRvzEGkNolVqF6MLpj4Q9WJb.html",
"json_url": "https://www.searchapi.io/api/v1/searches/search_xRvzEGkNolVqF6MLpj4Q9WJb"
},
"search_parameters": {
"engine": "youtube_transcripts",
"video_id": "0e3GPea1Tyg",
"lang": "en"
},
"transcripts": [
{
"text": "- [Mr. Beast] I've recreated every single set",
"start": 0.15,
"duration": 1.773
},
{
"text": "from Squid Game in real life,",
"start": 1.923,
"duration": 1.857
},
{
"text": "and whichever one of these 456 people survives the longest,",
"start": 3.78,
"duration": 3.6
},
{
"text": "wins 456 grand.",
"start": 7.38,
"duration": 2.1
},
{
"text": "(contestants cheering)",
"start": 9.48,
"duration": 1.38
},
{
"text": "The first game we're gonna play is red light, green light.",
"start": 10.86,
"duration": 2.37
},
...
],
"available_languages": [
{
"name": "Arabic",
"lang": "ar"
},
{
"name": "Chinese (Traditional)",
"lang": "zh-Hant"
},
{
"name": "Czech",
"lang": "cs"
},
{
"name": "English",
"lang": "en"
},
{
"name": "English (auto-generated)",
"lang": "en"
},
...
],
}
Transcripts Available in Other Languages
If the selected language is not available, the API will return available_languages
with the list of options.
You can then retry and use the language
parameter to get the transcript in the desired language.
https://www.searchapi.io/api/v1/search?engine=youtube_transcripts&lang=hi&video_id=MVYrJJNdrEg
- Python
- Node
- Ruby
- Java
- Go
- PHP
- Bash
- R
- Kotlin
- Swift
- C#
- C
- C++
- requests
import requests
url = "https://www.searchapi.io/api/v1/search"
params = {
"engine": "youtube_transcripts",
"video_id": "MVYrJJNdrEg",
"lang": "hi"
}
response = requests.get(url, params=params)
print(response.text)
{
...,
"search_parameters": {
"engine": "youtube_transcripts",
"video_id": "MVYrJJNdrEg",
"lang": "hi"
},
"available_languages": [
{
"name": "English (auto-generated)",
"lang": "en"
},
{
"name": "English (United States)",
"lang": "en-US"
}
],
"error": "Selected language hasn't been transcribed. Check `available_languages`."
}