$ show darknessomi/musicbox
NetEase-MusicBox is a Python 3.10+ terminal client for NetEase Cloud Music (music.163.com), sold as the `musicbox` command. It is a hybrid application: an interactive curses TUI, an agent-facing stateless CLI, and a resident background daemon (`musicboxd`) that owns playback state. The TUI and daemon are mutually exclusive via a flock single-owner lock; control commands reach the daemon over a 0600-permission Unix domain socket using newline-delimited JSON-RPC. Audio plays through subprocess backends (mpg123 for MP3, mpv for FLAC/hi-res with IPC seek/volume control), and all NetEase API access goes through reverse-engineered weapi/eapi encryption (RSA+AES and AES-ECB with PKCS7/gzip handling). Login is QR-code scan only; session cookies and player state persist to XDG-compliant JSON/text files.
The LLM identified 4 files worth highlighting for reuse:
Self-contained implementation of NetEase's weapi (RSA-encrypted AES key + AES-CBC params) and eapi (AES-ECB with MD5-derived message digest, hex-encoded, gzip-decompressed responses) wire protocols. Purely standard-library + pycryptodomex, with every scheme annotated against upstream api-enhanced reference code. Any project needing to talk to NetEase Cloud Music endpoints can extract this file unchanged; it also demonstrates a clean modern AES-ECB usage pattern with PKCS7 padding and gzip magic-byte sniffing.
CJK-aware display-width utilities for fixed-width terminal UIs: `truelen` computes display columns (CJK chars count as 2), `truelen_cut` truncates without splitting a multi-byte char, and `scrollstring` implements time-based marquee scrolling that advances by display columns instead of Python characters. Zero internal imports — trivially extractable — and it solves a real recurring problem in any TUI that renders mixed CJK/Latin text.
A generator/coroutine-based keyboard event stream parser. The `coroutine` decorator primes generators, `_cmd_parser` accumulates keystrokes until a command-terminating key, and the `cmd_parser` manager transparently swallows StopIteration and restarts the inner generator — a clean, non-obvious pattern for incremental input parsing in curses apps, including multi-key chords (`234j` → jump 234). The only internal import is one Config lookup for key mappings; the generator machinery itself is fully general and extractable for any event-driven terminal front-end.
A resident-background-service pattern for CLI tools: flock-based single-owner lock (fd kept open for process lifetime, making daemon and TUI mutually exclusive), double-fork daemonization with setsid and stdio detach, 0600-permission Unix-domain socket, and newline-delimited JSON-RPC with structured error types. The `acquire_lock`/`release_lock`/`send_request`/`spawn_daemon`/`stop_daemon` primitives are the reusable skeleton — an engineer could lift them into any CLI needing a stateful background process, though the RPC handler layer is app-specific.