Update app.py
Browse files
app.py
CHANGED
|
@@ -15,9 +15,14 @@ def get_youtube_captions(youtube_url):
|
|
| 15 |
"""
|
| 16 |
# Extract video ID from YouTube URL (for both regular videos and Shorts)
|
| 17 |
if "shorts" in youtube_url:
|
|
|
|
| 18 |
video_id = youtube_url.split("shorts/")[-1].split("?")[0]
|
| 19 |
else:
|
|
|
|
| 20 |
video_id = youtube_url.split("v=")[-1].split("&")[0]
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
try:
|
| 23 |
# Fetch transcript for the video
|
|
@@ -39,10 +44,13 @@ youtube_url = st.text_input(
|
|
| 39 |
)
|
| 40 |
|
| 41 |
if youtube_url:
|
|
|
|
|
|
|
|
|
|
| 42 |
try:
|
| 43 |
with st.spinner("Fetching and processing the YouTube video..."):
|
| 44 |
# Get captions using youtube-transcript-api
|
| 45 |
-
captions = get_youtube_captions(
|
| 46 |
|
| 47 |
# Check if captions are available
|
| 48 |
if "Error" not in captions:
|
|
|
|
| 15 |
"""
|
| 16 |
# Extract video ID from YouTube URL (for both regular videos and Shorts)
|
| 17 |
if "shorts" in youtube_url:
|
| 18 |
+
# For YouTube Shorts, extract the video ID after "shorts/"
|
| 19 |
video_id = youtube_url.split("shorts/")[-1].split("?")[0]
|
| 20 |
else:
|
| 21 |
+
# For regular YouTube videos, extract the video ID after "v="
|
| 22 |
video_id = youtube_url.split("v=")[-1].split("&")[0]
|
| 23 |
+
|
| 24 |
+
# Print extracted video ID for debugging
|
| 25 |
+
print(f"Extracted Video ID: {video_id}")
|
| 26 |
|
| 27 |
try:
|
| 28 |
# Fetch transcript for the video
|
|
|
|
| 44 |
)
|
| 45 |
|
| 46 |
if youtube_url:
|
| 47 |
+
# Clean URL before passing to the function (remove extra parts)
|
| 48 |
+
youtube_url_cleaned = youtube_url.split("?")[0] # Remove URL parameters
|
| 49 |
+
|
| 50 |
try:
|
| 51 |
with st.spinner("Fetching and processing the YouTube video..."):
|
| 52 |
# Get captions using youtube-transcript-api
|
| 53 |
+
captions = get_youtube_captions(youtube_url_cleaned)
|
| 54 |
|
| 55 |
# Check if captions are available
|
| 56 |
if "Error" not in captions:
|