Add provision for other languages in Youtube Video Block (#8630)

Co-authored-by: Toran Bruce Richards <toran.richards@gmail.com>
pull/8642/head^2
vishesh10 2024-11-14 14:50:46 +05:30 committed by GitHub
parent ce667f6287
commit 639242ac68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 1 deletions

View File

@ -62,7 +62,22 @@ class TranscribeYoutubeVideoBlock(Block):
@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)