Building on spotify-cli
Everything is open source: https://github.com/unlikefraction/spotify-cli. Reproduce a bug,
patch it, open a pull request, then spotify report '<what>' --pr <url>.
Layout
Use the library
Outcome::result says what an action did when it can do more than one thing (previous:
restarted or previous_item); Outcome::refocused says where the focus went back after an
AppleScript start brought Spotify.app forward; Outcome::note says when a start went to the
speaker or phone Spotify.app controls, or counted although the Web API's answer was lost (a 5xx
or no answer, and Spotify.app plays it). The rules the controller follows (every start through
the Web API first: songs, episodes, shows and Liked Songs directly, albums, playlists, artists
and radios through spotify_player; AppleScript first only for exact seeks; spotify_player's view
checked before commands that depend on it; refusals read from its log; restoring what a failed
start emptied) are in spotify docs playback.
web and focus are new in 0.1.6 (a Controller built for 0.1.5 needs them added).
web: Err(error) makes AppleScript start songs, episodes, shows and Liked Songs, as before, and
the controller then reports fallback: {from: "web_api", reason: error}; focus: None leaves
the focus where it lands. webapi::WebApi needs one method (send), so other HTTP
stacks can supply their own. The webapi module has the steps without the verification:
start (a track or episode: item lookup, device, PUT /me/player/play, position retry),
start_list (Liked Songs or a show), choose_device and target (where a start goes:
the active speaker or phone Spotify.app controls, else Spotify.app on this Mac), set_shuffle,
liked_songs, search, unanswered (a start whose effect is unknown) and cached_facts (what a
lookup found, without asking again). The library remembers, for the life of the process, the
album or show of each item it looked up (up to 500), and keeps one process-wide pause after a
Web API 429 (webapi::pause_left). Devices are listed at every start.
Try control code live, without the daemon:
It takes status, full, play [uri [context]], liked [random], pause, toggle, next,
previous, seek <time>, volume <0-100>, shuffle <on|off>, repeat <off|context|track>,
like, unlike, front (the frontmost app), handoff <uri> [context] (a bare AppleScript start
with the focus hand-back), lookup <uri> (the album or show a Web API start would use, the
release a relinked song plays from, its position),
webstate (a summary of the Web API's GET /me/player), devices (the Spotify Connect devices
and where a start would go now), websearch <query> (the Web API's search, as the daemon falls
back to it) and raw <GET|PUT> <path> [key=value…] [json body] (one Web API request, to see how
Spotify answers). Flags: --strategy auto|spotify_player|applescript, --no-web (the Web API's
playback commands, its PUTs, fail with web_api_disabled while lookups still answer, to try the
AppleScript fallback: a track then plays in its album), --no-refocus (no focus hand-back) and
--trace (method, path, status and time of each Web API request on stderr; never tokens). It
prints the outcome or error as JSON and the time it took on stderr, and it controls the real
Spotify.app.
The trigger engine is pure: feed trigger::Tracker::observe readings, pass the events to
trigger::evaluate, deliver the returned Firings however you like (Firing::data() is the Ting
payload, Firing::key() the idempotency key). trigger::validate_request checks a request's
note, label, times and percentage without any playback state, so run it before reading Spotify.
uri::SpotifyUri::parse accepts only ids of exactly 22 base62 characters (uri::ACCEPTED_FORMS
lists the forms), so malformed references fail as invalid_input before they reach Spotify.
player::parse_json reads spotify_player's JSON even when strings hold raw control characters,
and model::item_view turns its get item output for albums and artists into kind, item and
per-kind lists. spotify_player returns at most player::SEARCH_MAX_PER_KIND (10) search results
per kind.
Talk to the daemon
Newline-delimited JSON over ~/.silicon-spotify/daemon.sock, one request per connection:
Ops: daemon.status, daemon.shutdown, doctor, player.{status,play,pause,toggle,next,previous,seek,volume,shuffle,repeat,like},
spotify.{launch,auth.status,auth.login}, track.info, lyrics, search, library.get,
devices.{list,connect}, queue.{list,add,remove,move,clear}, playlist.{list,show,create,delete,add,remove,rename,import,fork,sync},
podcast.saved, trigger.{add,list,get,remove,clear,history,test,wait,retry}. Argument shapes: crates/cli/src/ops.rs (the
CLI is the reference client) and crates/daemon/src/*.rs. Unknown ops fail with unknown_op.
The socket accepts only the same OS user. Some fields a client may rely on:
queue.addtakes{"uris": […], "next": bool, "known": [{"uri", "name", "by", "duration_ms"}]};known(optional) holds facts the caller already has, such as the search hit it picked, so the daemon need not look them up; it looks up only the fieldsknownlacks (empty strings count as missing). Older daemons ignore it. The answer{"added", "queue"}may carrymetadata_pending(theq_…ids of added episodes whose facts the daemon still looks up in the background) andnote.track.infoaddsliked: true|falsefor songs when the Liked Songs check answers in 2.5 s.spotify.launchanswers{"launched", "already_running", "playback"}.player.nextmay carryskipped(a managed item whose hand-off was still in flight). Managed starts use the same controller asplayer.playand report its actualvia,playback,fallback,noteandrefocusedfields when present.queue.list'sspotify_upcomingmay carrycurrent_repeats_left_outandnote. Its top-levelwarnings(on every reply, empty unless something is worth knowing) holdsno_active_devicewhen Spotify reports nothing playing on any device and Spotify.app does not play either, so the upcoming list is empty for that reason.searchreplies carryvia(spotify_player, orweb_apiwhen spotify_player's search failed and the Web API's answered) and thenfallback: {from: "spotify_player", reason}. When both fail, the error is the Web API's with spotify_player's indetails.first_attempt.player.play's outcome may sayvia: "web_api"(a song, episode, show or Liked Songs started through the Web API) orfallback.from: "web_api", carriesnotewhen the start went to the speaker or phone Spotify.app controls or counted although the Web API's answer was lost, and carriesrefocused({app, via, hid_spotify, error}, the last two only when set) when an AppleScript start brought Spotify.app forward. The settings the CLI merges intoargsincludekeep_spotify_in_background(default true); older daemons ignore it.player.statuswith{"full": true}may setweb.relinked: true(the Web API plays Spotify.app's song under another id);player.likethen refuses with a non-retryabletrack_mismatchwhosedetailscarryrelinked: trueandmatched_by.
Build and release
The backend uses SPOTIFY_ACCOUNTS_URL, SPOTIFY_APP_ID, and SPOTIFY_APP_SECRET; keep its encryption key stable. See .env.example.
scripts/package-release.sh builds native clients and the Silicon Apps package. apps.yaml declares the binary and installation script for each target. macOS release binaries use Developer ID signing and Apple notarization. The operator steps are in deploy/README.md.
Conventions
- Library: stateless apart from the process-lifetime memory above (looked-up items, the Web API's rate-limit pause); never caches credentials, never updates behind the caller.
- Errors:
{code, message, hint, retryable, details}everywhere; add new codes todocs/errors.md. - Every playback command verifies its effect and reports
via/fallback. - Never write lyrics, titles, queries, notes or tokens to logs.
- Keep
crates/*versions equal; the CLI restarts an older daemon automatically.
Offline: spotify docs development · Source: docs/development.md