GoodML commited on
Commit
7844e16
·
verified ·
1 Parent(s): 58418df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -96,25 +96,26 @@ def process_youtube():
96
  return jsonify({"error": "No YouTube URL provided"}), 400
97
 
98
  try:
99
- # Extract the YouTube video ID from the URL
100
- video_id = youtube_url.split("=")[1]
101
- transcript = ""
102
- try:
103
- # Fetch the transcript for the video using YouTubeTranscriptApi
104
- transcript_data = YouTubeTranscriptApi.get_transcript(video_id)
105
-
106
- # Concatenate the text from each segment into a single transcript
107
- transcript = " ".join([segment['text'] for segment in transcript_data])
108
-
109
-
110
- except Exception as e:
111
- print(f"Error fetching transcript for video ID {video_id}: {e}")
112
 
113
- if not transcript:
114
- return jsonify({"error": f"Unable to fetch transcript from YouTube: {transcript}"}), 500
 
 
 
 
 
 
115
 
116
  # Send the transcript to the Gemini API for structured data
117
  structured_data = query_gemini_api(transcript)
 
118
 
119
  # Return the structured data
120
  return jsonify(structured_data)
 
96
  return jsonify({"error": "No YouTube URL provided"}), 400
97
 
98
  try:
99
+
100
+ """
101
+ Fetches the transcript of a YouTube video using the YouTube Transcript API.
102
+ """
103
+
104
+ # Extract the video ID from the YouTube URL
105
+ video_id = youtube_url.split("v=")[-1].split("&")[0]
 
 
 
 
 
 
106
 
107
+ # Fetch the transcript for the given video ID
108
+ transcript_data = YouTubeTranscriptApi.get_transcript(video_id)
109
+
110
+ # Print transcript to console
111
+ print(f"Transcript for video ID {video_id}:")
112
+ transcript = " ".join([segment['text'] for segment in transcript_data])
113
+
114
+
115
 
116
  # Send the transcript to the Gemini API for structured data
117
  structured_data = query_gemini_api(transcript)
118
+
119
 
120
  # Return the structured data
121
  return jsonify(structured_data)