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 from YouTube.

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