Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,6 +27,8 @@ import os
|
|
| 27 |
|
| 28 |
import yt_dlp
|
| 29 |
|
|
|
|
|
|
|
| 30 |
def download_video(url):
|
| 31 |
"""
|
| 32 |
Downloads a video from a URL using yt-dlp.
|
|
@@ -36,14 +38,20 @@ def download_video(url):
|
|
| 36 |
The path to the downloaded file, or None if an error occurred.
|
| 37 |
"""
|
| 38 |
print("Downloading...")
|
|
|
|
| 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':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
|
| 49 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
@@ -55,10 +63,13 @@ def download_video(url):
|
|
| 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 |
"""
|
| 64 |
Validates a YouTube URL, checks if the video exists, and returns whether its length exceeds 10 minutes.
|
|
|
|
| 27 |
|
| 28 |
import yt_dlp
|
| 29 |
|
| 30 |
+
import yt_dlp
|
| 31 |
+
|
| 32 |
def download_video(url):
|
| 33 |
"""
|
| 34 |
Downloads a video from a URL using yt-dlp.
|
|
|
|
| 38 |
The path to the downloaded file, or None if an error occurred.
|
| 39 |
"""
|
| 40 |
print("Downloading...")
|
| 41 |
+
|
| 42 |
try:
|
| 43 |
ydl_opts = {
|
| 44 |
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', # Prioritize mp4
|
| 45 |
'merge_output_format': 'mp4', # Ensure final output is mp4
|
| 46 |
'outtmpl': '%(title)s.%(ext)s', # Use title for filename
|
|
|
|
| 47 |
'noprogress': True, # Remove progress bar output
|
| 48 |
+
'quiet': False, # Show some logs for debugging
|
| 49 |
+
|
| 50 |
+
# Use cookies for authentication
|
| 51 |
+
'cookies': 'cookies.txt', # Path to exported cookies file
|
| 52 |
+
# OR Use cookies from browser (uncomment one of these based on your browser)
|
| 53 |
+
# 'cookies-from-browser': 'chrome', # Chrome
|
| 54 |
+
# 'cookies-from-browser': 'firefox', # Firefox
|
| 55 |
}
|
| 56 |
|
| 57 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
|
|
| 63 |
print(f"Download error: {e}")
|
| 64 |
except Exception as e:
|
| 65 |
print(f"Unexpected error: {e}")
|
| 66 |
+
|
| 67 |
return None
|
| 68 |
|
| 69 |
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
def validate_youtube(url):
|
| 74 |
"""
|
| 75 |
Validates a YouTube URL, checks if the video exists, and returns whether its length exceeds 10 minutes.
|