Skip to content

Advanced Discord bot for downloading and processing M3U8 video streams with stealth capabilities and intelligent queue management. Features multi-threaded processing, anti-detection measures, and Docker support for seamless deployment

License

Notifications You must be signed in to change notification settings

ST1LLWATER/tbx-dl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– TBX-DL (TurboBox Downloader)

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.

โœจ Key Features

Core Functionality

  • ๐Ÿ“ฅ 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

๐Ÿ”„ Queue Service Architecture

The bot implements a robust queue management system to handle video downloads efficiently and prevent system overload:

Core Queue Features

  • ๐Ÿ“Š 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

Queue Management

  • ๐ŸŽฏ 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

Queue Commands

  • ๐Ÿ“ฅ Check queue status: !q
  • ๐Ÿ—‘๏ธ Clear entire queue: !clear
  • ๐Ÿ“Š View position: Automatic position updates with each submission

Technical Implementation

// Queue configuration in constants.js
MAX_CONCURRENT_DOWNLOADS = 2; // Concurrent download limit
WORKER_CONCURRENCY = 20; // Worker threads for processing

๐Ÿ•ต๏ธ Browser Automation & Stealth Features

The bot utilizes advanced browser automation with Puppeteer Stealth to bypass anti-bot measures and handle complex video streaming services:

๐Ÿ›ก๏ธ Anti-Detection Features

  • ๐ŸŽญ 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

๐Ÿ”’ Advanced Protection

  • ๐Ÿ•ถ๏ธ 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

๐Ÿ’ก Technical Implementation

// 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
});

๐ŸŽ›๏ธ Configurable Browser Options

  • ๐Ÿ”ง Custom browser arguments for optimal performance
  • โšก Automatic page resource management
  • ๐Ÿ”„ Session persistence and cleanup
  • ๐ŸŒ Network interception capabilities

Advanced Features

  • ๐Ÿ’ช 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

๐Ÿ”ฎ Future Scope & Integrations

๐Ÿ“ฑ Platform Extensions

  • 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

๐ŸŽฏ Feature Expansions

  • ๐Ÿ”„ 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

๐Ÿ’ก API Development

  • ๐Ÿ”Œ 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

๐Ÿš€ Scalability Improvements

  • โšก 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

๐Ÿ› ๏ธ Technical Specifications

System Requirements

  • 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)

Configurable Options

The bot offers extensive customization through src/config/constants.js. Here's a complete list of all available configuration options:

๐Ÿ’พ File Management

  • ๐Ÿ“ฆ 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)

โš™๏ธ Performance Settings

  • ๐Ÿ”„ 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 Configuration

  • โŒจ๏ธ 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 Settings

  • ๐Ÿ”’ 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.

๐Ÿš€ Installation & Setup

๐Ÿ“‹ Local Deployment

  1. Clone the repository:

    git clone <repository-url>
    cd discord-video-downloader
  2. Install dependencies:

    npm install
  3. Set up environment:

    cp .env.example .env
  4. Configure your .env file:

    DISCORD_TOKEN=your_discord_bot_token_here
    

๐Ÿณ Docker Deployment

  1. Clone and prepare:

    git clone <repository-url>
    cd discord-video-downloader
    cp .env.example .env
  2. Build and launch:

    docker-compose up -d
  3. Monitor logs:

    docker-compose logs -f

๐Ÿ’ป Usage Guide

Development Mode

npm run dev

Production Mode

# Local
npm start

# Docker
docker-compose up -d

๐Ÿค– Bot Commands

  • !s <url> - Add a video URL to download queue
  • !q - View current queue status
  • !help - Display help information
  • !clear - Clear the download queue

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ config/         # Configuration and constants
โ”œโ”€โ”€ services/       # Core service implementations
โ”œโ”€โ”€ utils/          # Helper utilities
โ”œโ”€โ”€ workers/        # Worker thread processors
โ””โ”€โ”€ index.js        # Main bot entry point

๐Ÿ’พ Data Persistence

Docker Volumes

  • ./output: Permanent storage for processed videos (currently cleanup after serving videos for efficient storage management)
  • ./segments: Temporary storage for video processing

๐Ÿค Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the ISC License.

๐ŸŒŸ Support & Community

  • ๐Ÿ“ซ Report issues via GitHub Issues
  • ๐Ÿ’ก Feature requests are welcome
  • ๐Ÿค Pull requests are encouraged

Made with โค๏ธ for the Discord community

About

Advanced Discord bot for downloading and processing M3U8 video streams with stealth capabilities and intelligent queue management. Features multi-threaded processing, anti-detection measures, and Docker support for seamless deployment

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published