feat: Add Apple Music integration#3
Conversation
- Add Apple Music client with authentication and token storage - Add CLI commands for Apple Music auth, search, and playback - Add project documentation (CLAUDE.md, AGENTS.md) - Add beads workflow configuration - Update existing CLI files for music service integration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Documents the Apple Music integration including authentication, search, playback commands, architecture, and troubleshooting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add GetTransportSettings and SetPlayMode to the Sonos client for controlling playback modes. Includes new CLI command `sonos mode` with options: get, shuffle, shuffle-norepeat, repeat, repeat-one, normal. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add references section with links to token extraction guides and official Apple documentation for MusicKit integration. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update mode command Use field to list all six modes - Add input validation for PlayMode values in SetPlayMode 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add support for searching and playing Apple Music content on Sonos speakers: - Search Apple Music catalog (songs, albums, playlists, artists) - Play Apple Music content directly on Sonos speakers - Authentication via browser-extracted tokens (~6 month lifespan) - Enqueue via Sonos SMAPI for seamless playback New commands: - `sonos auth applemusic login/status/logout` - Token management - `sonos search applemusic <query>` - Search Apple Music - `sonos play applemusic <query>` - Search and play on Sonos Requires Apple Music to be linked in the Sonos app. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use service 52231 for DIDL metadata descriptors (not 204) - Add proper item ID prefixes (10032020 for tracks, 1004206c for albums) - URL-encode colons in item IDs to match Sonos format This fixes queue display showing "Q:0/1" instead of track titles. The URI uses sid=204 for routing, but metadata needs service 52231. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use service 52231 for DIDL metadata descriptors (not 204) - Add proper item ID prefixes (10032020 for tracks, 1004206c for albums) - URL-encode colons in item IDs to match Sonos format This fixes queue display showing "Q:0/1" instead of track titles. The URI uses sid=204 for routing, but metadata needs service 52231. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Was looking for this support too, thanks! |
|
Tried to use this locally, but there are a few issues. 1. Tries to open Safari / Apple Music app, even though default browser is ChromeShould probably just show the link and suggest to open it manually in the browser, because probably the system treats is as a deeplink otherwise.
2. Instructions are outdatedOutdated:
Correct:
3. User token doesn't necessarily start with
|
|
I’m going to close this an open a new one soon. I had to make more changes
to the cli.
…On Fri, Feb 27, 2026 at 6:26 AM cezarderevlean ***@***.***> wrote:
*cezarderevlean* left a comment (steipete/sonoscli#3)
<#3 (comment)>
Tried to use this locally, but there are a few issues.
1. Tries to open Safari / Apple Music app, even though default browser is
Chrome
Should probably just show the link and suggest to open it manually in the
browser, because probably the system treats is as a deeplink otherwise.
Opening Apple Music in your browser...
2. Instructions are outdated
Outdated:
To extract your Apple Music token:
1. Sign in to Apple Music at https://music.apple.com
2. Open browser Developer Tools (F12 or Cmd+Option+I)
3. Go to the "Application" tab (Chrome) or "Storage" tab (Firefox)
4. Find "Local Storage" → "https://music.apple.com"
5. Look for a key containing "music.user.token" or similar
6. Copy the token value
Alternatively, in the Console tab, run:
localStorage.getItem('music.ampwebplay.media-user-token')
Correct:
After signing in, run in browser console:
MusicKit.getInstance().developerToken
MusicKit.getInstance().musicUserToken
Paste developer token (JWT, starts with eyJ...):
Paste user token (starts with Av...):
3. User token doesn't necessarily start with Av (mine seems to start with
As)
The token is a long string starting with something like "Aw..." or similar.
Paste user token (starts with Av...):
4. Date when token expires is wrong:
Apple Music tokens saved successfully!
Token expires around: 0001-01-01T00:00:00Z
5. After successfully authenticating (allegedly), I get an error. Maybe
Apple restricted the API?
╰─❯ sonos search applemusic paparoutai
Error: apple music search failed: apple music api error: API capacity exceeded (status 429)
Ran a security check with MiniMax M2.5 @ OpenCode:
Security Review: No Issues Found
Your implementation is safe. Here's what I verified:
1. Tokens only go to Apple - The client sends tokens only to
https://amp-api.music.apple.com (Apple's official API). No third-party
servers.
2. Local storage only - Tokens are stored at
~/.config/sonoscli/applemusic_token.json with secure permissions (600/700).
3. No logging/telemetry - No token logging, no external analytics, no
unexpected network calls.
4. Minimal dependencies - Just cobra CLI framework + stdlib net/http.
The flow is:
- Browser opens to music.apple.com (Apple's site)
- You extract tokens from your browser's localStorage
- You paste them into the CLI
- CLI uses them only for API calls directly to Apple
You're not at risk. This is a standard pattern for personal CLI tools
that want to use Apple Music's web API without going through Apple's
official MusicKit SDK (which requires app registration).
—
Reply to this email directly, view it on GitHub
<#3 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA5WHV6KHLHSLSC57AUSB734OBHXXAVCNFSM6AAAAACQ72EZCSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSNZTGIZTKMRRG4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Summary
New Commands
sonos auth applemusic login/status/logout- Token managementsonos search applemusic <query>- Search Apple Music catalogsonos play applemusic <query>- Search and play on SonosFiles Added
internal/applemusic/internal/cli/auth_applemusic.gointernal/cli/search_applemusic.gointernal/cli/play_applemusic.gointernal/sonos/applemusic.godocs/applemusic.mdAuthentication
Tokens are extracted from the Apple Music web player:
MusicKit.getInstance().developerTokenandMusicKit.getInstance().musicUserTokensonos auth applemusic loginPrerequisites
🤖 Generated with Claude Code