How st1llwater/tbx-dl works
Project Type and Purpose
• This is a Node.js–based Discord bot (“TBX-DL”) whose primary function is to download, process, and serve M3U8-streamed videos on demand.
• It exposes Discord slash/prefix commands, manages an efficient concurrent download queue, uses Puppeteer for stealth browser automation, and FFmpeg for video processing.
File Structure
• Top-level scripts & configs:
• Dockerfile, docker-compose.yml, .env.example – containerization and environment setup
• segmentWorker.js – worker entry point for streaming segment processing
• files.txt – persistence listing (queue state)
• src/commands – command definitions and a commandHandler
• clearCommand, helpCommand, queueCommand, scrapeCommand
• src/services – core services
• browserService.js (Puppeteer setup & navigation)
• videoService.js (FFmpeg-based segment assembly & optimization)
• src/utils – helpers
• fileUtils.js (disk I/O)
• queueManager.js (in-memory + file-backed FIFO queue)
• src/workers – worker thread logic for segment processing
• segmentWorker.js
• src/config/constants.js – all configurable parameters (queue sizes, browser args, file limits)
Key Insights from README
• Architecture revolves around a robust, persistent FIFO queue (local file backup, auto-recovery).
• Concurrency: 2 simultaneous downloads; up to 20 worker threads for segment handling.
• Browser automation via Puppeteer Stealth plugin; anti-detection measures; dynamic user-agent & network spoofing.
• Docker‐based deployment with persistent volume mappings for output and temporary segments.
Essentials to Capture
• Job lifecycle from command receipt to final video delivery
• Concurrency limits and worker pool structure
• Persistence layer ensuring auto-recovery
• Browser automation & stealth plugin integration
• Containerization boundaries (Docker host, volumes)