Files
Downloader-Bot/services/exceptions.py
Mak5er 635e50b407 feat(settings): add media quality & file options, ZIP multi-photo archives, and categorized /settings UI
- Add video_quality, as_document, audio_format, and file_button to user settings schema and Alembic migrations.
- Categorize /settings into Media & Quality, Appearance & Buttons, and Chat & Clean-up with dynamic back navigation.
- Implement strict document delivery with disable_content_type_detection=True to prevent Telegram video player fallback when as_document is ON.
- Add multi-photo ZIP archive packaging for photo carousels in as_document mode.
- Differentiate DB media file cache entries between video and document types (url#document vs url#video) to eliminate cache collisions.
- Hide redundant Download File inline button when as_document setting is active.
- Remove obsolete referral system (/ref command and links).
2026-07-22 13:18:09 +03:00

62 lines
2.1 KiB
Python

from typing import Optional
class DownloaderBaseException(Exception):
"""Base exception class for all Downloader-Bot domain errors."""
user_message: str = "An error occurred while processing your request."
def __init__(self, message: str | None = None, user_message: str | None = None):
super().__init__(message or user_message or self.user_message)
if user_message:
self.user_message = user_message
class PlatformExtractError(DownloaderBaseException):
"""Raised when metadata or media extraction fails for a platform."""
def __init__(self, platform: str, reason: Optional[str] = None):
self.platform = platform
self.reason = reason
detail = f"Failed to extract content from {platform}."
if reason:
detail += f" {reason}"
super().__init__(
message=detail,
user_message=f"Couldn't process this {platform} link right now. Please try again later.",
)
class MediaPrivateError(PlatformExtractError):
"""Raised when media is private, deleted, or requires login."""
def __init__(self, platform: str):
super().__init__(
platform=platform,
reason="Content is private, deleted, or restricted.",
)
self.user_message = "This post appears to be private, deleted, or restricted."
class MediaGeoBlockedError(PlatformExtractError):
"""Raised when content is region-blocked or unavailable."""
def __init__(self, platform: str):
super().__init__(
platform=platform,
reason="Content is region-restricted.",
)
self.user_message = "This content is not available in the current region."
class ContentTooLargeError(DownloaderBaseException):
"""Raised when remote media file size exceeds Telegram limits."""
def __init__(self, size_bytes: int, limit_bytes: int):
self.size_bytes = size_bytes
self.limit_bytes = limit_bytes
super().__init__(
message=f"Media size {size_bytes} exceeds limit {limit_bytes}.",
user_message="The media file is too large for Telegram.",
)