mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
- Created ffmpeg package with specialized modules - Improved Docker compatibility using /tmp - Better permission handling - More robust error handling - Separated concerns for easier maintenance - Simplified imports through __init__.py
VideoArchiver Cog
A Red-DiscordBot cog for automatically archiving videos from monitored Discord channels. Supports both traditional prefix commands and Discord slash commands.
Features
- Automatically detects and downloads videos from monitored channels
- Supports multiple video hosting platforms through yt-dlp
- Enhanced queue system with priority processing and performance metrics
- Configurable video quality and format
- Role-based access control
- Automatic file cleanup
- Hardware-accelerated video processing (when available)
- Customizable notification messages
- Queue persistence across bot restarts
- Full slash command support for all commands
File Structure
The cog is organized into several modules for better maintainability:
video_archiver.py: Main cog class and entry pointcommands.py: Discord command handlersconfig_manager.py: Guild configuration managementprocessor.py: Video processing logicenhanced_queue.py: Advanced queue management systemupdate_checker.py: yt-dlp update managementutils.py: Utility functions and classesffmpeg_manager.py: FFmpeg configuration and hardware accelerationexceptions.py: Custom exception classes
Installation
- Install the cog using Red's cog manager:
[p]repo add videoarchiver <repository_url>
[p]cog install videoarchiver
- Load the cog:
[p]load videoarchiver
Configuration
Use the following commands to configure the cog. All commands support both prefix and slash command syntax:
Channel Settings
-
Set the archive channel:
[p]va setchannel <channel>or
/va setchannel <channel> -
Set the notification channel:
[p]va setnotification <channel>or
/va setnotification <channel> -
Set the log channel:
[p]va setlogchannel <channel>or
/va setlogchannel <channel> -
Add/remove a monitored channel:
[p]va addmonitor <channel> [p]va removemonitor <channel>or
/va addmonitor <channel> /va removemonitor <channel>
Role Management
- Add/remove allowed roles:
or
[p]va addrole <role> [p]va removerole <role> [p]va listroles/va addrole <role> /va removerole <role> /va listroles
Video Settings
- Set video format and quality:
or
[p]va setformat <format> [p]va setquality <pixels> [p]va setmaxsize <MB> [p]va setconcurrent <count>/va setformat <format> /va setquality <pixels> /va setmaxsize <MB> /va setconcurrent <count>
Message Settings
- Configure message handling:
or
[p]va setduration <hours> [p]va settemplate <template> [p]va toggledelete/va setduration <hours> /va settemplate <template> /va toggledelete
Site Management
- Manage supported sites:
or
[p]va enablesites [sites...] [p]va listsites/va enablesites [sites...] /va listsites
Queue Management
- Manage the processing queue:
or
[p]va queue [p]va clearqueue [p]va queuemetrics/va queue /va clearqueue /va queuemetrics
Update Management
- Manage yt-dlp updates:
or
[p]va updateytdlp [p]va toggleupdates/va updateytdlp /va toggleupdates
Technical Details
Enhanced Queue System
The cog uses an advanced queue system with the following features:
- Priority-based processing (first URL in messages gets highest priority)
- Queue persistence across bot restarts
- Automatic memory management and cleanup
- Performance metrics tracking (success rate, processing times)
- Health monitoring with automatic issue detection
- Deadlock prevention
- Configurable cleanup intervals
- Size-limited queue to prevent memory issues
- Detailed status tracking per guild
Queue Metrics
The queue system tracks various performance metrics:
- Total processed videos
- Success/failure rates
- Average processing time
- Peak memory usage
- Queue size per guild/channel
- Processing history
- Cleanup statistics
Configuration Management
- Settings are stored per guild
- Supports hot-reloading of configurations
- Automatic validation of settings
Error Handling
- Comprehensive error logging
- Automatic retry mechanisms with configurable attempts
- Guild-specific error reporting
- Detailed failure tracking
Performance Optimizations
- Hardware-accelerated video processing when available
- Efficient file handling with secure deletion
- Memory leak prevention through proper resource cleanup
- Automatic resource monitoring
- Periodic cleanup of old queue items
- Memory usage optimization
Requirements
- Python 3.8 or higher
- FFmpeg
- yt-dlp
- Discord.py 2.0 or higher
- Red-DiscordBot V3
- psutil>=5.9.0
Support
For issues and feature requests, please use the issue tracker on GitHub.