Spaces:
Build error
Build error
Update download.py
Browse files- download.py +2 -27
download.py
CHANGED
@@ -10,7 +10,7 @@ from pathlib import Path
|
|
10 |
from typing import Optional, Callable, Dict, Any, Union
|
11 |
|
12 |
# Configuration
|
13 |
-
MAX_FILE_SIZE = 40 * 1024 * 1024 # 40 MB
|
14 |
FILE_TOO_LARGE_MESSAGE = "The audio file exceeds the 40MB size limit. Please try a shorter video clip or select a lower quality option."
|
15 |
MAX_RETRIES = 3
|
16 |
RETRY_DELAY = 2 # seconds
|
@@ -348,29 +348,4 @@ def get_video_info(url: str) -> Dict[str, Any]:
|
|
348 |
return info
|
349 |
except Exception as e:
|
350 |
logger.error(f"Error getting video info: {str(e)}")
|
351 |
-
raise DownloadError(f"Could not retrieve video information: {str(e)}")
|
352 |
-
|
353 |
-
|
354 |
-
# Example usage
|
355 |
-
if __name__ == "__main__":
|
356 |
-
# Example progress callback
|
357 |
-
def print_progress(msg):
|
358 |
-
print(msg)
|
359 |
-
|
360 |
-
try:
|
361 |
-
# Example: Download audio from a YouTube URL
|
362 |
-
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
|
363 |
-
audio_path = download_video_audio(
|
364 |
-
url,
|
365 |
-
output_dir="./downloads",
|
366 |
-
audio_format="mp3",
|
367 |
-
progress_callback=print_progress
|
368 |
-
)
|
369 |
-
|
370 |
-
print(f"Downloaded to: {audio_path}")
|
371 |
-
|
372 |
-
# Clean up
|
373 |
-
if audio_path:
|
374 |
-
delete_download(audio_path)
|
375 |
-
except DownloadError as e:
|
376 |
-
print(f"Download failed: {e}")
|
|
|
10 |
from typing import Optional, Callable, Dict, Any, Union
|
11 |
|
12 |
# Configuration
|
13 |
+
MAX_FILE_SIZE = 40 * 1024 * 1024 # 40 MB
|
14 |
FILE_TOO_LARGE_MESSAGE = "The audio file exceeds the 40MB size limit. Please try a shorter video clip or select a lower quality option."
|
15 |
MAX_RETRIES = 3
|
16 |
RETRY_DELAY = 2 # seconds
|
|
|
348 |
return info
|
349 |
except Exception as e:
|
350 |
logger.error(f"Error getting video info: {str(e)}")
|
351 |
+
raise DownloadError(f"Could not retrieve video information: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|