Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,22 +8,27 @@ import os
|
|
8 |
CLASSIFIER = "Jzuluaga/accent-id-commonaccent_xlsr-en-english"
|
9 |
|
10 |
def download_video(url):
|
11 |
-
"""Handles YouTube and direct video links"""
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
with
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
def extract_audio(video_path):
|
29 |
clip = VideoFileClip(video_path)
|
|
|
8 |
CLASSIFIER = "Jzuluaga/accent-id-commonaccent_xlsr-en-english"
|
9 |
|
10 |
def download_video(url):
|
11 |
+
"""Handles YouTube and direct video links with error handling"""
|
12 |
+
try:
|
13 |
+
if "youtube.com" in url or "youtu.be" in url:
|
14 |
+
yt = YouTube(url)
|
15 |
+
stream = yt.streams.filter(progressive=True, file_extension='mp4').first()
|
16 |
+
if not stream:
|
17 |
+
raise ValueError("No suitable video stream found.")
|
18 |
+
return stream.download()
|
19 |
+
else:
|
20 |
+
# For direct MP4 links, download file
|
21 |
+
import requests
|
22 |
+
local_filename = "temp_video.mp4"
|
23 |
+
with requests.get(url, stream=True) as r:
|
24 |
+
r.raise_for_status()
|
25 |
+
with open(local_filename, 'wb') as f:
|
26 |
+
for chunk in r.iter_content(chunk_size=8192):
|
27 |
+
f.write(chunk)
|
28 |
+
return local_filename
|
29 |
+
except Exception as e:
|
30 |
+
raise RuntimeError(f"Failed to download video: {e}")
|
31 |
+
|
32 |
|
33 |
def extract_audio(video_path):
|
34 |
clip = VideoFileClip(video_path)
|