Spaces:
Runtime error
Runtime error
Commit ·
dc02be2
1
Parent(s): 09547ec
done
Browse files123452 unmodified lines8910111213141516171819202122232425262728import gradio as grfrom pytube import YouTubedef get_youtube_details(link):try:2 unmodified lines# Get the thumbnail URLthumbnail_url = yt.thumbnail_url# Attempt to fetch the transcripttranscript_text = "No transcript available."try:# Try to get the English captionscaption = yt.captions.get_by_language_code('en')if not caption:# Try English auto-generated captionscaption = yt.captions.get_by_language_code('a.en')if caption:# Get the caption in SRT formattranscript_text = caption.generate_srt_captions()else:transcript_text = "Transcript not available in English."except Exception as e:transcript_text = f"Error retrieving transcript: {str(e)}"return transcript_text, thumbnail_urlexcept Exception as e:1234562 unmodified lines91011121314151617181920212223242526272829303132333435363738import gradio as grfrom pytube import YouTubefrom youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFounddef get_youtube_details(link):try:2 unmodified lines# Get the thumbnail URLthumbnail_url = yt.thumbnail_url# Use pytube to get the video IDvideo_id = yt.video_idprint(f"Video ID: {video_id}") # Debugging# Attempt to fetch the transcripttranscript_text = "No transcript available."try:# List available transcriptstranscript_list = YouTubeTranscriptApi.list_transcripts(video_id)print("Available transcripts:")for transcript in transcript_list:print(f"Language Code: {transcript.language_code}, Language: {transcript.language}")# Try fetching the transcript for various English language codestranscript = transcript_list.find_transcript(['en', 'en-US', 'en-GB', 'en-AU'])print(f"Selected transcript language: {transcript.language_code}")# Fetch the transcript and join the text piecestranscript_data = transcript.fetch()transcript_text = "\n".join([item['text'] for item in transcript_data])except (TranscriptsDisabled, NoTranscriptFound) as e:transcript_text = f"Transcript not available: {str(e)}"except Exception as e:transcript_text = f"An error occurred while fetching the transcript: {str(e)}"return transcript_text, thumbnail_urlexcept Exception as e:
app.py+21-11