Update app.py
Browse files
app.py
CHANGED
@@ -25,33 +25,31 @@ from yt_dlp import YoutubeDL
|
|
25 |
from yt_dlp import YoutubeDL
|
26 |
import os
|
27 |
|
28 |
-
import yt_dlp
|
29 |
-
import time
|
30 |
-
import random
|
31 |
-
|
32 |
import yt_dlp
|
33 |
|
34 |
def download_video(url):
|
35 |
"""
|
36 |
-
Downloads a video from YouTube using yt-dlp.
|
37 |
"""
|
38 |
-
print("
|
39 |
|
40 |
ydl_opts = {
|
41 |
'format': 'bestvideo+bestaudio/best', # Ensures best quality
|
42 |
-
'
|
43 |
-
'
|
44 |
-
'quiet': False, # Shows
|
|
|
|
|
45 |
}
|
46 |
|
47 |
try:
|
48 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
49 |
info = ydl.extract_info(url, download=True)
|
50 |
-
local_file = ydl.prepare_filename(info) #
|
51 |
-
print(f"Downloaded: {local_file}")
|
52 |
return local_file
|
53 |
except Exception as e:
|
54 |
-
print(f"Download failed: {str(e)}")
|
55 |
return None
|
56 |
|
57 |
# Example Usage
|
|
|
25 |
from yt_dlp import YoutubeDL
|
26 |
import os
|
27 |
|
|
|
|
|
|
|
|
|
28 |
import yt_dlp
|
29 |
|
30 |
def download_video(url):
|
31 |
"""
|
32 |
+
Downloads a video from YouTube using yt-dlp with browser authentication.
|
33 |
"""
|
34 |
+
print("Starting download...")
|
35 |
|
36 |
ydl_opts = {
|
37 |
'format': 'bestvideo+bestaudio/best', # Ensures best quality
|
38 |
+
'merge_output_format': 'mp4', # Ensures final output is MP4
|
39 |
+
'outtmpl': '%(title)s.%(ext)s', # Saves file with video title
|
40 |
+
'quiet': False, # Shows progress
|
41 |
+
'cookies': 'youtube_cookies.txt', # Use exported cookies
|
42 |
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36', # Mimic browser
|
43 |
}
|
44 |
|
45 |
try:
|
46 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
47 |
info = ydl.extract_info(url, download=True)
|
48 |
+
local_file = ydl.prepare_filename(info) # Get output filename
|
49 |
+
print(f"✅ Downloaded: {local_file}")
|
50 |
return local_file
|
51 |
except Exception as e:
|
52 |
+
print(f"❌ Download failed: {str(e)}")
|
53 |
return None
|
54 |
|
55 |
# Example Usage
|