Toggle Menu
Prev Up Next

# `langchain_community.document_loaders.youtube`.YoutubeLoader

class langchain_community.document_loaders.youtube.YoutubeLoader(video_id: str, add_video_info: bool = False, language: Union[str, Sequence[str]] = 'en', translation: Optional[str] = None, transcript_format: TranscriptFormat = TranscriptFormat.TEXT, continue_on_failure: bool = False)

  Load YouTube transcripts.

  Initialize with YouTube video ID.

  Methods

  `__init__`(video_id[, add_video_info, ...]) | Initialize with YouTube video ID.
  `alazy_load`() | A lazy loader for Documents.
  `aload`() | Load data into Document objects.
  `extract_video_id`(youtube_url) | Extract video id from common YT urls.
  `from_youtube_url`(youtube_url, **kwargs) | Given youtube URL, load video.
  `lazy_load`() | A lazy loader for Documents.
  `load`() | Load documents.
  `load_and_split`([text_splitter]) | Load Documents and split into chunks.

  Parameters

    - video_id (str) –

    - add_video_info (bool) –

    - language (Union[str, Sequence[str]]) –

    - translation (Optional[str]) –

    - transcript_format (TranscriptFormat) –

    - continue_on_failure (bool) –

  __init__(video_id: str, add_video_info: bool = False, language: Union[str, Sequence[str]] = 'en', translation: Optional[str] = None, transcript_format: TranscriptFormat = TranscriptFormat.TEXT, continue_on_failure: bool = False)

    Initialize with YouTube video ID.

    Parameters

      - video_id (str) –

      - add_video_info (bool) –

      - language (Union[str, Sequence[str]]) –

      - translation (Optional[str]) –

      - transcript_format (TranscriptFormat) –

      - continue_on_failure (bool) –

  async alazy_load() → AsyncIterator[Document]

    A lazy loader for Documents.

    Return type

      AsyncIterator[Document]

  async aload() → List[Document]

    Load data into Document objects.

    Return type

      List[Document]

  static extract_video_id(youtube_url: str) → str

    Extract video id from common YT urls.

    Parameters

      youtube_url (str) –

    Return type

      str

  classmethod from_youtube_url(youtube_url: str, **kwargs: Any) → YoutubeLoader

    Given youtube URL, load video.

    Parameters

      - youtube_url (str) –

      - kwargs (Any) –

    Return type

      YoutubeLoader

  lazy_load() → Iterator[Document]

    A lazy loader for Documents.

    Return type

      Iterator[Document]

  load() → List[Document]

    Load documents.

    Return type

      List[Document]

  load_and_split(text_splitter: Optional[TextSplitter] = None) → List[Document]

    Load Documents and split into chunks. Chunks are returned as Documents.

    Do not override this method. It should be considered to be deprecated!

    Parameters

      text_splitter (Optional[TextSplitter]) – TextSplitter instance to use for splitting documents. Defaults to RecursiveCharacterTextSplitter.

    Returns

      List of Documents.

    Return type

      List[Document]

# Examples using YoutubeLoader

- %pip install -qU langchain langchain-community langchain-openai youtube-transcript-api pytube langchain-chroma

- %pip install -qU langchain langchain-openai youtube-transcript-api pytube

- Google

- Init the GoogleApiClient

- YouTube