diff --git a/autogpt_platform/backend/backend/blocks/youtube.py b/autogpt_platform/backend/backend/blocks/youtube.py index b4f0259d98b1..648d9d6dae07 100644 --- a/autogpt_platform/backend/backend/blocks/youtube.py +++ b/autogpt_platform/backend/backend/blocks/youtube.py @@ -62,7 +62,22 @@ def extract_video_id(url: str) -> str: @staticmethod def get_transcript(video_id: str): - return YouTubeTranscriptApi.get_transcript(video_id) + try: + transcript_list = YouTubeTranscriptApi.list_transcripts(video_id) + + if not transcript_list: + raise ValueError(f"No transcripts found for the video: {video_id}") + + for transcript in transcript_list: + first_transcript = transcript_list.find_transcript( + [transcript.language_code] + ) + return YouTubeTranscriptApi.get_transcript( + video_id, languages=[first_transcript.language_code] + ) + + except Exception: + raise ValueError(f"No transcripts found for the video: {video_id}") def run(self, input_data: Input, **kwargs) -> BlockOutput: video_id = self.extract_video_id(input_data.youtube_url)