How amtoaer/bili-sync works
Main Components
• Core Application Logic (crates/bili_sync):
– Contains modules for handling authentication, API endpoints (handling REST requests), configuration parsing, and task execution.
– Submodules include adapters (for converting different content types like “collection,” “favorite,” “submission,” and “watch later”), bilibili client implementations (networking with Bilibili services, including authentication and video streaming selection), and downloader tasks.
• Data Model and Persistence (crates/bili_sync_entity):
– Holds entity definitions, representing the data structures (collections, favorites, videos, etc.) used across the system.
• Database Migration and Schema Management (crates/bili_sync_migration):
– Manages database migrations, ensuring that the schema stays in sync with the codebase.
• Async Task Scheduling and HTTP Server (inside src/task):
– Uses Tokio and Reqwest to concurrently download, refresh tokens, and handle HTTP requests (likely for control or monitoring).
• External Dependencies/Integrations:
– Integration with external tools like FFmpeg (for merging audio/video streams), and signaling/logging for error handling.
• Web UI and Documentation:
– The “web” directory contains build assets that might be used to provide a status or management UI, and the “docs” directory holds detailed documentation and design guides.
• User Interface / Web Client (the “web” folder, possibly serving a UI dashboard).
• API / HTTP Server (within the task and API submodules in the core “bili_sync” crate).
• Core Logic and Download Manager (including the downloader, bilibili client, workflow, and adapter modules).
• Configuration & Credential Management (configuration modules handling CLI parameters and persistent settings).
• Database and ORM Layer (linking the core application logic with the persistence layer – including migrations and entities).
• External Systems (Bilibili’s API endpoints, FFmpeg for postprocessing, and potentially logging/monitoring services).
• Data flows from the API/HTTP server to the core logic, which then interacts with external Bilibili services.
• The core logic reads configuration and credentials, initiates downloads, processes and merges streams via FFmpeg, and then updates the database.
• Additionally, there may be periodic/polling/retry loops, so indicate channels for error reporting and scheduling.
• External dependencies:
• Labels for technologies such as Rust, Tokio, Reqwest, and FFmpeg.
Architectural Patterns and Design Principles
• Separation of Concerns/Micro-crates:
• Each crate (bili_sync, bili_sync_entity, bili_sync_migration) is responsible for a specific domain: application logic, data model, and database migration, respectively.
• Asynchronous/Concurrent Execution:
• Adapter Pattern:
• The “adapter” submodules show transformation between different domains (e.g., converting raw API responses from Bilibili into internal data representations).
• Modular and Extensible Design:
• The clear separation into APIs, configuration, tasks, and utilities suggests the application is designed with modularity in mind, allowing for extension and easy maintenance.