Upload app.py
Browse files
app.py
CHANGED
@@ -69,8 +69,9 @@ Focus on the main points and key insights. Write in a professional tone.
|
|
69 |
prompt = PromptTemplate(template=prompt_template, input_variables=["text"])
|
70 |
|
71 |
def get_youtube_content(url):
|
72 |
-
"""Get content from YouTube video
|
73 |
try:
|
|
|
74 |
from youtube_transcript_api import YouTubeTranscriptApi
|
75 |
from urllib.parse import urlparse, parse_qs
|
76 |
|
@@ -82,11 +83,26 @@ def get_youtube_content(url):
|
|
82 |
else:
|
83 |
raise ValueError("Not a valid YouTube URL")
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
response = requests.get(f"https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v={video_id}&format=json")
|
91 |
if response.status_code == 200:
|
92 |
video_info = response.json()
|
|
|
69 |
prompt = PromptTemplate(template=prompt_template, input_variables=["text"])
|
70 |
|
71 |
def get_youtube_content(url):
|
72 |
+
"""Get content from YouTube video"""
|
73 |
try:
|
74 |
+
# First try youtube-transcript-api
|
75 |
from youtube_transcript_api import YouTubeTranscriptApi
|
76 |
from urllib.parse import urlparse, parse_qs
|
77 |
|
|
|
83 |
else:
|
84 |
raise ValueError("Not a valid YouTube URL")
|
85 |
|
86 |
+
try:
|
87 |
+
# Try getting transcript
|
88 |
+
transcript_list = YouTubeTranscriptApi.get_transcript(video_id)
|
89 |
+
transcript_text = ' '.join([entry['text'] for entry in transcript_list])
|
90 |
+
except:
|
91 |
+
# Fallback to yt-dlp for description if transcript fails
|
92 |
+
ydl_opts = {
|
93 |
+
'quiet': True,
|
94 |
+
'no_warnings': True,
|
95 |
+
'extract_flat': True,
|
96 |
+
}
|
97 |
+
|
98 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
99 |
+
try:
|
100 |
+
video_info = ydl.extract_info(url, download=False)
|
101 |
+
transcript_text = video_info.get('description', 'No description available')
|
102 |
+
except:
|
103 |
+
transcript_text = "Could not extract video content."
|
104 |
+
|
105 |
+
# Get video info
|
106 |
response = requests.get(f"https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v={video_id}&format=json")
|
107 |
if response.status_code == 200:
|
108 |
video_info = response.json()
|