Update app.py
Browse files
app.py
CHANGED
@@ -42,27 +42,19 @@ multimodal_Agent = initialize_agent()
|
|
42 |
import tempfile
|
43 |
from yt_dlp import YoutubeDL
|
44 |
|
|
|
|
|
|
|
45 |
def download_youtube_video(youtube_url):
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
Parameters:
|
50 |
-
- youtube_url: The URL of the YouTube video.
|
51 |
-
|
52 |
-
Returns:
|
53 |
-
- The path to the downloaded video file.
|
54 |
-
"""
|
55 |
-
# Temporary file for the video
|
56 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
|
57 |
-
temp_video_path = temp_video.name
|
58 |
|
59 |
# yt-dlp options
|
60 |
ydl_opts = {
|
61 |
'format': 'bestvideo+bestaudio/best', # Download best video and audio
|
62 |
-
'outtmpl':
|
63 |
-
'
|
64 |
-
'
|
65 |
-
'quiet': True, # Suppress yt-dlp output
|
66 |
}
|
67 |
|
68 |
try:
|
@@ -70,10 +62,11 @@ def download_youtube_video(youtube_url):
|
|
70 |
with YoutubeDL(ydl_opts) as ydl:
|
71 |
ydl.download([youtube_url])
|
72 |
|
73 |
-
|
74 |
|
75 |
except Exception as e:
|
76 |
-
|
|
|
77 |
|
78 |
|
79 |
# YouTube video URL input
|
|
|
42 |
import tempfile
|
43 |
from yt_dlp import YoutubeDL
|
44 |
|
45 |
+
import browser_cookie3
|
46 |
+
from yt_dlp import YoutubeDL
|
47 |
+
|
48 |
def download_youtube_video(youtube_url):
|
49 |
+
# Extract cookies from browser (Chrome, Firefox, etc.)
|
50 |
+
cookies = browser_cookie3.load()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
# yt-dlp options
|
53 |
ydl_opts = {
|
54 |
'format': 'bestvideo+bestaudio/best', # Download best video and audio
|
55 |
+
'outtmpl': 'downloaded_video.mp4', # Output file path
|
56 |
+
'cookies': cookies, # Use cookies directly from browser
|
57 |
+
'quiet': True, # Suppress yt-dlp output
|
|
|
58 |
}
|
59 |
|
60 |
try:
|
|
|
62 |
with YoutubeDL(ydl_opts) as ydl:
|
63 |
ydl.download([youtube_url])
|
64 |
|
65 |
+
print("Download successful!")
|
66 |
|
67 |
except Exception as e:
|
68 |
+
print(f"An error occurred: {str(e)}")
|
69 |
+
|
70 |
|
71 |
|
72 |
# YouTube video URL input
|