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:
pacnpal
2024-11-15 04:18:57 +00:00
parent 02966f1a66
commit c144fb35ba
7 changed files with 440 additions and 173 deletions

View File

@@ -18,6 +18,7 @@ from videoarchiver.utils.video_downloader import VideoDownloader
from videoarchiver.utils.message_manager import MessageManager
from videoarchiver.utils.file_ops import cleanup_downloads
from videoarchiver.enhanced_queue import EnhancedVideoQueueManager
from videoarchiver.ffmpeg.ffmpeg_manager import FFmpegManager # Add FFmpeg manager import
from videoarchiver.exceptions import (
ProcessingError,
ConfigError,
@@ -164,6 +165,8 @@ class VideoArchiver(commands.Cog):
await components['message_manager'].cancel_all_deletions()
if 'downloader' in components:
components['downloader'] = None
if 'ffmpeg_mgr' in components:
components['ffmpeg_mgr'] = None
except Exception as e:
logger.error(f"Error cleaning up guild {guild_id}: {str(e)}")
@@ -199,16 +202,23 @@ class VideoArchiver(commands.Cog):
await old_components['message_manager'].cancel_all_deletions()
if 'downloader' in old_components:
old_components['downloader'] = None
if 'ffmpeg_mgr' in old_components:
old_components['ffmpeg_mgr'] = None
# Initialize FFmpeg manager first
ffmpeg_mgr = FFmpegManager()
# Initialize new components with validated settings
self.components[guild_id] = {
'ffmpeg_mgr': ffmpeg_mgr, # Add FFmpeg manager to components
'downloader': VideoDownloader(
str(self.download_path),
settings['video_format'],
settings['video_quality'],
settings['max_file_size'],
settings['enabled_sites'] if settings['enabled_sites'] else None,
settings['concurrent_downloads']
settings['concurrent_downloads'],
ffmpeg_mgr=ffmpeg_mgr # Pass FFmpeg manager to VideoDownloader
),
'message_manager': MessageManager(
settings['message_duration'],
@@ -245,6 +255,8 @@ class VideoArchiver(commands.Cog):
await components['message_manager'].cancel_all_deletions()
if 'downloader' in components:
components['downloader'] = None
if 'ffmpeg_mgr' in components:
components['ffmpeg_mgr'] = None
# Remove guild components
self.components.pop(guild.id)