Youtube Loader load method Fixed (#30314)

- **Description:** Fixed the `YoutubeLoader` loading method not
returning the correct object
- **Issue:** #30309

---------

Co-authored-by: ccurme <chester.curme@gmail.com>
This commit is contained in:
Mohammad Mohtashim 2025-03-23 23:48:03 +05:00 committed by GitHub
parent df4448dfac
commit 33f1ab1528
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -241,6 +241,7 @@ class YoutubeLoader(BaseLoader):
"""Load YouTube transcripts into `Document` objects."""
try:
from youtube_transcript_api import (
FetchedTranscript,
NoTranscriptFound,
TranscriptsDisabled,
YouTubeTranscriptApi,
@ -269,8 +270,11 @@ class YoutubeLoader(BaseLoader):
if self.translation is not None:
transcript = transcript.translate(self.translation)
transcript_pieces: List[Dict[str, Any]] = transcript.fetch()
transcript_object = transcript.fetch()
if isinstance(transcript_object, FetchedTranscript):
transcript_pieces = [{"text": x.text} for x in transcript_object.snippets]
else:
transcript_pieces: List[Dict[str, Any]] = transcript_object # type: ignore[no-redef]
if self.transcript_format == TranscriptFormat.TEXT:
transcript = " ".join(