Interface YoutubeTranscriptApi
It provides functionality for retrieving all available transcripts or retrieving actual transcript content for a single video, playlist, or channel.
To instantiate this API, you should use TranscriptApiFactory
.
-
Method Summary
Modifier and TypeMethodDescriptiongetTranscript
(String videoId, String... languageCodes) Retrieves transcript content for a single video.getTranscriptsForChannel
(String channelName, TranscriptRequest request, String... languageCodes) Retrieves transcript content for all videos for the specified channel.getTranscriptsForPlaylist
(String playlistId, TranscriptRequest request, String... languageCodes) Retrieves transcript content for all videos in the specified playlist.getTranscriptWithCookies
(String videoId, String cookiesPath, String... languageCodes) Retrieves transcript content for a given video using cookies from a specified file path.listTranscripts
(String videoId) Retrieves a list of available transcripts for a given video.listTranscriptsForChannel
(String channelName, TranscriptRequest request) Retrieves transcript lists for all videos for the specified channel.listTranscriptsForPlaylist
(String playlistId, TranscriptRequest request) Retrieves transcript lists for all videos in the specified playlist.listTranscriptsWithCookies
(String videoId, String cookiesPath) Retrieves a list of available transcripts for a given video using cookies from a specified file path.
-
Method Details
-
listTranscriptsWithCookies
TranscriptList listTranscriptsWithCookies(String videoId, String cookiesPath) throws TranscriptRetrievalException Retrieves a list of available transcripts for a given video using cookies from a specified file path.Used when you want to list transcripts for a video that is age-restricted. It tries to bypass the age-restriction by using the provided authentication cookies.
Note: For more information on how to obtain the authentication cookies, see the GitHub page.
- Parameters:
videoId
- The ID of the videocookiesPath
- The file path to the text file containing the authentication cookies- Returns:
TranscriptList
A list of all available transcripts for the given video- Throws:
TranscriptRetrievalException
- If the retrieval of the transcript list failsIllegalArgumentException
- If the video ID is invalid
-
listTranscripts
Retrieves a list of available transcripts for a given video.- Parameters:
videoId
- The ID of the video- Returns:
TranscriptList
A list of all available transcripts for the given video- Throws:
TranscriptRetrievalException
- If the retrieval of the transcript list failsIllegalArgumentException
- If the video ID is invalid
-
getTranscriptWithCookies
TranscriptContent getTranscriptWithCookies(String videoId, String cookiesPath, String... languageCodes) throws TranscriptRetrievalException Retrieves transcript content for a given video using cookies from a specified file path.Used when you want to retrieve transcript content for a video that is age-restricted. It tries to bypass the age-restriction by using the provided authentication cookies.
Note: For more information on how to obtain the authentication cookies, see the GitHub page.
This is a shortcut for calling:
listTranscriptsWithCookies(videoId).findTranscript(languageCodes).fetch();
- Parameters:
videoId
- The ID of the videocookiesPath
- The file path to the text file containing the authentication cookieslanguageCodes
- A varargs list of language codes in descending priority.For example:
If this is set to("de", "en")
, it will first attempt to fetch the German transcript ("de"), and then fetch the English transcript ("en") if the former fails. If no language code is provided, it uses English as the default language.- Returns:
TranscriptContent
The transcript content- Throws:
TranscriptRetrievalException
- If the retrieval of the transcript failsIllegalArgumentException
- If the video ID is invalid
-
getTranscript
TranscriptContent getTranscript(String videoId, String... languageCodes) throws TranscriptRetrievalException Retrieves transcript content for a single video.This is a shortcut for calling:
listTranscripts(videoId).findTranscript(languageCodes).fetch();
- Parameters:
videoId
- The ID of the videolanguageCodes
- A varargs list of language codes in descending priority.For example:
If this is set to("de", "en")
, it will first attempt to fetch the German transcript ("de"), and then fetch the English transcript ("en") if the former fails. If no language code is provided, it uses English as the default language.- Returns:
TranscriptContent
The transcript content- Throws:
TranscriptRetrievalException
- If the retrieval of the transcript failsIllegalArgumentException
- If the video ID is invalid
-
listTranscriptsForPlaylist
Map<String,TranscriptList> listTranscriptsForPlaylist(String playlistId, TranscriptRequest request) throws TranscriptRetrievalException Retrieves transcript lists for all videos in the specified playlist.- Parameters:
playlistId
- The ID of the playlistrequest
-TranscriptRequest
request object containing API key, cookies file path, and stop on error flag- Returns:
- A map of video IDs to
TranscriptList
objects - Throws:
TranscriptRetrievalException
- If the retrieval of the transcript lists fails
-
listTranscriptsForChannel
Map<String,TranscriptList> listTranscriptsForChannel(String channelName, TranscriptRequest request) throws TranscriptRetrievalException Retrieves transcript lists for all videos for the specified channel.- Parameters:
channelName
- The name of the channelrequest
-TranscriptRequest
request object containing API key, cookies file path, and stop on error flag- Returns:
- A map of video IDs to
TranscriptList
objects - Throws:
TranscriptRetrievalException
- If the retrieval of the transcript lists fails
-
getTranscriptsForPlaylist
Map<String,TranscriptContent> getTranscriptsForPlaylist(String playlistId, TranscriptRequest request, String... languageCodes) throws TranscriptRetrievalException Retrieves transcript content for all videos in the specified playlist.- Parameters:
playlistId
- The ID of the playlistrequest
-TranscriptRequest
request object containing API key, cookies file path, and stop on error flaglanguageCodes
- A varargs list of language codes in descending priority.For example:
If this is set to("de", "en")
, it will first attempt to fetch the German transcript ("de"), and then fetch the English transcript ("en") if the former fails. If no language code is provided, it uses English as the default language.- Returns:
- A map of video IDs to
TranscriptContent
objects - Throws:
TranscriptRetrievalException
- If the retrieval of the transcript fails
-
getTranscriptsForChannel
Map<String,TranscriptContent> getTranscriptsForChannel(String channelName, TranscriptRequest request, String... languageCodes) throws TranscriptRetrievalException Retrieves transcript content for all videos for the specified channel.- Parameters:
channelName
- The name of the channelrequest
-TranscriptRequest
request object containing API key, cookies file path, and stop on error flaglanguageCodes
- A varargs list of language codes in descending priority.For example:
If this is set to("de", "en")
, it will first attempt to fetch the German transcript ("de"), and then fetch the English transcript ("en") if the former fails. If no language code is provided, it uses English as the default language.- Returns:
- A map of video IDs to
TranscriptContent
objects - Throws:
TranscriptRetrievalException
- If the retrieval of the transcript fails
-