Spaces:
Runtime error
Runtime error
Update Download_Video.py
Browse files- Download_Video.py +18 -6
Download_Video.py
CHANGED
@@ -1,8 +1,20 @@
|
|
1 |
-
import
|
|
|
2 |
|
3 |
-
def download_video(url):
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
|
|
1 |
+
from yt_dlp import YoutubeDL
|
2 |
+
import os
|
3 |
|
4 |
+
def download_video(url, download_dir=None):
|
5 |
+
try:
|
6 |
+
# Set download options
|
7 |
+
ydl_opts = {
|
8 |
+
'format': 'best', # Download the best quality available
|
9 |
+
'outtmpl': os.path.join(download_dir, '%(title)s.%(ext)s') if download_dir else '%(title)s.%(ext)s', # Save file with title as name
|
10 |
+
'quiet': True, # Suppress output (set to False for debugging)
|
11 |
+
}
|
12 |
+
|
13 |
+
with YoutubeDL(ydl_opts) as ydl:
|
14 |
+
info_dict = ydl.extract_info(url, download=True) # Extract video info and download
|
15 |
+
video_path = ydl.prepare_filename(info_dict) # Get the path of the downloaded file
|
16 |
+
return video_path
|
17 |
+
|
18 |
+
except Exception as e:
|
19 |
+
return f"An error occurred: {e}"
|
20 |
|