feat: add error handling to downloader

Added DownloadError exception class that is raised when yt-dlp fails.
The download_space function now wraps yt-dlp calls in a try-except block
to catch any exceptions and raise a custom DownloadError with a clear message.

Test added to verify that DownloadError is raised when yt-dlp fails.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
synapz-organdClaude committed 2025-10-26 09:45:09 -04:00
1 parent 73775c122b
commit 5eec3129bc
2 files changed
+33 -3

No files matched your search

+13 -2
View File
@@ -4,6 +4,11 @@ from typing import Optional
from src.validator import validate_space_url
class DownloadError(Exception):
"""Raised when download fails."""
pass
def download_space(
space_url: str,
output_dir: str,
@@ -19,6 +24,9 @@ def download_space(
Returns:
Path to the downloaded MP3 file
Raises:
DownloadError: If download fails
"""
# Extract space ID from URL using validator for robustness
is_valid, space_id, error_message = validate_space_url(space_url)
@@ -45,8 +53,11 @@ def download_space(
ydl_opts['cookiefile'] = cookies_file
# Download with yt-dlp
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.extract_info(space_url, download=True)
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.extract_info(space_url, download=True)
except Exception as e:
raise DownloadError(f"Failed to download Space: {str(e)}")
# Return the expected output path
return os.path.join(output_dir, f'space_{space_id}.mp3')