A powerful Discord bot that efficiently downloads and processes videos from various sources streaming via M3U8, featuring an advanced queue management system and intelligent file handling capabilities. TBX-DL combines stealth browser automation with robust queue management to provide a reliable video downloading solution.
- ๐ฅ Downloads videos from multiple platforms and URLs
- ๐ฅ Processes videos with automatic format optimization
- ๐ Smart queue management system (processes 2 URLs concurrently)
- ๐พ File size limit enforcement (configurable, default 10MB)
- ๐งน Automatic message cleanup for a tidy Discord channel
The bot implements a robust queue management system to handle video downloads efficiently and prevent system overload:
- ๐ Concurrent Processing: Handles multiple downloads (default: 2) simultaneously while maintaining system stability
- ๐พ Persistent Storage: Queue state is preserved in a local file system, ensuring no requests are lost during restarts
- ๐ Batch Processing: Implements smart batching to process requests in optimal groups
- ๐ Position Tracking: Real-time tracking of queue positions with user feedback
- ๐ฏ FIFO Implementation: First-in-first-out queue system ensures fair processing order
- ๐ Auto-Recovery: Automatically recovers queue state after system restarts
- โก Memory Efficient: Streams data to disk to handle large queues without memory issues
- ๐ Graceful Handling: Proper error handling and cleanup for failed downloads
- ๐ฅ Check queue status:
!q
- ๐๏ธ Clear entire queue:
!clear
- ๐ View position: Automatic position updates with each submission
// Queue configuration in constants.js
MAX_CONCURRENT_DOWNLOADS = 2; // Concurrent download limit
WORKER_CONCURRENCY = 20; // Worker threads for processing
The bot utilizes advanced browser automation with Puppeteer Stealth to bypass anti-bot measures and handle complex video streaming services:
- ๐ญ Chromium Fingerprint Masking: Prevents detection of automated browser usage
- ๐ WebDriver Detection Bypass: Eliminates traces of automation frameworks
- ๐ Network Pattern Normalization: Mimics natural browser network patterns
- ๐ฅ๏ธ Hardware Concurrency Spoofing: Simulates realistic system configurations
- ๐ถ๏ธ Stealth Plugin Integration: Uses
puppeteer-extra-plugin-stealth
for enhanced anonymity - ๐ฏ User Agent Rotation: Dynamic user agent management
- ๐ Anti-Bot Bypass: Successfully handles services with strict anti-bot measures
- ๐ Auto-Recovery: Intelligent browser session management and recovery
// Browser configuration
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());
// Browser launch configuration
const browser = await puppeteer.launch({
headless: false,
args: BROWSER_ARGS, // Customized browser arguments
});
- ๐ง Custom browser arguments for optimal performance
- โก Automatic page resource management
- ๐ Session persistence and cleanup
- ๐ Network interception capabilities
- ๐ช Persistent queue system that survives bot restarts
- ๐ Real-time progress tracking and notifications
- ๐ณ Docker support for seamless deployment
- ๐ Multi-threaded video segment processing
- ๐ก๏ธ Built-in rate limiting and error handling
-
WhatsApp Integration:
- Direct video downloads through WhatsApp commands
- Group chat support for collaborative downloading
- Instant video sharing capabilities
- Custom format selection via WhatsApp interface
-
Telegram Bot Integration:
- Parallel bot service on Telegram
- Inline command support for quick downloads
- Channel-based queue management
- Progress tracking through message updates
-
Slack Workspace Integration:
- Enterprise-focused video downloading
- Team-based queue management
- Workspace-specific configurations
- Integration with Slack workflows
-
๐ Cross-Platform Sync:
- Unified queue across multiple platforms
- Synchronized progress tracking
- Shared configuration management
- Cross-platform file sharing
-
๐จ Enhanced Processing:
- Advanced video format conversion
- Custom video trimming and editing
- Thumbnail generation
- Subtitle extraction and embedding
-
๐ Advanced Security:
- Multi-factor authentication
- Platform-specific access controls
- Rate limiting per user/platform
- Enhanced stealth capabilities
-
๐ RESTful API Service:
- Public API for third-party integrations
- Webhook support for status updates
- API key management system
- Documentation and SDK development
-
๐ง Developer Tools:
- CLI tool for local usage
- SDK for multiple programming languages
- Plugin system for custom extensions
- Integration templates and examples
-
โก Performance Optimizations:
- Distributed queue processing
- Cloud-based video processing
- Regional content delivery
- Load balancing capabilities
-
๐ Analytics & Monitoring:
- Usage statistics dashboard
- Performance metrics tracking
- Error rate monitoring
- Resource utilization insights
- Node.js >= 16.0.0 (for local deployment)
- FFmpeg (automatically installed via ffmpeg-static)
- Discord Bot Token
- Docker and Docker Compose (optional, for containerized deployment)
The bot offers extensive customization through src/config/constants.js
. Here's a complete list of all available configuration options:
- ๐ฆ
MAX_FILE_SIZE_MB
: Maximum file size limit (default: 10MB) - ๐
MAX_FILE_SIZE_BYTES
: Automatically calculated from MAX_FILE_SIZE_MB - ๐ข
SEGMENTS_PER_MB
: Number of segments per megabyte (default: 3) - ๐
MAX_SEGMENTS
: Maximum segments per file (default: 30 for 10MB) - โก
DOWNLOAD_ALL_SEGMENTS
: Force download all segments regardless of size (default: false)
- ๐
MAX_CONCURRENT_DOWNLOADS
: Number of parallel downloads (default: 2) - ๐งต
WORKER_CONCURRENCY
: Number of worker threads for processing (default: 20) - โฑ๏ธ
PAGE_LOAD_TIMEOUT
: Maximum wait time for page load (default: 60000ms) - ๐
M3U8_DETECTION_TIMEOUT
: Timeout for M3U8 stream detection (default: 30000ms) - ๐
DYNAMIC_CONTENT_WAIT
: Wait time for dynamic content loading (default: 15000ms)
- โจ๏ธ
BOT_PREFIX
: Command prefix for the bot (default: "!") - ๐ง
COMMANDS
: Command mappings:SCRAPE
: Download command (default: "s")HELP
: Help command (default: "help")QUEUE
: Queue status command (default: "q")CLEAR
: Queue clear command (default: "clear")
- ๐งน
MESSAGE_DELETE_TIMEOUT
: Auto-delete timeout for messages (default: 5000ms)
- ๐
BROWSER_ARGS
: Chromium launch arguments:[ '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-accelerated-2d-canvas', '--disable-gpu', '--window-size=1920,1080', ];
- ๐ญ
USER_AGENT
: Custom user agent string for browser requests'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36';
All configurations can be modified in src/config/constants.js
before deployment. For runtime changes, consider implementing a configuration reload mechanism.
-
Clone the repository:
git clone <repository-url> cd discord-video-downloader
-
Install dependencies:
npm install
-
Set up environment:
cp .env.example .env
-
Configure your
.env
file:DISCORD_TOKEN=your_discord_bot_token_here
-
Clone and prepare:
git clone <repository-url> cd discord-video-downloader cp .env.example .env
-
Build and launch:
docker-compose up -d
-
Monitor logs:
docker-compose logs -f
npm run dev
# Local
npm start
# Docker
docker-compose up -d
!s <url>
- Add a video URL to download queue!q
- View current queue status!help
- Display help information!clear
- Clear the download queue
src/
โโโ config/ # Configuration and constants
โโโ services/ # Core service implementations
โโโ utils/ # Helper utilities
โโโ workers/ # Worker thread processors
โโโ index.js # Main bot entry point
./output
: Permanent storage for processed videos (currently cleanup after serving videos for efficient storage management)./segments
: Temporary storage for video processing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the ISC License.
- ๐ซ Report issues via GitHub Issues
- ๐ก Feature requests are welcome
- ๐ค Pull requests are encouraged
Made with โค๏ธ for the Discord community