Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -283,7 +283,7 @@ def download_youtube_video(url, project_path, proxy=None, proxy_user=None, proxy
|
|
| 283 |
|
| 284 |
# Základní konfigurace
|
| 285 |
ydl_opts = {
|
| 286 |
-
'format': '
|
| 287 |
'outtmpl': output_path,
|
| 288 |
'noplaylist': True,
|
| 289 |
'quiet': False,
|
|
@@ -293,8 +293,14 @@ def download_youtube_video(url, project_path, proxy=None, proxy_user=None, proxy
|
|
| 293 |
'merge_output_format': 'mp4', # Vynutí výstup v MP4
|
| 294 |
'postprocessors': [{
|
| 295 |
'key': 'FFmpegVideoConvertor',
|
| 296 |
-
'preferedformat': 'mp4',
|
| 297 |
}],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
}
|
| 299 |
|
| 300 |
# Přidáme cookies pokud existují
|
|
@@ -319,19 +325,31 @@ def download_youtube_video(url, project_path, proxy=None, proxy_user=None, proxy
|
|
| 319 |
try:
|
| 320 |
print("\nZahajuji stahování videa...")
|
| 321 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
ydl
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
print("✓ Video úspěšně staženo")
|
| 334 |
return output_path, thumbnail_url
|
|
|
|
| 335 |
except Exception as e:
|
| 336 |
error_str = str(e)
|
| 337 |
if "Sign in to confirm your age" in error_str or "Sign in to this account" in error_str or "Private video" in error_str:
|
|
|
|
| 283 |
|
| 284 |
# Základní konfigurace
|
| 285 |
ydl_opts = {
|
| 286 |
+
'format': 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b',
|
| 287 |
'outtmpl': output_path,
|
| 288 |
'noplaylist': True,
|
| 289 |
'quiet': False,
|
|
|
|
| 293 |
'merge_output_format': 'mp4', # Vynutí výstup v MP4
|
| 294 |
'postprocessors': [{
|
| 295 |
'key': 'FFmpegVideoConvertor',
|
| 296 |
+
'preferedformat': 'mp4',
|
| 297 |
}],
|
| 298 |
+
'http_headers': { # Add common headers
|
| 299 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36',
|
| 300 |
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
| 301 |
+
'Accept-Language': 'en-us,en;q=0.5',
|
| 302 |
+
'Sec-Fetch-Mode': 'navigate'
|
| 303 |
+
}
|
| 304 |
}
|
| 305 |
|
| 306 |
# Přidáme cookies pokud existují
|
|
|
|
| 325 |
try:
|
| 326 |
print("\nZahajuji stahování videa...")
|
| 327 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 328 |
+
try:
|
| 329 |
+
# First try with format selection
|
| 330 |
+
info = ydl.extract_info(url, download=False)
|
| 331 |
+
print("\nDostupné formáty:")
|
| 332 |
+
if hasattr(ydl, 'list_formats'):
|
| 333 |
+
ydl.list_formats(info)
|
| 334 |
+
|
| 335 |
+
thumbnail_url = info.get('thumbnail', '')
|
| 336 |
+
print("✓ Informace o videu úspěšně získány")
|
| 337 |
+
|
| 338 |
+
# Try downloading with current format
|
| 339 |
+
ydl.download([url])
|
| 340 |
+
except Exception as format_error:
|
| 341 |
+
if "Requested format is not available" in str(format_error):
|
| 342 |
+
print("⚠ Požadovaný formát není dostupný, zkouším alternativní formát...")
|
| 343 |
+
# Try with a more basic format
|
| 344 |
+
ydl_opts['format'] = 'best'
|
| 345 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl2:
|
| 346 |
+
ydl2.download([url])
|
| 347 |
+
else:
|
| 348 |
+
raise format_error
|
| 349 |
+
|
| 350 |
print("✓ Video úspěšně staženo")
|
| 351 |
return output_path, thumbnail_url
|
| 352 |
+
|
| 353 |
except Exception as e:
|
| 354 |
error_str = str(e)
|
| 355 |
if "Sign in to confirm your age" in error_str or "Sign in to this account" in error_str or "Private video" in error_str:
|