Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1330,15 +1330,31 @@ def download_video(video_url, download_path, info_dict, download_video_flag):
|
|
| 1330 |
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]',
|
| 1331 |
'outtmpl': video_file_path,
|
| 1332 |
'ffmpeg_location': ffmpeg_path
|
|
|
|
| 1333 |
}
|
| 1334 |
|
| 1335 |
-
|
| 1336 |
-
|
| 1337 |
-
|
| 1338 |
-
|
| 1339 |
-
|
| 1340 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1341 |
else:
|
|
|
|
| 1342 |
return None
|
| 1343 |
|
| 1344 |
|
|
|
|
| 1330 |
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]',
|
| 1331 |
'outtmpl': video_file_path,
|
| 1332 |
'ffmpeg_location': ffmpeg_path
|
| 1333 |
+
'merge_output_format': 'mp4',
|
| 1334 |
}
|
| 1335 |
|
| 1336 |
+
retry_attempts = 3
|
| 1337 |
+
for attempt in range(retry_attempts):
|
| 1338 |
+
try:
|
| 1339 |
+
with yt_dlp.YoutubeDL(ydl_opts_video) as ydl:
|
| 1340 |
+
logging.debug("yt_dlp: About to download video with youtube-dl")
|
| 1341 |
+
ydl.download([video_url])
|
| 1342 |
+
logging.debug("yt_dlp: Video successfully downloaded with youtube-dl")
|
| 1343 |
+
if os.path.exists(video_file_path):
|
| 1344 |
+
return video_file_path
|
| 1345 |
+
else:
|
| 1346 |
+
logging.error("yt_dlp: Video file not found after download")
|
| 1347 |
+
return None
|
| 1348 |
+
except Exception as e:
|
| 1349 |
+
logging.error(f"yt_dlp: Error downloading video: {e}")
|
| 1350 |
+
if attempt < retry_attempts - 1:
|
| 1351 |
+
logging.info(f"Retrying download... (Attempt {attempt + 1}/{retry_attempts})")
|
| 1352 |
+
time.sleep(2) # Wait a bit before retrying
|
| 1353 |
+
else:
|
| 1354 |
+
logging.error("yt_dlp: Failed to download video after multiple attempts")
|
| 1355 |
+
return None
|
| 1356 |
else:
|
| 1357 |
+
logging.debug("Download video flag is set to False")
|
| 1358 |
return None
|
| 1359 |
|
| 1360 |
|