Interface YoutubeTranscriptApi


public interface 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 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 video
      cookiesPath - 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 fails
      IllegalArgumentException - If the video ID is invalid
    • listTranscripts

      TranscriptList listTranscripts(String videoId) throws TranscriptRetrievalException
      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 fails
      IllegalArgumentException - 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 video
      cookiesPath - The file path to the text file containing the authentication cookies
      languageCodes - 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 fails
      IllegalArgumentException - 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 video
      languageCodes - 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 fails
      IllegalArgumentException - 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 playlist
      request - 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 channel
      request - 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 playlist
      request - TranscriptRequest request object containing API key, cookies file path, and stop on error flag
      languageCodes - 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 channel
      request - TranscriptRequest request object containing API key, cookies file path, and stop on error flag
      languageCodes - 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