Commit Graph

395 Commits

Author SHA1 Message Date
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
pacnpal
c012baef07 Add debug logging for URL detection
- Added detailed logging in process_message method:
  - Log message content and attachments
  - Log guild settings and enabled sites
  - Log URL detection process for each word
  - Track queue additions and failures

This will help diagnose why URLs aren't being detected and added to the queue.
2024-11-15 18:24:11 +00:00
pacnpal
546ce5e66c remove enhanced queue file 2024-11-15 18:19:20 +00:00
pacnpal
6d1e373c43 Update VideoArchiver README with detailed queue system architecture
- Added detailed description of modular queue components:
  - Models for data structures
  - Persistence for state management
  - Monitoring for health checks
  - Cleanup for resource management
  - Manager for core operations

- Expanded metrics and monitoring section
- Added state management details
- Improved feature descriptions for new queue architecture
2024-11-15 18:19:05 +00:00
pacnpal
b1eafbb01d Refactor queue system into modular structure
- Created new queue module with separate components:
  - models.py: QueueItem and QueueMetrics data classes
  - persistence.py: Queue state persistence
  - monitoring.py: Health monitoring and metrics
  - cleanup.py: Cleanup operations
  - manager.py: Main queue management
  - __init__.py: Package exports

- Updated imports in video_archiver.py and processor.py
- Removed old enhanced_queue.py
- Updated README with new queue system details

This refactoring improves code organization and maintainability
through better separation of concerns while maintaining all
existing functionality.
2024-11-15 18:16:53 +00:00
pacnpal
44599b2b22 The TypeError in _monitor_health where string dates were being compared with datetime objects - Fixed by:
Adding a property-based approach for processing_time in QueueItem class
Ensuring processing_time is always stored as a float internally using _processing_time
Adding automatic type conversion in the property setter
Properly handling the conversion in to_dict and from_dict methods
Ensuring proper type checking in _monitor_health before comparisons
The "no running event loop" errors in the progress callback - Fixed by implementing proper event loop handling in processor.py's progress_callback function.
2024-11-15 18:07:08 +00:00
pacnpal
45492d7ee4 fixes 2024-11-15 17:59:26 +00:00
pacnpal
2bf85b532b Adding robust datetime handling in _periodic_cleanup:
Added try-except blocks around individual item processing
Added proper string to datetime conversion with fallbacks
Added cleanup of problematic items that can't be processed
Improved error handling:

Added specific error logging for individual item failures
Added graceful removal of problematic items
Ensured cleanup continues even if some items fail
Added fallback mechanisms:

Uses current_time as fallback for invalid datetime values
Removes items that can't be properly processed
Prevents single item failures from breaking the entire cleanup process
2024-11-15 17:35:14 +00:00
pacnpal
39169b3edb Fixed the TypeError in _periodic_cleanup by adding runtime type checking and conversion:
Added checks to ensure added_at is always a datetime object before comparison
Converts string timestamps to datetime objects when needed
Implemented proper datetime serialization/deserialization in QueueItem:

to_dict method properly converts datetime objects to ISO format strings
from_dict method properly converts ISO format strings back to datetime objects
Added datetime handling for all datetime fields:

added_at
last_retry
last_error_time
2024-11-15 17:32:12 +00:00
pacnpal
285e64db21 The "AttributeError: 'VideoProcessor' object has no attribute 'process_message'" error has been fixed by implementing the process_message method in the VideoProcessor class. This method now properly handles video processing requests from Discord messages.
The "TypeError: '<' not supported between instances of 'str' and 'datetime.datetime'" error has been fixed by implementing proper datetime handling in the QueueItem class. The added to_dict and from_dict methods ensure that datetime objects are correctly serialized and deserialized when saving and loading queue state.
2024-11-15 17:25:45 +00:00
pacnpal
56b4711661 fixes 2024-11-15 16:51:12 +00:00
pacnpal
e66af6e844 Added timeout handling and force cleanup in VideoArchiver cog
Added proper cancellation and requeuing of downloads in VideoProcessor
Added cancellable logger and process cleanup in VideoDownloader
Added shutdown flag and force_stop capability in EnhancedQueueManager
Added process tracking and kill_all_processes method in FFmpegManager
The changes ensure that:

Active downloads are paused and requeued when unload is called
If cleanup takes too long, force cleanup kicks in
All resources are properly cleaned up, even in case of timeout
Downloads can be safely cancelled and resumed later
No processes are left hanging during unload
2024-11-15 15:48:03 +00:00
pacnpal
74bd55c3e9 Enhanced Download Progress Tracking:
Track download speed, ETA, and bytes downloaded/total
Monitor fragment downloads and retry counts
Track video metadata (title, format, resolution, FPS)
Store extractor information and video details
Add timestamps for all progress updates
Detailed Compression Progress:
Track input/output file sizes and compression ratio
Monitor codec usage and hardware acceleration status
Track compression parameters (preset, CRF, bitrates)
Monitor elapsed time and estimated completion
Track audio codec and bitrate information
Queue Management Improvements:
Added global progress tracking dictionaries
Maintain active status of downloads and compressions
Track start times and last update timestamps
Store detailed error information when failures occur
Command Access:
Added queuedetails command for bot owners
Display comprehensive progress information
Show active downloads and compressions
Display detailed error statistics
Show hardware acceleration usage
2024-11-15 14:58:44 +00:00
pacnpal
cc3fa06d00 Add detailed progress tracking for downloads and compression:
- Add detailed download progress hook with extensive metadata
- Add comprehensive compression progress tracking
- Track download speed, ETA, file sizes, and formats
- Track compression codec, hardware acceleration, and bitrates
- Add timestamps for all progress updates
2024-11-15 14:58:30 +00:00
pacnpal
b8d6eb957c Improve queue persistence across cog reloads:
- Add global queue manager instance
- Modify initialization to use existing queue manager
- Add get_queue_manager() class method
- Prevent queue manager cleanup during reloads
2024-11-15 14:46:55 +00:00
pacnpal
90a3090379 Improve video download stability and progress tracking:
- Increase retries and retry delay
- Reduce concurrent downloads for better stability
- Add exponential backoff with jitter
- Improve progress logging and error handling
- Add file size limits and timeouts
- Optimize chunk size and socket timeout
2024-11-15 14:44:21 +00:00
pacnpal
245710e4d4 Added explicit import of CommandAlreadyRegistered exception
Wrapped the command registration in a try-except block
Silently continues if the command is already registered
Maintains all other functionality including cog loading and task initialization
2024-11-15 14:32:33 +00:00
pacnpal
172fe83288 Added a command existence check using discord.utils.get()
Only register the command if it's not already present
Maintained all other functionality including cog loading and task initialization
2024-11-15 14:30:50 +00:00
pacnpal
23fac11cfd Initial state: 📹 (video camera) when video is queued
Queue position: 1️⃣-5️⃣ showing position in queue
Download progress: 0️⃣2️⃣4️⃣6️⃣8️⃣🔟 showing download percentage (0%, 20%, 40%, 60%, 80%, 100%)
Processing state: ⚙️ when video is being processed
Compression progress: 🟨🟩 showing FFmpeg progress (0%, 50%, 100%)
Final state:  for success or  for failure
All status changes are now logged with message IDs for better tracking:

Queue position updates
Download progress at 20% intervals
Processing state changes
Compression progress
Success/failure states
Error conditions with detailed messages
2024-11-15 14:27:20 +00:00
pacnpal
c46e967378 Appears in the context menu when right-clicking a user
Checks for proper permissions
Removes the birthday role if present
Cancels any scheduled role removal tasks
Provides appropriate feedback and error handling
Logs all actions for debugging purposes
2024-11-15 14:19:30 +00:00
pacnpal
807422e160 Added proper exception handling for all try blocks that were missing except/finally clauses
Fixed the unclosed parenthesis in the format_message() call
Completed the message formatting section with proper parameters
Reorganized the code structure for better maintainability
Ensured proper error handling and cleanup throughout
2024-11-15 14:14:57 +00:00
pacnpal
f8d383a55a 📥 Pending: Shows items waiting to be processed
⚙️ Processing: Shows items currently being processed
 Completed: Shows successfully processed items
 Failed: Shows failed items
2024-11-15 14:12:43 +00:00
pacnpal
0d7b1d449f Made secure_delete_file and cleanup_downloads async in file_ops.py
Added chunked file processing and size limits to prevent blocking
Updated video_downloader.py to properly await secure_delete_file
Updated video_archiver.py to properly await cleanup_downloads
Simplified the secure deletion process while maintaining security
Added proper error handling and logging throughout
2024-11-15 13:47:28 +00:00
pacnpal
0194142c56 New Command:
Added /removebirthday command to manually remove birthday roles from users
Includes permission checks and proper error handling
Cleans up any scheduled tasks for the user
Enhanced Error Handling:

Added comprehensive try/except blocks throughout the cog
Added detailed logging for all operations and errors
Better handling of Discord API errors
Improved error messages for users
Improved Role Removal:

Added hourly cleanup task to ensure role removals are processed
Better handling of timezone issues
Proper cleanup of tasks when cog is unloaded
Improved task management to prevent memory leaks
Better Logging:

Added detailed logging for all operations
Logs include guild IDs, member IDs, and error details
Helps track issues and debug problems
2024-11-15 13:40:28 +00:00
pacnpal
b4479c951b Fixed Discord Integration:
Added missing discord import
Added proper error handling for all discord operations
Improved error reporting for discord-specific failures
Enhanced Error Handling:
Added try/except blocks around all major operations
Implemented proper cleanup in finally blocks
Added more specific error messages for debugging
Queue Processing Improvements:
Ensured the queue continues processing even if individual items fail
Added better file cleanup to prevent resource leaks
Improved error reporting to help diagnose issues
Resource Management:
Added proper cleanup of downloaded files
Improved handling of missing discord resources
Better management of failed downloads
2024-11-15 13:36:26 +00:00
pacnpal
887547473c Added proper physical GPU detection on Linux/Windows/macOS
Separated physical GPU detection from FFmpeg encoder support
Only enable GPU encoding when both physical GPU and FFmpeg support exist
Added multiple detection methods for better reliability
2024-11-15 05:26:10 +00:00
pacnpal
8e581d660e Fixed NVENC preset compatibility
Added proper NVENC preset validation
Separated CPU and GPU presets
Added preset conversion logic for GPU encoding
2024-11-15 05:22:38 +00:00