Google's YouTube Data API has a captions resource, but it gives caption text only for videos you can edit. For any other public video it returns track metadata and no text. Our API returns a public video's transcript as JSON with timestamps, from a video ID or URL, for 1 credit.
What Google's captions API allows
The captions resource has two read methods. captions.list returns a video's caption tracks without the text. captions.download takes a track ID and returns the track as SRT, VTT, TTML, SBV or SCC, or a machine translation with tlang.
Both need OAuth with the youtube.force-ssl or youtubepartner scope, and download needs permission to edit the video, or it returns 403 forbidden. Use Google's API for videos you can edit, where it also uploads and edits captions.
The quota:
captions.list: 50 units.captions.download: 200 units.- One transcript: 250 units, so 40 transcripts a day from the default 10,000 units.
- More quota needs Google's quota extension form. Searches use a separate bucket of 100 calls a day; see the YouTube search API quota.
Get a transcript with ToolzerHub
We make ToolzerHub. Our YouTube API returns the transcript of a public video as JSON with one API key: no Google Cloud project, no OAuth and no access to the channel. video_reference takes a video ID or a watch, youtu.be, Shorts or embed URL. The YouTube reference lists all 29 endpoints under /v2/youtube/.
curl "https://api.toolzerhub.com/v2/youtube/transcript?video_reference=M7lc1UVf-VE&language_code=en" \
-H "x-api-key: $TOOLZERHUB_API_KEY"
The response shape, from the API reference:
{
"data": {
"id": "string",
"transcript": [
{
"startMs": "string",
"endMs": "string",
"startTime": "string",
"text": "string"
}
]
}
}
transcriptis a list of timed segments. Each has the line'stext, itsstartMsandendMs, and a displaystartTime.- The millisecond fields are strings. Convert them to numbers before you do arithmetic.
language_codepicks the transcript language. There is no cursor: one call returns one video, and whether a transcript exists depends on the video's published captions.
For an SRT or VTT file, GET /v2/youtube/subtitles lists a video's caption tracks with each track's language and url. Pass that url as caption_source to GET /v2/youtube/subtitle with caption_style set to srt or vtt; json3, srv1, srv2, srv3 and ttml also work. Add translation_code for a translation. That is 2 calls per video.
What it costs
Every call costs 1 credit and returns one video's transcript, so 1,000 transcripts cost 1,000 credits. The SRT or VTT route is 2 credits per video. You get 100 free credits a month; $19 buys 10,000 credits that never expire, and plans for higher volume cover more videos. Get a free API key and run the request above.
For a few videos from your own computer, the open-source youtube-transcript-api Python library is free and needs no API key, but it uses an undocumented part of YouTube's API. For other YouTube jobs see how to get all comments and all videos from a channel.
We are not affiliated with YouTube or Google.
Sources
- YouTube Data API
captions.download, https://developers.google.com/youtube/v3/docs/captions/download - YouTube Data API
captions.list, https://developers.google.com/youtube/v3/docs/captions/list - Captions resource, https://developers.google.com/youtube/v3/docs/captions
- Quota costs, https://developers.google.com/youtube/v3/determine_quota_cost
- Getting started (default quota, extension form), https://developers.google.com/youtube/v3/getting-started
- Authentication guide, https://developers.google.com/youtube/v3/guides/authentication
- ToolzerHub transcript reference, https://docs.toolzerhub.com/reference/youtube/video/get-you-tube-transcript
- ToolzerHub YouTube reference (29 endpoints), https://docs.toolzerhub.com/reference/youtube
- youtube-transcript-api README, https://github.com/jdepoix/youtube-transcript-api
- ToolzerHub plans and credit packs, https://toolzerhub.com/pricing