krunaldave commited on
Commit
703c66d
·
verified ·
1 Parent(s): 6023620

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -15,17 +15,13 @@ def summarize_youtube_video(video_url: str) -> str:
15
  """
16
  try:
17
  from youtube_transcript_api import YouTubeTranscriptApi
18
-
19
- # Extract video ID
20
  match = re.search(r"(?:v=|youtu\.be/)([a-zA-Z0-9_-]{11})", video_url)
21
  if not match:
22
  return "Could not extract a valid video ID from the URL."
23
-
24
  video_id = match.group(1)
25
- transcript = YouTubeTranscriptApi.get_transcript(video_id)
26
- full_text = " ".join([entry['text'] for entry in transcript])
27
-
28
- # Truncate to avoid token limits
29
  return f"Transcript: {full_text[:4000]}"
30
  except Exception as e:
31
  return f"Error fetching transcript: {str(e)}"
 
15
  """
16
  try:
17
  from youtube_transcript_api import YouTubeTranscriptApi
 
 
18
  match = re.search(r"(?:v=|youtu\.be/)([a-zA-Z0-9_-]{11})", video_url)
19
  if not match:
20
  return "Could not extract a valid video ID from the URL."
 
21
  video_id = match.group(1)
22
+ ytt_api = YouTubeTranscriptApi() # ← instantiate now
23
+ transcript = ytt_api.fetch(video_id) # ← .fetch() not .get_transcript()
24
+ full_text = " ".join([entry.text for entry in transcript]) # ← .text not ['text']
 
25
  return f"Transcript: {full_text[:4000]}"
26
  except Exception as e:
27
  return f"Error fetching transcript: {str(e)}"