$ show fiso64/sockseek
Sockseek is a command-line music downloader for the Soulseek peer-to-peer network, written in C# (.NET). It searches the Soulseek network for songs and albums, ranks candidates using a sophisticated multi-level sorting algorithm (bitrate, format, user reputation, etc.), and downloads the best match. The application supports multiple input sources: free-text search strings, Spotify/YouTube/Bandcamp/MusicBrainz URLs, CSV files, Soulseek links, and list files. It can run as a one-shot CLI tool or as a persistent daemon with an HTTP API and SignalR real-time event hub for remote control and live progress monitoring. Architecturally, the codebase is modular with four main projects: `Sockseek.Core` (core domain logic, search, download orchestration, extractors, file management), `Sockseek.Cli` (CLI entry point, interactive mode, progress rendering), `Sockseek.Server` (ASP.NET Core daemon with SignalR, event coalescing, state store), and `Sockseek.Api` (DTOs, JSON serialization context, client library). The system uses an event-driven architecture for decoupled progress reporting and state management. Extensive unit and integration tests (over 50 test files) and performance benchmarks (BenchmarkDotNet) ensure reliability and performance. Key features include incremental search result projection (album folders, aggregate tracks), a flexible profile system with condition-based auto-profiles, file condition evaluation (bitrate, sample rate, strict title/artist/album matching), fallback downloads via yt-dlp, stale download detection, and post-download command execution with variable substitution. The daemon exposes a full REST API and OpenAPI specification, enabling remote CLI clients and potential third-party integrations.
The LLM identified 6 files worth highlighting for reuse:
A reusable rate limiter that wraps a semaphore with a configurable reset window. Allows N concurrent operations per time period, automatically resetting after the window expires. Used to throttle Soulseek search requests to avoid being banned. Demonstrates clean separation of timing and concurrency concerns, and can be extracted for any rate-limited resource access.
Implements an incremental projection pattern for album folder search results. Maintains an internal cache of previously processed raw results and only reprocesses new or changed entries, avoiding full recomputation on each update. This is critical for real-time search result display as new peers respond. The pattern is generic and could be adapted to any streaming aggregation scenario.
Contains the core sorting logic for ranking search results. Uses a custom `BoolSortKey` that packs multiple boolean flags (strict title, artist, album match, format, bitrate, sample rate, etc.) into a single `uint` for fast descending comparison. This avoids expensive per-field comparisons and enables deterministic ordering. The bit-packing technique is a non-obvious optimization for multi-criteria ranking and is reusable in any domain requiring composable boolean-based sorting.
Defines a structured patch DTO for applying partial updates to download settings. Uses sentinel values and nullable fields to represent 'no change', enabling the remote CLI to send only the delta of settings that differ from the server's current configuration. This pattern reduces network payload and avoids full settings resync. The `ApplyTo` method merges patches into existing settings objects. Reusable for any client-server settings synchronization.
A comprehensive mock implementation of the Soulseek client interface for unit testing. Supports configurable search responses, file indexes, download delays, and failure injection. Enables offline testing of the entire download pipeline without connecting to the real P2P network. Demonstrates a well-structured test double pattern with builder methods for realistic test scenarios. Can be adapted to mock any external service in .NET testing.
Parses and executes post-download shell commands with structured options (scope=track/album, when=success/failure/skipped, hidden, lock, update-index). Supports variable substitution (e.g., `{file}`, `{artist}`, `{album}`) and legacy syntax detection. The command string format is well-documented and parsed without external dependencies. This pattern is reusable for any system that needs to run configurable post-processing actions with scoping and conditional execution.