$ show spotiflacapp/SpotiFLAC-Mobile
SpotiFLAC-Mobile is a cross-platform mobile application (Android and iOS) that enables users to download and play high-fidelity music in lossless formats such as FLAC and DSD. It operates through an extension-based architecture where community-provided plugins supply download sources, metadata, lyrics, and cover art. The application integrates with streaming services like Deezer, Tidal, Qobuz, and Spotify via these extensions, handling authentication, rate limiting, and content resolution. The system is built on a multi-language stack: a core Rust backend handles audio processing, metadata tagging, library management, and network communication; a Flutter (Dart) frontend provides the user interface; and platform-specific code in Kotlin (Android) and Swift (iOS) bridges native features like file system access, USB audio output, and system audio routing. The Rust backend is exposed to mobile languages via UniFFI-generated bindings. Key data flows include: extension-based download orchestration with cancellation and progress reporting, audio file finalization (metadata embedding, ReplayGain scanning, cover art insertion), incremental library scanning with SQLite persistence, and multi-provider lyrics fetching with caching. The application also features hi-res audio authenticity verification using STFT analysis, direct USB audio output for bit-perfect playback, and a comprehensive extension management system with sandboxed JavaScript runtimes. External dependencies include FFmpeg for audio conversion, libusb for USB audio transport, and various web APIs (Deezer, MusicBrainz, LRCLib, Apple Music, etc.) for metadata and lyrics enrichment. The project demonstrates strong engineering practices with extensive unit and integration tests, a modular crate architecture, and reusable patterns for cancellation, progress tracking, and caching.
The LLM identified 5 files worth highlighting for reuse:
Implements a cooperative cancellation pattern using CancellationRegistry and RequestLease. Allows multiple concurrent operations to share a cancellation scope, with pre-cancel sentinels, lease tracking, and batch cancel/reset. The pattern is thread-safe and designed for cross-FFI use, making it reusable in any async system that needs coordinated cancellation.
Provides a thread-safe progress registry where workers report progress via snapshots and subscribers receive delta updates. Uses coalescing (250ms/64KB thresholds) to reduce UI updates. The subscription model allows multiple listeners and batch removal. This pattern is reusable for any long-running operation that needs progress reporting to a UI or monitoring system.
A standalone utility class for converting PCM audio between different bit depths and formats (packed 24-bit, float-to-integer, bit-depth padding). Designed for bit-perfect playback, it handles endianness and sample alignment. The class has no external dependencies beyond standard Kotlin, making it easily extractable for any audio processing project.
Implements a content-addressable cache for cover art with TTL-based expiry, byte budget enforcement, and flight coalescing to deduplicate concurrent downloads for the same URL. Uses atomic file writes and a SQLite index for persistence. The caching pattern (TTL + flight + budget) is reusable for any resource that is fetched from a network and cached locally.
Orchestrates lyrics fetching from multiple providers (LRCLib, Apple Music, Netease, etc.) with priority ordering, negative caching, flight deduplication, and concurrency limits. Handles provider failures gracefully and caches results with TTL. The multi-provider pattern with fallback and caching is reusable for any data aggregation service.