Last.fm
Setup
export LASTFM_API_KEY="your_api_key_here"
# For write operations only:
export LASTFM_API_SECRET="your_api_secret"
export LASTFM_SESSION_KEY="your_session_key"
Get an API key at https://www.last.fm/api/account/create (free, requires a Last.fm account).
Essential Commands
User queries — "what am I listening to"
Configurable via LASTFM_USERNAME env var. Defaults to <username> if unset.
lastfm-cli user info <username> # Profile + stats
lastfm-cli user recent-tracks <username> --limit 10 # Recent listening
lastfm-cli user top-artists <username> --period 7day # Weekly top artists
lastfm-cli user top-tracks <username> --period overall # All-time faves
lastfm-cli user loved-tracks <username> # Loved tracks
lastfm-cli user friends <username> # Social graph
lastfm-cli user weekly-charts <username> # Available chart periods
Music Discovery — "what's similar to X"
lastfm-cli artist similar <artist> --limit 10 # Taste graph neighbors
lastfm-cli artist info <artist> # Bio, stats, tags
lastfm-cli artist top-tracks <artist> # Their most popular
lastfm-cli track similar <artist> "<track>" # Track-level similarity
lastfm-cli album info <artist> "<album>" # Tracklist, metadata
lastfm-cli tag top-artists <tag> # Genre browsing
Charts — "what's popular"
lastfm-cli chart top-artists --limit 20 # Global
lastfm-cli geo top-artists "Japan" --limit 20 # Per-country
lastfm-cli geo top-tracks "Germany" --limit 20
lastfm-cli tag top-tracks "electronic" --limit 15 # By genre tag
Search — "find that thing"
lastfm-cli artist search "Radiohead" # Find by name
lastfm-cli album search "OK Computer" # Find albums
lastfm-cli track search "Karma Police" # Find tracks
Write operations (require session auth)
lastfm-cli track scrobble "Artist" "Song" --album "Album"
lastfm-cli track now-playing "Artist" "Song"
lastfm-cli track love "Artist" "Song"
Auth flow (one-time setup)
# 1. Get a token
lastfm-cli auth get-token
# 2. User visits: https://www.last.fm/api/auth/?api_key=KEY&token=TOKEN
# 3. Exchange for session key
lastfm-cli auth get-session <token>
# → Set export LASTFM_SESSION_KEY=<key>
Reference Files
references/auth-flow.md — Full walkthrough for setting up write operation auth (scrobble, love, now-playing). Read this before attempting write operations.
Music Discovery Pipeline — "find me new stuff I'll like"
The core flow for turning liked tracks into recommendations:
Get user's top artists/tracks from Last.fm:
lastfm-cli user top-artists <username> --period 1month --limit 5 --json
lastfm-cli user top-tracks <username> --period 1month --limit 10 --json
lastfm-cli user loved-tracks <username> --json
For each artist, find similar artists via Last.fm's collaborative filtering:
lastfm-cli artist similar "<artist>" --limit 5 --json
For each track, find similar tracks for more granular recommendations:
lastfm-cli track similar "<artist>" "<track>" --limit 5 --json
Cross-reference against what they've already scrobbled (recent-tracks) to filter out already-heard material.
Check against the user's own collection (via Radarr/Sonarr/jellyfin or Spotify library) to see what's already in the library vs genuinely new discovery.
Using with --json for Machine Processing
# Pipe to jq for structured queries
lastfm-cli artist similar "Radiohead" --limit 5 --json | jq '.similarartists.artist[] | {name, match}'
# Get a user's all-time top artists with playcounts
lastfm-cli user top-artists <username> --period overall --limit 3 --json | jq '.topartists.artist[] | {name, playcount}'
# Find most popular tracks by a genre
lastfm-cli tag top-tracks "electronic" --limit 10 --json | jq '.tracks.track[] | {name, artist: .artist.name, listeners}'
Known Gotchas
- API key required for EVERY request. The key is free — get one at the Last.fm API account page.
- Rate limit is ~5 req/sec sustained. The API docs say "be reasonable" — if you're making several calls per second continuously, your account may be suspended. Add small delays in loops.
- User-Agent header matters. The CLI sends
lastfm-cli/1.0 (hermes-agent). Last.fm's docs explicitly ask for an identifiable User-Agent.
- XML is the default response format. The CLI requests
format=json. Without it, responses come back as XML.
- Artist names can be misspelled. Use
--autocorrect flag on artist commands to let Last.fm correct misspellings.
- Write operations need auth setup. scrobble, love, and now-playing require a full auth flow (token → session key). Read-only endpoints don't.
- The collaborative filtering graph is NOT social.
artist.getSimilar returns algorithmic similarity based on aggregate listening patterns, not human-curated recommendations.
- Timestamps for scrobbles are UNIX epoch seconds. If omitted, uses current time.
--from and --to on recent-tracks accept ISO 8601 date strings (e.g., 2026-05-27).
- Period values:
overall, 7day, 1month, 3month, 6month, 12month.
When to Reach for This Tool
- User asks "what's [person] listening to lately?"
- User wants music discovery: "find me artists similar to..."
- User wants listening statistics: top artists, tracks, albums by period
- User wants geographic music trends: "what's popular in [country]"
- User wants genre exploration via tags
- User wants to scrobble or love tracks programmatically
- Any question about music metadata, artist info, album tracklists
Available Scripts
| Script |
Purpose |
Invocation |
scripts/lastfm-cli |
The CLI tool this skill drives: read-only queries (user info/recent-tracks/top-artists/top-tracks/loved-tracks/friends/weekly-charts), discovery (artist similar, track similar), charts and geo charts, search, tags, and — with session auth — scrobble, now-playing, and love. Run it for every Last.fm data question above; see Essential Commands for the full command surface. |
scripts/lastfm-cli user top-artists <username> --period 7day --limit 10 |
scripts/test-lastfm.sh |
Shell test suite covering the CLI's argument handling and output formatting without network calls. Run it after modifying scripts/lastfm-cli or when auditing a change to its behavior; CI runs it via scripts/check-skill-tests.py. |
bash scripts/test-lastfm.sh |
Prerequisites
- A free Last.fm API key exported as
LASTFM_API_KEY (create one at https://www.last.fm/api/account/create); every request fails without it.
- For write operations only:
LASTFM_API_SECRET plus a session key from the one-time auth flow in references/auth-flow.md, exported as LASTFM_SESSION_KEY.
- Python 3 on PATH — invoke the bundled tool as
python3 scripts/lastfm-cli ... if it is not executable directly; the SKILL.md examples assume lastfm-cli resolves on PATH.
- Optional:
LASTFM_USERNAME to set the default user for user queries; jq when piping --json output for structured processing.
Limitations
- Read-only endpoints need only the API key; scrobble, now-playing, and love require the full token → session-key auth flow and will fail without it.
- Sustained call rates above ~5 req/sec risk account suspension — add small delays in loops.
- Similarity endpoints are algorithmic collaborative filtering over aggregate listening patterns, not social or human-curated recommendations.
- Period values are fixed to
overall, 7day, 1month, 3month, 6month, and 12month; arbitrary date ranges are only available via --from/--to on recent-tracks.
- Misspelled artist names return empty or wrong results unless
--autocorrect is used.
When not to use
Do not use this skill for music playback control (local players, streaming queues), for non-Last.fm catalog data (MusicBrainz, Spotify metadata), or as a lyrics source — the API covers listening history, metadata, charts, tags, similarity, and scrobbling only.
1---2name: lastfm3description: Interact with the Last.fm music data API: lookup user listening history, get artist/album/track metadata, discover similar music via collaborative filtering, explore global and per-country charts, search by artist/album/track, manage tags, and scrobble listening events. Use when the user asks about music data, listening statistics, music recommendations, similar artists, charts, or wants to scrobble or love tracks. Do not use this skill for unrelated requests; route to the nearest named specialist.4license: MIT5---67# Last.fm89## Setup1011```bash12export LASTFM_API_KEY="your_api_key_here"13# For write operations only:14export LASTFM_API_SECRET="your_api_secret"15export LASTFM_SESSION_KEY="your_session_key"16```1718Get an API key at https://www.last.fm/api/account/create (free, requires a Last.fm account).1920## Essential Commands2122### User queries — "what am I listening to"2324Configurable via `LASTFM_USERNAME` env var. Defaults to `<username>` if unset.2526```bash27lastfm-cli user info <username> # Profile + stats28lastfm-cli user recent-tracks <username> --limit 10 # Recent listening29lastfm-cli user top-artists <username> --period 7day # Weekly top artists30lastfm-cli user top-tracks <username> --period overall # All-time faves31lastfm-cli user loved-tracks <username> # Loved tracks32lastfm-cli user friends <username> # Social graph33lastfm-cli user weekly-charts <username> # Available chart periods34```3536### Music Discovery — "what's similar to X"3738```bash39lastfm-cli artist similar <artist> --limit 10 # Taste graph neighbors40lastfm-cli artist info <artist> # Bio, stats, tags41lastfm-cli artist top-tracks <artist> # Their most popular42lastfm-cli track similar <artist> "<track>" # Track-level similarity43lastfm-cli album info <artist> "<album>" # Tracklist, metadata44lastfm-cli tag top-artists <tag> # Genre browsing45```4647### Charts — "what's popular"4849```bash50lastfm-cli chart top-artists --limit 20 # Global51lastfm-cli geo top-artists "Japan" --limit 20 # Per-country52lastfm-cli geo top-tracks "Germany" --limit 2053lastfm-cli tag top-tracks "electronic" --limit 15 # By genre tag54```5556### Search — "find that thing"5758```bash59lastfm-cli artist search "Radiohead" # Find by name60lastfm-cli album search "OK Computer" # Find albums61lastfm-cli track search "Karma Police" # Find tracks62```6364### Write operations (require session auth)6566```bash67lastfm-cli track scrobble "Artist" "Song" --album "Album"68lastfm-cli track now-playing "Artist" "Song"69lastfm-cli track love "Artist" "Song"70```7172### Auth flow (one-time setup)7374```bash75# 1. Get a token76lastfm-cli auth get-token7778# 2. User visits: https://www.last.fm/api/auth/?api_key=KEY&token=TOKEN7980# 3. Exchange for session key81lastfm-cli auth get-session <token>82# → Set export LASTFM_SESSION_KEY=<key>83```8485## Reference Files8687- `references/auth-flow.md` — Full walkthrough for setting up write operation auth (scrobble, love, now-playing). Read this before attempting write operations.8889## Music Discovery Pipeline — "find me new stuff I'll like"9091The core flow for turning liked tracks into recommendations:92931. **Get user's top artists/tracks** from Last.fm:94 ```bash95 lastfm-cli user top-artists <username> --period 1month --limit 5 --json96 lastfm-cli user top-tracks <username> --period 1month --limit 10 --json97 lastfm-cli user loved-tracks <username> --json98 ```991002. **For each artist, find similar artists** via Last.fm's collaborative filtering:101 ```bash102 lastfm-cli artist similar "<artist>" --limit 5 --json103 ```1041053. **For each track, find similar tracks** for more granular recommendations:106 ```bash107 lastfm-cli track similar "<artist>" "<track>" --limit 5 --json108 ```1091104. **Cross-reference** against what they've already scrobbled (recent-tracks) to filter out already-heard material.1111125. **Check against the user's own collection** (via Radarr/Sonarr/jellyfin or Spotify library) to see what's already in the library vs genuinely new discovery.113114## Using with --json for Machine Processing115116```bash117# Pipe to jq for structured queries118lastfm-cli artist similar "Radiohead" --limit 5 --json | jq '.similarartists.artist[] | {name, match}'119120# Get a user's all-time top artists with playcounts121lastfm-cli user top-artists <username> --period overall --limit 3 --json | jq '.topartists.artist[] | {name, playcount}'122123# Find most popular tracks by a genre124lastfm-cli tag top-tracks "electronic" --limit 10 --json | jq '.tracks.track[] | {name, artist: .artist.name, listeners}'125```126127## Known Gotchas128129- **API key required for EVERY request.** The key is free — get one at the Last.fm API account page.130- **Rate limit is ~5 req/sec sustained.** The API docs say "be reasonable" — if you're making several calls per second continuously, your account may be suspended. Add small delays in loops.131- **User-Agent header matters.** The CLI sends `lastfm-cli/1.0 (hermes-agent)`. Last.fm's docs explicitly ask for an identifiable User-Agent.132- **XML is the default response format.** The CLI requests `format=json`. Without it, responses come back as XML.133- **Artist names can be misspelled.** Use `--autocorrect` flag on artist commands to let Last.fm correct misspellings.134- **Write operations need auth setup.** scrobble, love, and now-playing require a full auth flow (token → session key). Read-only endpoints don't.135- **The collaborative filtering graph is NOT social.** `artist.getSimilar` returns algorithmic similarity based on aggregate listening patterns, not human-curated recommendations.136- **Timestamps for scrobbles** are UNIX epoch seconds. If omitted, uses current time.137- **`--from` and `--to` on recent-tracks** accept ISO 8601 date strings (e.g., `2026-05-27`).138- **Period values**: `overall`, `7day`, `1month`, `3month`, `6month`, `12month`.139140## When to Reach for This Tool141142- User asks "what's [person] listening to lately?"143- User wants music discovery: "find me artists similar to..."144- User wants listening statistics: top artists, tracks, albums by period145- User wants geographic music trends: "what's popular in [country]"146- User wants genre exploration via tags147- User wants to scrobble or love tracks programmatically148- Any question about music metadata, artist info, album tracklists149150## Available Scripts151152| Script | Purpose | Invocation |153|---|---|---|154| `scripts/lastfm-cli` | The CLI tool this skill drives: read-only queries (user info/recent-tracks/top-artists/top-tracks/loved-tracks/friends/weekly-charts), discovery (`artist similar`, `track similar`), charts and geo charts, search, tags, and — with session auth — `scrobble`, `now-playing`, and `love`. Run it for every Last.fm data question above; see Essential Commands for the full command surface. | `scripts/lastfm-cli user top-artists <username> --period 7day --limit 10` |155| `scripts/test-lastfm.sh` | Shell test suite covering the CLI's argument handling and output formatting without network calls. Run it after modifying `scripts/lastfm-cli` or when auditing a change to its behavior; CI runs it via `scripts/check-skill-tests.py`. | `bash scripts/test-lastfm.sh` |156157## Prerequisites158159- A free Last.fm API key exported as `LASTFM_API_KEY` (create one at https://www.last.fm/api/account/create); every request fails without it.160- For write operations only: `LASTFM_API_SECRET` plus a session key from the one-time auth flow in `references/auth-flow.md`, exported as `LASTFM_SESSION_KEY`.161- Python 3 on PATH — invoke the bundled tool as `python3 scripts/lastfm-cli ...` if it is not executable directly; the SKILL.md examples assume `lastfm-cli` resolves on PATH.162- Optional: `LASTFM_USERNAME` to set the default user for user queries; `jq` when piping `--json` output for structured processing.163164## Limitations165166- Read-only endpoints need only the API key; scrobble, now-playing, and love require the full token → session-key auth flow and will fail without it.167- Sustained call rates above ~5 req/sec risk account suspension — add small delays in loops.168- Similarity endpoints are algorithmic collaborative filtering over aggregate listening patterns, not social or human-curated recommendations.169- Period values are fixed to `overall`, `7day`, `1month`, `3month`, `6month`, and `12month`; arbitrary date ranges are only available via `--from`/`--to` on recent-tracks.170- Misspelled artist names return empty or wrong results unless `--autocorrect` is used.171172## When not to use173174Do not use this skill for music playback control (local players, streaming queues), for non-Last.fm catalog data (MusicBrainz, Spotify metadata), or as a lyrics source — the API covers listening history, metadata, charts, tags, similarity, and scrobbling only.