Apple Music DJ 🎧
An intelligent Apple Music personalization engine for OpenClaw. Reads your listening history,
Replay stats, ratings, and library to build a deep taste profile — then generates playlists
using five strategies, surfaces insights about your listening, and writes everything directly
to your Apple Music library. Also includes shareable Taste DNA Cards, compatibility scoring,
catalog gap analysis, album deep dives, artist rabbit holes, daily song drops, concert prep
playlists, and personalized new release radar.
Architecture
CODEBLOCK0
Prerequisites
Two environment variables must be set. If the user doesn't have them, walk them through
references/auth-setup.md before doing anything else.
| Variable | Purpose |
|---|
| INLINECODE1 | JWT signed with MusicKit private key (Apple Developer portal) |
| INLINECODE2 |
Per-user authorization token (obtained via MusicKit JS
authorize()) |
Verify with: INLINECODE4
Taste Profiling
Before generating any playlist, build (or load from cache) a taste profile.
Run: INLINECODE5
Use --max-age 0 to force a refresh, bypassing any cached profile.
The profiler pulls from all available data sources:
| Source | Endpoint | Signal |
|---|
| Loved/disliked songs | INLINECODE7 | ★★★★★ Explicit intent |
| Heavy rotation |
GET /v1/me/history/heavy-rotation | ★★★★☆ Repeated engagement |
| Recently played |
GET /v1/me/recent/played/tracks | ★★★★☆ Current mood |
| Replay summaries |
GET /v1/me/music-summaries | ★★★★☆ Annual deep data |
| Library songs |
GET /v1/me/library/songs?include=catalog | ★★★☆☆ Broad taste |
| Library artists |
GET /v1/me/library/artists | ★★★☆☆ Artist affinity |
| Recommendations |
GET /v1/me/recommendations | ★★☆☆☆ Apple's inference |
Output: Taste DNA profile cached at ~/.apple-music-dj/taste_profile.json (7-day TTL by default).
The profile includes: top artists (weighted), genre distribution, era profile, energy
classification, variety score, loved/disliked IDs, library song IDs, and Replay highlights.
Sparse Data Handling
If the user has limited history:
- 1. Check Replay data — covers a full year even if recent history is short
- Lean on INLINECODE15
- Ask user to name 3–5 artists/songs they love as manual seeds
- Use catalog search with those seeds to bootstrap
Playlist Strategies
Five strategies. Read detailed algorithms in references/playlist-strategies.md.
Strategy 1: Deep Cuts Explorer
Triggers: "deep cuts", "hidden gems", "B-sides", "underrated", "album tracks"
Find tracks from artists the user loves but hasn't heard yet. Excludes top songs, singles,
and anything in library.
Strategy 2: Mood / Activity Matcher
Triggers: "workout", "chill", "focus", "party", "sleep", "cooking", "driving",
"running", "morning", "sad", "study", "dinner" — any mood/activity word.
Maps mood to musical attributes, filters through user's taste.
Strategy 3: Trend Radar
Triggers: "trending", "what's hot", "charts", "popular", "new releases"
Current charts filtered through user's genre preferences. Includes wildcard picks.
Strategy 4: Constellation Discovery
Triggers: "surprise me", "something new", "expand my taste", "I'm bored", "discovery"
Journey from familiar artists outward to new territory in 3 "rings" of distance.
Strategy 5: Playlist Refresh / Evolution
Triggers: "refresh my [playlist]", "update my [playlist]", "evolve", "getting stale"
Analyzes existing playlist's sonic signature, adds fresh matching tracks, optionally
prunes overplayed songs.
Engagement Features
Beyond playlist strategies, these features drive daily engagement and deeper music discovery.
Taste DNA Card
Triggers: "taste card", "taste DNA", "share my taste", "my music identity", "listener profile"
Generate a shareable visual card (SVG or text) summarizing the user's taste: archetype label
(e.g., "Deep Catalog Digger", "Genre Drifter"), top genres with bars, top artists, era mix,
and stats (energy, variety, mainstream, velocity).
Run: INLINECODE17
Archetype detection is automatic based on profile data. Always present the text version
in chat; offer to generate the SVG for sharing. The card is designed to be screenshot-friendly.
Compatibility Score
Triggers: "how compatible am I with [artist]", "compatibility", "do I match [artist]",
"compare my taste with", "would I like [artist]"
Score how well the user's taste aligns with an artist's catalog DNA (0-100%).
Also supports comparing two user profiles if both have run the taste profiler.
Run:
- - INLINECODE18
- INLINECODE19
Present the percentage, a verdict ("Deeply compatible", "Strong overlap", "Wild card"),
matching genres, and whether the artist is already in their library.
Listening Insights
Triggers: "listening timeline", "how has my taste changed", "listening streaks",
"milestones", "year in review", "my [year] in music", "wrapped", "listening stats"
Three subcommands:
Timeline: python3 scripts/listening_insights.py timeline <profile.json>
Shows taste evolution across Replay years — top artist, genre, and listen time per year.
Present as a narrative: "In 2022 you were deep into shoegaze, by 2024 you shifted to jazz."
Streaks: python3 scripts/listening_insights.py streaks <profile.json>
Surfaces milestones (from Replay API) and computed insights: artist loyalty, genre dominance,
discovery rate, library size, rating activity.
Year in Review: python3 scripts/listening_insights.py year-review <profile.json> [--year 2025]
Comprehensive year analysis — deeper than Apple Replay. Includes obscurity score, variety
analysis, top songs/artists/albums, total listen time, and narrative insights.
Catalog Gap Analysis
Triggers: "what have I missed", "what am I missing from [artist]", "catalog gaps",
"albums I haven't heard", "discography check"
Scans the user's favorite artists' full discographies and identifies albums with zero tracks
in the user's library. Ranks recommendations by release date.
Run: INLINECODE23
Present as: "You love Radiohead but you've only heard 3 of their 9 albums. Here's what
you're missing, ranked by how much you'd probably like each one."
Album Deep Dive
Triggers: "tell me about [album]", "album deep dive", "what's on [album]",
"should I listen to [album]", "break down [album]"
Pull track listing, classify each track as single vs deep cut, show where the album sits
in the artist's discography, and recommend which deep cuts to try first.
Run: INLINECODE24
Artist Rabbit Hole
Triggers: "rabbit hole from [artist]", "take me on a journey from [artist]",
"artist chain", "explore from [artist]", "where does [artist] lead"
Interactive chain exploration. Starts from one artist, searches for adjacent artists,
maps outward step by step. Each step tagged as familiar/adjacent/frontier zone.
Outputs tracks from each artist for a potential journey playlist.
Run: INLINECODE25
Present each step with the artist name, zone, genres, and sample tracks. Ask if the user
wants to go deeper or turn the exploration into a playlist.
Daily Song Drop
Triggers: "daily song", "song of the day", "give me one track", "daily pick"
One track per day with a one-sentence rationale. Uses a date-based seed for consistency
(same pick all day). Draws from deep cuts and trending tracks scored against the user's taste.
Run: INLINECODE26
What Should I Listen To Right Now?
Triggers: "what should I listen to", "what should I play", "recommend something now",
"I need music", "play something"
Context-aware instant recommendation. Factors in time of day (morning → gentle indie,
late night → ambient), maps to genre boosts, and scores candidates accordingly.
Run: INLINECODE27
Concert Prep Playlist
Triggers: "seeing [artist] live", "concert prep", "going to [artist] show",
"setlist for [artist]", "get ready for [artist] concert"
Builds a prep playlist: top songs (likely setlist material) + deep cuts to learn before
the show. Creates directly in Apple Music library.
Run: INLINECODE28
Personalized New Release Radar
Triggers: "new releases", "what's new from my artists", "any new music",
"release radar", "new albums this week"
Scans the user's top 20 artists for releases in the last 7 days, plus searches for
genre-relevant new releases from adjacent artists. Can optionally create a playlist.
Run: INLINECODE29
Quick Commands
| User says | Action |
|---|
| "Analyze my taste" | Run taste profiler, present Taste DNA report |
| "Show my taste card" |
Generate and display Taste DNA Card |
| "Make me a playlist" | Ask what kind, then select strategy |
| "Surprise me" | Constellation Discovery — no questions asked |
| "More like [artist]" | Deep Cuts + Constellation hybrid seeded from named artist |
| "Refresh my workout playlist" | Strategy 5 on the named playlist |
| "What have I been into?" | Present recent listening summary |
| "How compatible am I with [artist]?" | Run compatibility score |
| "What have I missed from [artist]?" | Catalog gap analysis |
| "Tell me about [album]" | Album deep dive |
| "Take me on a rabbit hole from [artist]" | Artist chain exploration |
| "Give me one song" | Daily song drop |
| "What should I listen to right now?" | Context-aware instant pick |
| "I'm seeing [artist] next week" | Concert prep playlist |
| "Any new releases for me?" | Personalized new release scan |
| "My year in review" | Year in review (previous year) |
| "Set up weekly playlists" | Configure cron (see below) |
Cron / Automated Playlists
OpenClaw has first-class cron and heartbeat support. This skill can automate:
Weekly Mix (recommended default):
CODEBLOCK1
New Release Watch:
CODEBLOCK2
Daily Song Drop:
CODEBLOCK3
Playlist Health Check:
CODEBLOCK4
When the user asks to set up automation, configure via OpenClaw's cron system and
confirm the schedule with them before activating.
Assembly Rules
After any strategy produces candidate tracks, apply before creating:
Sequencing:
- 1. Tracks 1–3: Open strong (high-confidence picks)
- Tracks 4–8: Build energy, introduce variety
- Tracks 9–15: Peak — best discoveries here
- Tracks 16–22: Sustain interest, new textures
- Tracks 23–28: Wind down
- Final track: Memorable closer, not filler
Hard rules:
- - Min 5 tracks between same-artist repeats
- Max 2 tracks from same album
- No tracks from disliked artists
- No explicit content unless user's library already has it
- All IDs must be catalog IDs (not library IDs)
- Target: 25–40 tracks unless user specifies otherwise
Naming: INLINECODE30
Storefront Detection
Catalog endpoints need a storefront code (us, gb, jp...).
Detection order:
- 1.
APPLE_MUSIC_STOREFRONT env var → use it - INLINECODE32 → auto-detect and cache
- Fall back to
us, warn user
Error Handling
| Code | Meaning | Action |
|---|
| 401 | Dev token invalid/expired | Regenerate JWT. See INLINECODE34 |
| 403 |
User token expired (~6mo) | Re-authorize via browser. No refresh flow exists |
| 404 | Resource removed from catalog | Skip, log warning, continue |
| 429 | Rate limited | Exponential backoff: 1s→2s→4s→8s, max 3 retries |
| Empty data | New user or privacy settings | Fall back: Replay → recs → manual seeds |
Presenting Results
After creating a playlist:
- 1. ✅ Confirmation with playlist name
- Brief explanation connecting the curation to their taste
- Track listing (# · Song · Artist)
- Offer refinement: "Want me to adjust the energy, swap tracks, or make it longer?"
Tone: Music-savvy friend. Be specific about why tracks were chosen.
Say "I noticed you've been deep into shoegaze lately, so I pulled Slowdive deep cuts and
some bands in that orbit" — not "Here's an awesome playlist just for you!"
Reference Files
| File | Read when... |
|---|
| INLINECODE35 | User needs token setup help |
| INLINECODE36 |
Need endpoint details, formats, genre IDs |
|
references/playlist-strategies.md | Before executing any playlist strategy |
|
references/troubleshooting.md | User hits errors, things aren't working |
Privacy & Data Disclosure
This skill accesses user data through the Apple Music API. Here's exactly what it reads,
stores, and transmits.
Data read (via Apple Music API):
| Data | Endpoint | Purpose |
|---|
| Recently played tracks | INLINECODE39 | Current taste signal |
| Heavy rotation |
/v1/me/history/heavy-rotation | Repeated listening signal |
| Library songs & artists |
/v1/me/library/songs,
/artists | Broad taste mapping |
| Ratings (loved/disliked) |
/v1/me/ratings/songs | Explicit preferences |
| Recommendations |
/v1/me/recommendations | Apple's inference data |
| Replay summaries |
/v1/me/music-summaries | Annual listening stats |
| Storefront |
/v1/me/storefront | Region detection |
Data stored locally:
| File | Contents | Location |
|---|
| Taste profile cache | Aggregated taste data (JSON) | INLINECODE47 |
| Taste DNA Card |
Generated SVG image | User-specified output path |
Data NOT collected:
- - No data is sent to any third-party service
- No analytics or telemetry
- No data leaves the user's machine (all API calls go directly to Apple)
- Tokens are never logged or stored by the skill (env vars only)
Cache management:
- - Taste profile cache has a 7-day TTL by default
- Cache can be cleared: INLINECODE48
- Use
--max-age 0 to bypass cache and fetch fresh data
Scripts
| Script | Lang | Purpose |
|---|
| INLINECODE50 | Python | Shared utilities (API calls, profile loading, search) |
| INLINECODE51 |
Bash | API wrapper — all endpoints, retry logic |
|
scripts/taste_profiler.py | Python | Taste DNA profiler with caching |
|
scripts/build_playlist.sh | Bash | Playlist creation & refresh (create or add tracks) |
|
scripts/generate_dev_token.py | Python | Developer JWT generator |
|
scripts/taste_card.py | Python | Shareable Taste DNA Card (SVG/text) |
|
scripts/compatibility.py | Python | Taste compatibility scoring (artist or profile) |
|
scripts/listening_insights.py | Python | Timeline, streaks, milestones, year in review |
|
scripts/catalog_explorer.py | Python | Gap analysis, album deep dive, artist rabbit hole |
|
scripts/daily_pick.py | Python | Daily song drop & instant recommendation |
|
scripts/playlist_history.py | Python | Playlist creation history tracking |
|
scripts/concert_prep.sh | Bash | Concert prep playlist builder |
|
scripts/new_releases.sh | Bash | Personalized new release radar |
|
scripts/verify_setup.sh | Bash | Setup verification (prereqs, tokens, API) |
Example Interactions
"I've been in a funk, make me something uplifting"
→ Strategy 2 (Mood). Target: uplifting energy from their preferred genres.
"I keep listening to the same 20 songs"
→ Strategy 4 (Constellation). Start from heavy rotation, expand outward.
"Make me a running playlist"
→ Strategy 2 (Activity). 140–180 BPM feel, high energy, filtered through taste.
"What's trending that I'd actually like?"
→ Strategy 3 (Trend Radar). Charts filtered through taste fingerprint + wildcards.
"I love Radiohead and Björk but I've heard everything"
→ Strategy 1 (Deep Cuts) + Strategy 4 (Constellation) combined.
"My gym playlist is getting stale"
→ Strategy 5 (Refresh). Analyze vibe, add fresh tracks, prune overplayed ones.
"Set me up with weekly auto-playlists"
→ Cron config. Confirm schedule, set up weekly Trend Radar + Constellation mix.
"Show me my taste card"
→ Generate Taste DNA Card. Present text version in chat, offer SVG export.
"How compatible am I with Tyler, the Creator?"
→ Compatibility score. Show percentage, verdict, matching genres.
"What albums am I missing from Radiohead?"
→ Catalog gap analysis. List unheard albums, recommend starting points.
"Tell me about In Rainbows"
→ Album deep dive. Track listing, deep cuts vs singles, discography context.
"Take me on a rabbit hole from Radiohead"
→ Artist chain: Radiohead → Talk Talk → Bark Psychosis → Disco Inferno. Offer playlist.
"Give me one song for today"
→ Daily song drop. One track, one reason, done.
"What should I listen to right now?"
→ Context-aware pick. Time of day + taste → instant recommendation.
"I'm seeing Phoebe Bridgers next month"
→ Concert prep playlist. Top songs + deep cuts, created in Apple Music.
"Any new releases from my artists?"
→ New release radar. Scan top artists + genre discoveries, report findings.
"How was my 2025 in music?"
→ Year in review. Listen time, top artists, obscurity score, narrative insights.
Apple Music DJ 🎧
为OpenClaw打造的智能Apple Music个性化引擎。读取您的收听历史、Replay统计数据、评分和资料库,构建深度品味画像——然后通过五种策略生成播放列表,呈现您的收听洞察,并将所有内容直接写入您的Apple Music资料库。还包括可分享的品味DNA卡片、兼容性评分、曲库缺口分析、专辑深度探索、艺术家兔子洞、每日歌曲推荐、演唱会准备播放列表和个性化新发行雷达。
架构
用户请求
│
▼
┌─────────────┐ ┌──────────────────────────────────────────────┐
│ 品味 │◄──│ Apple Music API(读取) │
│ 画像器 │ │ · 最近播放 · 资料库歌曲/艺术家 │
│ (缓存) │ │ · 高频播放 · 评分(喜爱/不喜欢) │
│ │ │ · 推荐 · Replay摘要 │
└──────┬───────┘ └──────────────────────────────────────────────┘
│
▼
┌─────────────┐ ┌──────────────────────────────────────────────┐
│ 策略 │───▶│ Apple Music API(曲库) │
│ 引擎 │ │ · 搜索 · 排行榜 · 艺术家专辑/热门歌曲 │
│ │ │ · 流派 · 新发行 │
└──────┬───────┘ └──────────────────────────────────────────────┘
│
▼
┌─────────────┐ ┌──────────────────────────────────────────────┐
│ 播放列表 │───▶│ Apple Music API(写入) │
│ 构建器 │ │ · POST /me/library/playlists │
│ │ │ · POST /me/library/playlists/{id}/tracks │
└─────────────┘ └──────────────────────────────────────────────┘
前提条件
必须设置两个环境变量。如果用户没有设置,在进行任何其他操作之前,引导他们阅读references/auth-setup.md。
| 变量 | 用途 |
|---|
| APPLEMUSICDEVTOKEN | 使用MusicKit私钥签名的JWT(Apple开发者门户) |
| APPLEMUSICUSERTOKEN |
每个用户的授权令牌(通过MusicKit JS authorize()获取) |
通过以下命令验证:scripts/applemusicapi.sh verify
品味画像
在生成任何播放列表之前,构建(或从缓存加载)品味画像。
运行:python3 scripts/tasteprofiler.py [--cache ~/.apple-music-dj/tasteprofile.json] [--max-age 0] [--storefront us]
使用--max-age 0强制刷新,绕过任何缓存的画像。
画像器从所有可用数据源获取数据:
| 数据源 | 端点 | 信号强度 |
|---|
| 喜爱/不喜欢的歌曲 | GET /v1/me/ratings/songs | ★★★★★ 明确意图 |
| 高频播放 |
GET /v1/me/history/heavy-rotation | ★★★★☆ 重复参与 |
| 最近播放 | GET /v1/me/recent/played/tracks | ★★★★☆ 当前心情 |
| Replay摘要 | GET /v1/me/music-summaries | ★★★★☆ 年度深度数据 |
| 资料库歌曲 | GET /v1/me/library/songs?include=catalog | ★★★☆☆ 广泛品味 |
| 资料库艺术家 | GET /v1/me/library/artists | ★★★☆☆ 艺术家亲和度 |
| 推荐 | GET /v1/me/recommendations | ★★☆☆☆ Apple的推断 |
输出: 品味DNA画像缓存于~/.apple-music-dj/taste_profile.json(默认7天TTL)。
画像包括:热门艺术家(加权)、流派分布、年代画像、能量分类、多样性评分、喜爱/不喜欢ID、资料库歌曲ID和Replay亮点。
稀疏数据处理
如果用户历史记录有限:
- 1. 检查Replay数据——即使近期历史较短,也覆盖一整年
- 依赖/me/recommendations
- 要求用户提供3-5个他们喜爱的艺术家/歌曲作为手动种子
- 使用这些种子通过曲库搜索进行引导
播放列表策略
五种策略。详细算法请阅读references/playlist-strategies.md。
策略1:深度曲目探索者
触发词: 深度曲目、隐藏宝藏、B面曲、被低估、专辑曲目
从用户喜爱但尚未听过的艺术家中寻找曲目。排除热门歌曲、单曲和资料库中已有的任何内容。
策略2:心情/活动匹配器
触发词: 锻炼、放松、专注、派对、睡眠、烹饪、驾驶、跑步、早晨、悲伤、学习、晚餐——任何心情/活动词汇。
将心情映射到音乐属性,通过用户品味进行过滤。
策略3:趋势雷达
触发词: 趋势、热门、排行榜、流行、新发行
当前排行榜通过用户流派偏好进行过滤。包括随机选择。
策略4:星座发现
触发词: 给我惊喜、新东西、拓展品味、我无聊了、发现
从熟悉的艺术家出发,向外探索新领域,分为3个距离环。
策略5:播放列表刷新/进化
触发词: 刷新我的[播放列表]、更新我的[播放列表]、进化、变旧了
分析现有播放列表的声音特征,添加新的匹配曲目,可选择修剪播放过多的歌曲。
互动功能
除了播放列表策略,这些功能推动日常互动和更深层次的音乐发现。
品味DNA卡片
触发词: 品味卡片、品味DNA、分享我的品味、我的音乐身份、听众画像
生成可分享的视觉卡片(SVG或文本),总结用户的品味:原型标签(例如深度曲库挖掘者、流派漂流者)、带条形图的热门流派、热门艺术家、年代混合和统计数据(能量、多样性、主流性、变化速度)。
运行:python3 scripts/taste_card.py [--format svg|text] [--output card.svg]
原型检测基于画像数据自动完成。始终在聊天中呈现文本版本;提供生成SVG用于分享的选项。卡片设计为适合截图。
兼容性评分
触发词: 我和[艺术家]的兼容性如何、兼容性、我匹配[艺术家]吗、比较我的品味和、我会喜欢[艺术家]吗
评分用户品味与艺术家曲库DNA的匹配程度(0-100%)。
如果两个用户都运行了品味画像器,也支持比较两个用户画像。
运行:
- - python3 scripts/compatibility.py artist
- python3 scripts/compatibility.py profile
呈现百分比、结论(深度兼容、高度重叠、意外之选)、匹配的流派,以及该艺术家是否已在他们的资料库中。
收听洞察
触发词: 收听时间线、我的品味如何变化、收听连续记录、里程碑、年度回顾、我的[年份]音乐、年度总结、收听统计
三个子命令:
时间线: python3 scripts/listening_insights.py timeline
展示跨Replay年份的品味演变——每年热门艺术家、流派和收听时间。以叙述方式呈现:2022年你深陷盯鞋摇滚,到2024年你转向了爵士。
连续记录: python3 scripts/listening_insights.py streaks
呈现里程碑(来自Replay API)和计算出的洞察:艺术家忠诚度、流派主导性、发现率、资料库大小、评分活动。
年度回顾: python3 scripts/listening_insights.py year-review [--year 2025]
全面的年度分析——比Apple Replay更深入。包括冷门度评分、多样性分析、热门歌曲/艺术家/专辑、总收听时间和叙述性洞察。
曲库缺口分析
触发词: 我错过了什么、我错过了[艺术家]的什么、曲库缺口、我没听过的专辑、作品目录检查
扫描用户喜爱艺术家的完整作品目录,识别用户资料库中零曲目的专辑。按发行日期对推荐进行排序。
运行:python3 scripts/catalog_explorer.py gap-analysis
呈现为:你喜爱Radiohead,但你只听了他9张专辑中的3张。以下是你错过的内容,按你可能喜欢每张的程度排序。
专辑深度