Package io.github.thoroldvix.api
Class YoutubeTranscriptApi
java.lang.Object
io.github.thoroldvix.api.YoutubeTranscriptApi
This is the main interface for the YouTube Transcript API.
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, BulkTranscriptRequest request, String... languageCodes) Retrieves transcript content for all videos for the specified channel.getTranscriptsForPlaylist
(String playlistId, BulkTranscriptRequest request, String... languageCodes) Retrieves transcript content for all videos in the specified playlist.listTranscripts
(String videoId) Retrieves a list of available transcripts for a given video.listTranscriptsForChannel
(String channelName, BulkTranscriptRequest request) Retrieves transcript lists for all videos for the specified channel.listTranscriptsForPlaylist
(String playlistId, BulkTranscriptRequest request) Retrieves transcript lists for all videos in the specified playlist.
-
Method Details
-
getTranscript
public 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
-
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
-
listTranscriptsForPlaylist
public Map<String,TranscriptList> listTranscriptsForPlaylist(String playlistId, BulkTranscriptRequest request) throws TranscriptRetrievalException Retrieves transcript lists for all videos in the specified playlist.- Parameters:
playlistId
- The ID of the playlistrequest
-BulkTranscriptRequest
request object containing API key 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
public Map<String,TranscriptContent> getTranscriptsForPlaylist(String playlistId, BulkTranscriptRequest request, String... languageCodes) throws TranscriptRetrievalException Retrieves transcript content for all videos in the specified playlist.- Parameters:
playlistId
- The ID of the playlistrequest
-BulkTranscriptRequest
request object containing API key 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
-
listTranscriptsForChannel
public Map<String,TranscriptList> listTranscriptsForChannel(String channelName, BulkTranscriptRequest request) throws TranscriptRetrievalException Retrieves transcript lists for all videos for the specified channel.- Parameters:
channelName
- The name of the channelrequest
-BulkTranscriptRequest
request object containing API key and stop on error flag- Returns:
- A map of video IDs to
TranscriptList
objects - Throws:
TranscriptRetrievalException
- If the retrieval of the transcript lists fails
-
getTranscriptsForChannel
public Map<String,TranscriptContent> getTranscriptsForChannel(String channelName, BulkTranscriptRequest request, String... languageCodes) throws TranscriptRetrievalException Retrieves transcript content for all videos for the specified channel.- Parameters:
channelName
- The name of the channelrequest
-BulkTranscriptRequest
request object containing API key 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
-