Commit Graph

271 Commits

Author SHA1 Message Date
pacnpal
08d5dc56cf Fixed role_manager.py typing issues by adding missing imports (Optional, Any)
Added process_queue method to EnhancedVideoQueueManager and updated its initialization
Updated component_manager.py to use EnhancedVideoQueueManager correctly
Fixed circular imports in the core module by:
Moving initialization logic to lifecycle.py
Making initialization.py provide thin wrappers that delegate to lifecycle.py
Ensuring proper import order in base.py
Verified all module init.py files are properly exposing their components:
core/init.py exposes VideoArchiver
queue/init.py exposes EnhancedVideoQueueManager and dependencies
processor/init.py exposes VideoProcessor and related components
commands/init.py exposes command setup functions
The import chain is now clean:

base.py imports from lifecycle.py
lifecycle.py contains all initialization logic
initialization.py delegates to lifecycle.py
No circular dependencies
All components are properly exposed through their respective init.py files
2024-11-16 17:13:11 +00:00
pacnpal
e680002731 All module components are now properly initialized and imported:
Database components with proper schema management
FFmpeg components with process management
Queue system with state management
Processor components with proper handlers
Utility components with shared instances
Configuration components with validation
Initialization sequence is now properly ordered:

Config Manager initialization
Path setup
Database initialization
FFmpeg setup
Queue Manager initialization
Video Processor setup
Guild Components initialization
Update Checker startup
Queue Processing start
Proper cleanup handling is in place:

Component cleanup in reverse order
Resource cleanup with timeouts
Force cleanup for hung processes
System-wide FFmpeg process cleanup
Health monitoring is implemented for all components:

Database connection monitoring
Queue health checks
Processor status tracking
Component state validation
2024-11-16 16:43:02 +00:00
pacnpal
871eccd978 video_downloader.py correctly imports and uses secure_delete_file with await
guild.py correctly imports cleanup_downloads directly from file_ops.py
initialization.py now correctly imports cleanup_downloads from file_ops.py
cleanup.py now correctly imports cleanup_downloads from file_ops.py
utils/init.py correctly re-exports both functions
The circular import has been resolved by:

Having all files import directly from file_ops.py
Removing the re-export of cleanup_downloads from cleanup.py
Ensuring proper async/await usage throughout
2024-11-16 16:35:41 +00:00
pacnpal
e937d1a5e2 ok 2024-11-16 05:05:21 +00:00
pacnpal
a4ca6e8ea6 Core Systems:
Component-based architecture with lifecycle management
Enhanced error handling and recovery mechanisms
Comprehensive state management and tracking
Event-driven architecture with monitoring
Queue Management:

Multiple processing strategies for different scenarios
Advanced state management with recovery
Comprehensive metrics and health monitoring
Sophisticated cleanup system with multiple strategies
Processing Pipeline:

Enhanced message handling with validation
Improved URL extraction and processing
Better queue management and monitoring
Advanced cleanup mechanisms
Overall Benefits:

Better code organization and maintainability
Improved error handling and recovery
Enhanced monitoring and reporting
More robust and reliable system
2024-11-16 05:01:29 +00:00
pacnpal
537a325807 Core Functionality:
base.py: Streamlined to core cog functionality and lifecycle management
initialization.py: Centralized initialization logic
error_handler.py: Unified error handling
response_handler.py: Consistent response handling
Command Organization:

commands/archiver_commands.py: Core archiver functionality
commands/database_commands.py: Database operations
commands/settings_commands.py: Settings management
All commands properly integrated with the cog using setup functions
Improved Architecture:

Consistent command registration pattern
Better separation of concerns
Maintained all original functionality
Enhanced error handling and response management
Proper command integration with the cog structure
2024-11-16 03:30:11 +00:00
pacnpal
6aeb87fb40 Added immediate deferral for all slash commands that perform async operations, preventing the "Unknown interaction" error
Improved the interaction response handling system to better manage both deferred and non-deferred responses
Enhanced error handling around interaction responses
Added proper fallback mechanisms for response handling
2024-11-16 03:12:22 +00:00
pacnpal
e1d65ffcd0 massage 2024-11-16 02:11:44 +00:00
pacnpal
b2369d6e61 no 2024-11-16 02:06:33 +00:00
pacnpal
fa494dccd3 fix 2024-11-16 01:57:41 +00:00
pacnpal
18792c77f2 fix 2024-11-16 01:50:34 +00:00
pacnpal
669db54442 Added proper error handling in enable_database command to handle cases where the setting doesn't exist yet
Fixed redbot import issues by importing specific exception classes
Ensured database setting is properly synchronized between base.py and config_manager.py
Added proper database initialization and reference handling
2024-11-16 01:43:17 +00:00
pacnpal
372b7de34a Changed the default "enabled" setting in base.py from True to False to match config_manager.py's default.
Fixed the command error handling by properly referencing the commands from redbot.core.commands instead of using the bare 'commands' reference.
2024-11-16 01:33:59 +00:00
pacnpal
609aecdc4e Updated default settings (video archiving enabled by default)
New database functionality and commands
Additional video format support (MKV)
Message duration now in hours (0-168)
Enhanced error handling and logging
Queue persistence and management improvements
Hardware acceleration updates
More detailed command descriptions
Improved performance & limitations documentation
2024-11-16 01:22:37 +00:00
pacnpal
01a9067368 Added proper command validation in the on_message event handler to prevent interference with command processing
Added missing asyncio import in events.py
Ensured all long-running operations are handled in background tasks
Fixed task initialization and management in base.py
2024-11-16 01:04:08 +00:00
pacnpal
46250b14d0 Fixed the prefix checking logic to properly handle multiple prefixes
Commands will now work correctly during initialization
Video processing features still wait for full initialization
Properly handle both single string and list prefixes
2024-11-16 00:42:31 +00:00
pacnpal
18b5d305f3 Commands will now work even during initialization
Only video processing features are blocked until initialization completes
The on_message event handler now checks if a message is a command first and lets it process normally
2024-11-16 00:39:40 +00:00
pacnpal
3520111cec Fixing race conditions and deadlocks in the queue system by:
Using a single lock instead of multiple locks
Properly handling task cancellation
Adding timeouts and retries
Improving error handling and recovery across all components:

Queue manager now properly handles initialization failures
Monitoring system has shorter timeouts and better activity tracking
Cleanup system has proper task tracking and error recovery
Persistence system has file locking and backup mechanisms
Removing deprecated pkg_resources usage and improving the update checker:

Using importlib.metadata for version checking
Adding proper shutdown handling
Improving error handling and retries
2024-11-16 00:36:46 +00:00
pacnpal
51a4e8f48c Updated update_checker.py to use importlib.metadata instead of the deprecated pkg_resources
Verified no other files were using pkg_resources
Maintained all existing functionality while using modern Python package version checking
2024-11-16 00:29:51 +00:00
pacnpal
32c63deeff Removed the problematic singleton pattern from queue manager
Added proper activity tracking in the monitoring system
Reduced timeouts and deadlock thresholds
Implemented more aggressive cleanup procedures
Added system-wide FFmpeg process cleanup
2024-11-16 00:24:28 +00:00
pacnpal
39061cbf3e Added proper initialization control:
Setup lock in init.py to prevent concurrent cog loads
Check for existing cog instance to prevent duplicates
Setup_in_progress flag to track initialization state
Improved timeout handling and cleanup
Enhanced Queue Manager singleton pattern:
Class-level lock to prevent multiple instance creation
Consistent event naming with _init_event
Sequential component initialization
Proper lock ordering (global -> queue -> processing)
Improved state management:
Single source of truth for initialization state
Proper cleanup of resources on failure
Better error handling and logging
Timeout handling for all async operations
2024-11-15 23:09:55 +00:00
pacnpal
53e7769811 Added proper initialization sequence in the queue manager:
Sequential component initialization
Coordination through an _initialized event
Consistent lock hierarchy with _global_lock
Updated the base cog to properly initialize components:
Added timeout handling for queue manager initialization
Ensures queue manager is fully initialized before starting queue processing
Added proper error handling and cleanup
Established consistent lock ordering:
Global Lock -> Queue Lock -> Processing Lock
Prevents circular wait conditions
Each component respects the lock hierarchy
Improved task coordination:
Sequential initialization of components
Proper waiting for initialization before starting operations
Timeout handling for all async operations
2024-11-15 23:04:13 +00:00
pacnpal
9e7e4a851d Fixed _process_item method:
Removed all duplicate code and unnecessary operations
Proper error handling with clean structure
Efficient state management with locks
No unnecessary persistence or sleep calls
Improved queue processing:

Batch processing up to 5 items at a time
Concurrent processing using asyncio.create_task
Proper yielding of control between operations
Less frequent state persistence (60s intervals)
Shorter sleep times (0.1s) when queue is empty
Better resource management:

Proper task tracking and cleanup
Efficient error recovery
Clean state persistence
Proper lock usage to prevent race conditions
2024-11-15 22:57:21 +00:00
pacnpal
c122319eb9 Added the missing process_video method to VideoProcessor that properly delegates to QueueHandler
Modified the initialization process to start queue processing as a non-blocking background task
Added proper cleanup of the queue task during cog unload
Optimized the queue manager's process_queue method to:
Use shorter sleep times (0.1s) when queue is empty
Persist state less frequently (every 60s)
Better handle task switching with asyncio.sleep(0)
Improve error recovery with brief pauses
These changes resolve both the initial "process_video missing" error and the subsequent "initialization timeout" error by:

Properly implementing the missing method
Making queue processing non-blocking during initialization
Ensuring proper cleanup of all tasks
Optimizing the queue processing loop for better performance
2024-11-15 22:48:54 +00:00
pacnpal
d83c04817e update 2024-11-15 22:46:33 +00:00
pacnpal
e5459fc3b8 yeah 2024-11-15 22:46:10 +00:00
pacnpal
8204df3599 Added process_video method to VideoProcessor class
Method delegates to queue_handler.process_video
Maintains proper separation of concerns between components
Preserves the existing video processing logic
2024-11-15 22:42:36 +00:00
pacnpal
512dd1ff88 Eliminating duplicate queue processing that was causing race conditions
Adding proper processing state tracking and timing
Implementing more aggressive monitoring (1-minute intervals)
Adding activity tracking to detect and recover from hung states
Improving error handling and logging throughout the system
Reducing timeouts and deadlock thresholds for faster recovery
2024-11-15 22:38:36 +00:00
pacnpal
73364e7438 ok 2024-11-15 22:27:29 +00:00
pacnpal
f691d6a96c Fixed a circular import in processor.py by correcting the import statement from 'videoarchiver.processor' to '.processor'
Removed the separate commands cog loading from init.py since all commands are now part of the main VideoArchiver class
Verified the core/init.py is correctly exporting the VideoArchiver class
Removed the redundant video_archiver.py file
These changes should resolve both the "No module named 'videoarchiver.commands'" error and the asyncio-related issues by:

Eliminating circular imports that could cause import-time issues
Simplifying the cog loading process to only load the main VideoArchiver class
Ensuring proper module structure and exports
2024-11-15 22:22:24 +00:00
pacnpal
97e0d9c279 re-structure 2024-11-15 22:17:30 +00:00
pacnpal
5fedd97b61 yeah 2024-11-15 22:02:19 +00:00
pacnpal
87605ad7f1 Added extremely aggressive timeouts:
CLEANUP_TIMEOUT = 1s
UNLOAD_TIMEOUT = 2s
INIT_TIMEOUT = 5s
COMPONENT_INIT_TIMEOUT = 2s
Added timeout protection for all async operations:

Download cleanup
Guild component initialization
Update checker start
Cleanup processes
Force cleanup fallbacks
Improved cleanup process:

Immediate task cancellation
Aggressive reference clearing
Force cleanup fallbacks
Comprehensive error logging
2024-11-15 21:49:58 +00:00
pacnpal
2025c4e8f0 Fixed the guild_only import by importing it directly from redbot.core.commands
Improved the cog unload process by:
Reducing cleanup timeouts (UNLOAD_TIMEOUT to 5s, CLEANUP_TIMEOUT to 3s)
Adding immediate task cancellation
Implementing aggressive cleanup with force_cleanup_resources
Clearing all references in the finally block
Fixed code indentation issues
2024-11-15 21:39:19 +00:00
pacnpal
29f7a6345e fix 2024-11-15 21:22:55 +00:00
pacnpal
e8f02c2b59 fix 2024-11-15 21:19:52 +00:00
pacnpal
1748ab2188 Changed VideoArchiver to inherit from GroupCog instead of Cog
Moved all command definitions directly into the VideoArchiver class
Updated command decorators to use proper hybrid_group and hybrid_command syntax
Properly set up command error handling within the class
Removed external command setup in favor of class-based commands
Maintained backward compatibility through a stub commands.py file
2024-11-15 20:18:51 +00:00
pacnpal
121e1395f4 Updated default_guild_settings in core/base.py from 25MB to 8MB
Verified consistency with config_manager.py which already had 8MB as default
Confirmed proper validation in config_manager.py (allows 1-100MB range)
Verified all other files reference the max_file_size setting correctly
2024-11-15 20:11:43 +00:00
pacnpal
42b3ceb314 Created /core module with specialized files:
base.py: Main cog class and initialization logic
cleanup.py: Resource cleanup functionality
commands.py: Command handlers
events.py: Event listeners
guild.py: Guild component management
init.py: Module exports
Improved code organization by:

Separating concerns into focused modules
Maintaining clear dependencies between modules
Keeping related functionality together
Making the codebase more maintainable
Preserved all existing functionality while making the code more modular and easier to maintain.
2024-11-15 20:01:45 +00:00
pacnpal
434911abf0 fix 2024-11-15 19:39:36 +00:00
pacnpal
dae8bbb6b4 Adding the 'db' parameter to the VideoProcessor class initialization
Properly storing and handling the db instance
Ensuring the db is passed to the queue_handler when available
The QueueHandler class was already properly set up to handle the db parameter, so no changes were needed there. The database integration should now work correctly for:

Checking if videos are already archived
Adding newly archived videos to the database
Providing archived video information to users
2024-11-15 19:22:52 +00:00
pacnpal
2e2951e714 Fixed the "cannot import name '_download_progress'" error by:
Adding a shared progress_tracker instance in processor/init.py
Exposing public functions that wrap the ProgressTracker methods
Removing direct access to private _download_progress variable
Fixed the "'QueueItem' object has no attribute 'retry_count'" error by:

Updating the QueueItem class in queue/models.py to use retry_count instead of retries
This matches the field name used in the queue manager's implementation
2024-11-15 19:19:46 +00:00
pacnpal
12810273a6 Adding the missing priority field with a default value of 0 2024-11-15 19:05:28 +00:00
pacnpal
780be9e391 Adding the missing guild_id field to the QueueItem class
Changing user_id to author_id for consistency with the message handler
Updating the field types from str to int for all Discord IDs (message_id, channel_id, author_id, guild_id)
2024-11-15 19:02:51 +00:00
pacnpal
971d52bd00 Separation of Concerns:
Core processing logic in VideoProcessor class
Dedicated message handling in MessageHandler
Queue operations in QueueHandler
Progress tracking in ProgressTracker
Reaction management in reactions.py
Improved Maintainability:
Each component has a single responsibility
Easier to test individual components
Better code organization and readability
Reduced file sizes for better version control
Better Resource Management:
Centralized progress tracking
Isolated queue operations
Cleaner cleanup processes
Optimized Imports:
Components can be imported individually as needed
Main processor.py provides backward compatibility
Clear module interface through init.py
2024-11-15 18:58:05 +00:00
pacnpal
8b0103ca08 Only accept URLs that match known video platform patterns (YouTube, Vimeo, TikTok, etc.)
Accept URLs that end in video file extensions (.mp4, .webm, .mov)
Reject invalid URLs like "huge." that don't match any video patterns
2024-11-15 18:50:39 +00:00
pacnpal
61fbe7ca49 Adding the processing_time field to the QueueItem class in models.py with a default value of 0.0
Ensuring proper type conversion for the processing_time field in the persistence layer
Maintaining all existing functionality while adding the new field
2024-11-15 18:45:25 +00:00
pacnpal
6337e1dc01 Fix URL detection and validation
- Add proper URL validation (must start with http/https or contain dot)
- Remove duplicate URL check that caused double processing
- Add detailed debug logging for URL detection process
- Fix enabled_sites filtering logic

This fixes issues with URL detection and improves validation to prevent processing non-URL text.
2024-11-15 18:37:08 +00:00
pacnpal
13c51d334a updates 2024-11-15 18:27:04 +00:00
pacnpal
33180f1d36 Fix URL detection logic
- Accept all URLs if no sites are enabled (default behavior)
- Only filter URLs against enabled_sites if specific sites are set
- Add detailed logging for URL detection process
- Log guild settings and enabled sites

This fixes the issue where URLs weren't being detected when no sites were explicitly enabled.
2024-11-15 18:26:01 +00:00