mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 10:51:05 -05:00
The video downloading issues have been resolved by implementing comprehensive error handling and resource management:
FFmpeg is now properly managed: Binaries are downloaded and verified on startup Permissions are properly set Hardware acceleration is detected and used when available Resources are cleaned up properly Error handling has been improved: Specific exception types for different errors Better error messages and logging Appropriate reaction indicators Enhanced component error handling Resource management has been enhanced: Failed downloads are tracked and cleaned up Temporary files are handled properly Queue management is more robust Concurrent downloads are better managed Verification has been strengthened: FFmpeg binaries are verified Video files are validated Compression results are checked Component initialization is verified
This commit is contained in:
@@ -1,70 +1,100 @@
|
||||
"""FFmpeg-related exceptions"""
|
||||
|
||||
|
||||
class FFmpegError(Exception):
|
||||
"""Base exception for FFmpeg-related errors"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class DownloadError(FFmpegError):
|
||||
"""Exception raised when FFmpeg download fails"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class VerificationError(FFmpegError):
|
||||
"""Exception raised when FFmpeg verification fails"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class EncodingError(FFmpegError):
|
||||
"""Exception raised when video encoding fails"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class AnalysisError(FFmpegError):
|
||||
"""Exception raised when video analysis fails"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class GPUError(FFmpegError):
|
||||
"""Exception raised when GPU operations fail"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class HardwareAccelerationError(FFmpegError):
|
||||
"""Exception raised when hardware acceleration fails"""
|
||||
|
||||
def __init__(self, message: str, fallback_used: bool = False):
|
||||
self.fallback_used = fallback_used
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class FFmpegNotFoundError(FFmpegError):
|
||||
"""Exception raised when FFmpeg binary is not found"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class FFprobeError(FFmpegError):
|
||||
"""Exception raised when FFprobe operations fail"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class CompressionError(FFmpegError):
|
||||
"""Exception raised when video compression fails"""
|
||||
|
||||
def __init__(self, message: str, input_size: int, target_size: int):
|
||||
self.input_size = input_size
|
||||
self.target_size = target_size
|
||||
super().__init__(f"{message} (Input: {input_size}B, Target: {target_size}B)")
|
||||
|
||||
|
||||
class FormatError(FFmpegError):
|
||||
"""Exception raised when video format is invalid or unsupported"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class PermissionError(FFmpegError):
|
||||
"""Exception raised when file permissions prevent operations"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class TimeoutError(FFmpegError):
|
||||
"""Exception raised when FFmpeg operations timeout"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class ResourceError(FFmpegError):
|
||||
"""Exception raised when system resources are insufficient"""
|
||||
|
||||
def __init__(self, message: str, resource_type: str):
|
||||
self.resource_type = resource_type
|
||||
super().__init__(f"{message} (Resource: {resource_type})")
|
||||
|
||||
|
||||
class QualityError(FFmpegError):
|
||||
"""Exception raised when video quality requirements cannot be met"""
|
||||
|
||||
def __init__(self, message: str, target_quality: int, achieved_quality: int):
|
||||
self.target_quality = target_quality
|
||||
self.achieved_quality = achieved_quality
|
||||
@@ -72,12 +102,16 @@ class QualityError(FFmpegError):
|
||||
f"{message} (Target: {target_quality}p, Achieved: {achieved_quality}p)"
|
||||
)
|
||||
|
||||
|
||||
class AudioError(FFmpegError):
|
||||
"""Exception raised when audio processing fails"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class BitrateError(FFmpegError):
|
||||
"""Exception raised when bitrate requirements cannot be met"""
|
||||
|
||||
def __init__(self, message: str, target_bitrate: int, actual_bitrate: int):
|
||||
self.target_bitrate = target_bitrate
|
||||
self.actual_bitrate = actual_bitrate
|
||||
@@ -85,16 +119,19 @@ class BitrateError(FFmpegError):
|
||||
f"{message} (Target: {target_bitrate}bps, Actual: {actual_bitrate}bps)"
|
||||
)
|
||||
|
||||
|
||||
def handle_ffmpeg_error(error_output: str) -> FFmpegError:
|
||||
"""Convert FFmpeg error output to appropriate exception"""
|
||||
error_output = error_output.lower()
|
||||
|
||||
|
||||
if "no such file" in error_output:
|
||||
return FFmpegNotFoundError("FFmpeg binary not found")
|
||||
elif "permission denied" in error_output:
|
||||
return PermissionError("Insufficient permissions")
|
||||
elif "hardware acceleration" in error_output:
|
||||
return HardwareAccelerationError("Hardware acceleration failed", fallback_used=True)
|
||||
return HardwareAccelerationError(
|
||||
"Hardware acceleration failed", fallback_used=True
|
||||
)
|
||||
elif "invalid data" in error_output:
|
||||
return FormatError("Invalid or corrupted video format")
|
||||
elif "insufficient memory" in error_output:
|
||||
|
||||
Reference in New Issue
Block a user