How hr3lxphr6j/bililive-go works
Main Components
• Live Recorder Core: This is the heart of the application. It includes the main command (src/cmd/bililive/bililive.go) that coordinates the live recording process.
• Live Providers Integration: Represented by the modules under src/live (with subfolders for each supported streaming platform like bilibili, douyu, huya, etc.). These components handle platform-specific details.
• Listeners & Event Handling: Under src/listeners and src/pkg/events, these modules monitor events (e.g., errors, status updates) and dispatch notifications or trigger actions.
• Recorder Module: Under src/recorders, which manages the actual recording process by interfacing with external tools such as ffmpeg.
• Configuration Management: Modules in src/configs (and the external config.yml/config.docker.yml files) handle runtime settings, including cookies and recording parameters.
• Web Server & API: Found in src/servers and the web application code in src/webapp. These parts expose functionalities via HTTP endpoints for configuration management, file access, and status updates.
• Metrics and Logging: src/metrics, src/log, and related packages capture and export monitoring data, supporting integration with Prometheus for metrics collection and Grafana for visualization.
• Utility Libraries: Generic helper functions (src/pkg/utils, src/pkg/counter, src/pkg/reader, etc.) that support the main workflow.
Relationships and Interactions
• The Application Server (HTTP server) interacts with the Webapp (React-based front end) to present configuration UIs, monitor recording statuses, and provide access to recorded videos.
• The Recorder Core coordinates with:
– Live Provider Modules: Each module (e.g., src/live/bilibili, src/live/douyu) implements platform-specific logic.
– Listener Modules that capture live events, errors, and notifications.
– The Recorder Module that uses ffmpeg (external dependency) to record streams.
• Configuration is centrally managed and read from config files, which can be updated either manually or via the web interface.
• Metrics and logs from the recorder modules, listeners, and server are sent out for monitoring. External systems like Prometheus and Grafana (supported via Docker-Compose configurations) retrieve, display, and alert on these metrics.
• Docker utilization: Dockerfiles, docker-compose.yml, and related scripts indicate containerization for the service and its dependencies (e.g., the Grafana dashboard and Prometheus).
Important Architectural Patterns and Technologies
• Modular Design: The clear separation in the file structure (live modules, listeners, recorders, web server, etc.) suggests a modular architecture that can be extended with additional streaming platforms.
• Separation of Concerns: Frontend (src/webapp) is distinct from the backend server (src/servers) and the business logic (other src subfolders).
• Event-driven Patterns: Listeners and event dispatchers (in src/pkg/events) indicate an event-driven mechanism guiding interactions between modules.
• Containerization and CI/CD: With Dockerfiles, docker-compose, GitHub workflows, Travis configuration, and Makefiles, the project is designed for automated builds, testing, and deployment.
• Dependency on External Tools: ffmpeg is the key external dependency for handling media streams.
Specific Elements
• Web Interface (React front end with components and API endpoints)
• Application Server (Golang backend handling HTTP requests and managing configuration)
• Live Recorder Engine that contains sub-components:
• Live Providers Modules (e.g., Bilibili, Douyu, etc.)
• Listener/Event Dispatcher Subsystem
• Recorder Component (integrating with ffmpeg)
• Utility/Support Components (Configuration, Metrics, Logging)
• Deployment & External Dependencies (Docker container environment, ffmpeg, Prometheus, Grafana)
• Data flow from the web UI to the backend server/API.
• Event/command flow from the recorder engine to the live providers.
• Interactions between components (e.g., configuration being read by the recorder and updated by the web UI).
• Communication with external tools (e.g., how recorded streams are processed by ffmpeg and metrics forwarded to Prometheus).
• Core business logic modules (engine, listeners, recorders)
• UI components (frontend webapp)
• External services and dependencies
Final Advice
• Modularity and separation of concerns so that new live platforms or enhancements in the web interface can be integrated into the system without major changes to the core architecture.