Interface YoutubeTranscriptApi
It provides functionality for retrieving all available transcripts or retrieving actual transcript content from YouTube.
To instantiate this API, you should use TranscriptApiFactory
.
-
Method Summary
Modifier and TypeMethodDescriptiongetTranscript
(String videoId, String... languageCodes) Retrieves transcript content for a single video.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.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
-