mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-23 19:39:58 +00:00
fix: Make YoutubeLoader support on demand language translation (#13583)
**Description:** Enhance the functionality of YoutubeLoader to enable the translation of available transcripts by refining the existing logic. **Issue:** Encountering a problem with YoutubeLoader (#13523) where the translation feature is not functioning as expected. Tag maintainers/contributors who might be interested: @eyurtsev --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
@@ -146,7 +146,7 @@ class YoutubeLoader(BaseLoader):
|
||||
video_id: str,
|
||||
add_video_info: bool = False,
|
||||
language: Union[str, Sequence[str]] = "en",
|
||||
translation: str = "en",
|
||||
translation: Optional[str] = None,
|
||||
continue_on_failure: bool = False,
|
||||
):
|
||||
"""Initialize with YouTube video ID."""
|
||||
@@ -206,8 +206,10 @@ class YoutubeLoader(BaseLoader):
|
||||
try:
|
||||
transcript = transcript_list.find_transcript(self.language)
|
||||
except NoTranscriptFound:
|
||||
en_transcript = transcript_list.find_transcript(["en"])
|
||||
transcript = en_transcript.translate(self.translation)
|
||||
transcript = transcript_list.find_transcript(["en"])
|
||||
|
||||
if self.translation is not None:
|
||||
transcript = transcript.translate(self.translation)
|
||||
|
||||
transcript_pieces = transcript.fetch()
|
||||
|
||||
|
Reference in New Issue
Block a user