Update app.py
Browse files
app.py
CHANGED
|
@@ -25,13 +25,13 @@ from yt_dlp import YoutubeDL
|
|
| 25 |
from yt_dlp import YoutubeDL
|
| 26 |
import os
|
| 27 |
|
|
|
|
|
|
|
| 28 |
def download_video(url):
|
| 29 |
"""
|
| 30 |
Downloads a video from a URL using yt-dlp.
|
| 31 |
-
|
| 32 |
Args:
|
| 33 |
url: The URL of the video to download.
|
| 34 |
-
|
| 35 |
Returns:
|
| 36 |
The path to the downloaded file, or None if an error occurred.
|
| 37 |
"""
|
|
@@ -39,17 +39,25 @@ def download_video(url):
|
|
| 39 |
try:
|
| 40 |
ydl_opts = {
|
| 41 |
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', # Prioritize mp4
|
| 42 |
-
'merge_output_format': 'mp4',
|
| 43 |
'outtmpl': '%(title)s.%(ext)s', # Use title for filename
|
|
|
|
|
|
|
|
|
|
| 44 |
}
|
| 45 |
-
|
|
|
|
| 46 |
info_dict = ydl.extract_info(url, download=True)
|
| 47 |
-
filename = ydl.prepare_filename(info_dict)
|
| 48 |
-
print("Downloaded")
|
| 49 |
return filename
|
|
|
|
|
|
|
| 50 |
except Exception as e:
|
| 51 |
-
print(f"
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
|
| 54 |
def validate_youtube(url):
|
| 55 |
"""
|
|
|
|
| 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 a URL using yt-dlp.
|
|
|
|
| 33 |
Args:
|
| 34 |
url: The URL of the video to download.
|
|
|
|
| 35 |
Returns:
|
| 36 |
The path to the downloaded file, or None if an error occurred.
|
| 37 |
"""
|
|
|
|
| 39 |
try:
|
| 40 |
ydl_opts = {
|
| 41 |
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', # Prioritize mp4
|
| 42 |
+
'merge_output_format': 'mp4', # Ensure final output is mp4
|
| 43 |
'outtmpl': '%(title)s.%(ext)s', # Use title for filename
|
| 44 |
+
'cookies-from-browser': 'chrome', # Use cookies from Chrome (Change to your browser)
|
| 45 |
+
'noprogress': True, # Remove progress bar output
|
| 46 |
+
'quiet': True, # Run in quiet mode
|
| 47 |
}
|
| 48 |
+
|
| 49 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 50 |
info_dict = ydl.extract_info(url, download=True)
|
| 51 |
+
filename = ydl.prepare_filename(info_dict) # Get the actual filename
|
| 52 |
+
print("Downloaded:", filename)
|
| 53 |
return filename
|
| 54 |
+
except yt_dlp.utils.DownloadError as e:
|
| 55 |
+
print(f"Download error: {e}")
|
| 56 |
except Exception as e:
|
| 57 |
+
print(f"Unexpected error: {e}")
|
| 58 |
+
|
| 59 |
+
return None
|
| 60 |
+
|
| 61 |
|
| 62 |
def validate_youtube(url):
|
| 63 |
"""
|