Subtitles
Extract YouTube subtitles and closed captions by video ID, with configurable language and subtitle origin (auto-generated or uploader-provided).
You can get YouTube subtitles and closed captions (CC) by providing the YouTube video ID and a language_code to the youtube_subtitles source.
Request samples
The following example demonstrates how to retrieve English closed captions from a YouTube video where captions were provided by the uploader.
curl 'https://realtime.oxylabs.io/v1/queries' \
--user 'USERNAME:PASSWORD' \
-H 'Content-Type: application/json' \
-d '{
"source": "youtube_subtitles",
"query": "c4P_YuNnZ7U",
"context": [
{
"key": "language_code",
"value": "en"
},
{
"key": "subtitle_origin",
"value": "uploader_provided"
}
]
}'import requests
from pprint import pprint
# Structure payload.
payload = {
'source': 'youtube_subtitles',
'query': 'c4P_YuNnZ7U',
'context': [
{
'key': 'language_code',
'value': 'en'
},
{
'key': 'subtitle_origin',
'value': 'uploader_provided'
}
]
}
# Get response.
response = requests.request(
'POST',
'https://realtime.oxylabs.io/v1/queries',
auth=('username', 'password'),
json=payload,
)
# Print the JSON response with the result.
pprint(response.json())We use synchronous Realtime integration method in our examples. If you would like to use Proxy Endpoint or asynchronous Push-Pull integration, refer to the integration methods section.
Request parameter values
Generic
source
Sets the scraper.
youtube_subtitles
query
YouTube video ID.
–
context:
language_code
Specifies the language of the subtitles. Find available values here.
NOTE: If the provided language_code has no matching subtitles / closed captions in the YouTube video, the result returns a 404 status.
–
context:
subtitle_origin
Specifies whether to retrieve subtitles that are auto_generated or uploader_provided.
–
– mandatory parameter
Error codes
11201
VIDEO_DELETED
Video is deleted.
11203
VIDEO_PRIVATE
Video is set to private by uploader and only they and explicitly invited people can see it.
11204
VIDEO_GEO_RESTRICTED
Video is geo-restricted.
11205
VIDEO_LIVE
Video is live now.
11206
VIDEO_AGE_RESTRICTED
Video is age restricted.
11207
VIDEO_MEMBER_ONLY
Video is for channel members only, and viewers have to pay the monthly subscription fee.
11208
VIDEO_PREMIUM_ONLY
Video requires the YouTube Premium subscription.
Last updated
Was this helpful?

