How nya-wsl/bili_rec_monitor works
Project type and purpose
• This is a Python-based background service (not a web frontend) whose job is to monitor Bilibili live streams, react to state‐change webhooks emitted by BililiveRecorder, send notifications via the WxPusher WeChat service, manage local recording files, and optionally upload them to Baidu Netdisk using an OpenAPI client.
File structure
• Entry point:
• bili_rec_monitor.py – the main service script
• Configuration:
• config.example.yml – holds all user‐tweakable settings (rooms, users, commands, Baidu credentials, WxPusher tokens)
• Auth & Upload:
• pcs_auth.py – Baidu Netdisk authentication helper
• pcs.py – wrapper around Baidu OpenAPI calls (file upload, move)
• openapi_client/… – auto-generated OpenAPI client code (models, API endpoints)
• Dependencies & Builds:
• requirements.txt / pyproject.toml – Python dependencies (watchdog optional, requests, pyyaml, etc.)
• External or auxiliary tools:
• Potential use of pm2 or systemd to daemonize / watch the process
Extract architecture hints from the README
• The service subscribes to webhooks from BililiveRecorder.
• Once an event arrives, it triggers zero or more of:
a) send “live start/end” and “recording start/end/write start/end” notifications to multiple WxPusher recipients
b) execute custom commands (user-defined hooks)
c) move recordings on the local filesystem
d) upload recordings to Baidu Netdisk (with authentication managed by pcs_auth + openapi_client)
• Supports multiple users and multiple rooms concurrently.
• BililiveRecorder (webhook emitter)
• WxPusher (WeChat Service API)
• Baidu Netdisk (OpenAPI REST endpoints)
1. HTTP Webhook Receiver – part of bili_rec_monitor.py
2. Event Dispatcher / Handler Registry – routes each event type
3. Notification Module – wraps HTTP calls to WxPusher using tokens from config
4. Command Executor – runs user‐configured shell commands
5. File Manager – moves/renames files on local disk
6. Upload Module – pcs_auth + pcs.py + openapi_client handles OAuth and file uploads
7. Configuration Loader – reads config.yml into memory at startup
• Local Environment
• File System – for temporary or final storage of recordings
• Logs – capture events, errors, HTTP requests
• BililiveRecorder → (HTTP POST) → Webhook Receiver
• Webhook Receiver → Event Dispatcher
• Dispatcher → Notification Module → WxPusher → WeChat users
• Dispatcher → Command Executor → Operating System
• Dispatcher → File Manager → Local FS
• Dispatcher → Upload Module → pcs_auth → OpenAPI Client → Baidu Netdisk
• Bi-directional auth/token flows between Upload Module and Baidu Netdisk
Architectural patterns & important principles
• Event‐driven: Each webhook is an event triggering multiple independent side-effects
• Modular: Separate concerns (notification vs. file operations vs. upload vs. commands)
• Configuration-driven: Behavior flexibly controlled via YAML
• External integration points: clearly separate external APIs into their own modules