Last.fm Profile Skill
Retrieves Last.fm user listening data including now playing, top tracks/artists/albums by time period, and loved tracks. Optionally supports write operations (love/unlove tracks, scrobble) when LASTFM_SESSION_KEY is configured.
Required Environment Variables
- -
LASTFM_API_KEY: Your Last.fm API key (get one at https://www.last.fm/api/account/create) - INLINECODE2 : Your Last.fm username
Optional Environment Variables
- -
LASTFM_SESSION_KEY: Required for write operations (love/unlove, scrobble) - INLINECODE4 : Required to sign write operations (love/unlove, scrobble)
Workflow
- 1. Validate required environment variables are present
- Ensure dependencies (
jq, curl) are available - Determine which command the user is requesting
- Determine which command the user is requesting
- Construct API request to INLINECODE7
- Execute HTTP GET request with appropriate method and parameters
- Parse JSON response and format for user
Supported Commands
Read Operations (No Auth Required)
| Command | Description | Example |
|---|
| INLINECODE8 , INLINECODE9 | Current or most recent track | INLINECODE10 |
| INLINECODE11 |
Top tracks by period |
/lastfm top-tracks 7day |
|
top-artists [period] | Top artists by period |
/lastfm top-artists 1month |
|
top-albums [period] | Top albums by period |
/lastfm top-albums overall |
|
loved | Loved tracks |
/lastfm loved |
|
recent [limit] | Recent tracks (default 10) |
/lastfm recent 20 |
|
profile | User profile info |
/lastfm profile |
Time Periods
- -
7day - Last 7 days - INLINECODE24 - Last 30 days
- INLINECODE25 - Last 90 days
- INLINECODE26 - Last 180 days
- INLINECODE27 - Last year
- INLINECODE28 - All time (default if not specified)
Write Operations (Auth Required)
| Command | Description | Example |
|---|
| INLINECODE29 | Love a track | INLINECODE30 |
| INLINECODE31 |
Unlove a track |
/lastfm unlove "Radiohead" "Creep" |
API Request Construction
Base URL: INLINECODE33
Required parameters for all requests:
- -
api_key: Value from INLINECODE35 - INLINECODE36 : INLINECODE37
- INLINECODE38 : API method name
User-specific requests also require:
- -
user: Value from INLINECODE40
Method Parameters
| Method | Additional Parameters |
|---|
| INLINECODE41 | INLINECODE42 |
| INLINECODE43 |
user,
limit (optional) |
|
user.getTopTracks |
user,
period (optional) |
|
user.getTopArtists |
user,
period (optional) |
|
user.getTopAlbums |
user,
period (optional) |
|
user.getLovedTracks |
user |
|
track.love |
artist,
track,
sk (session key) |
|
track.unlove |
artist,
track,
sk (session key) |
Response Parsing
Now Playing Response
Extract from recenttracks.track[0]:
- - If
@attr.nowplaying === "true": currently playing - INLINECODE67 - Artist name
- INLINECODE68 - Track name
- INLINECODE69 - Album name
Top Items Response
Extract array from:
- -
toptracks.track[] for top tracks - INLINECODE71 for top artists
- INLINECODE72 for top albums
Each item includes:
- -
name - Item name - INLINECODE74 - Play count
- INLINECODE75 - Artist (for tracks/albums)
- INLINECODE76 - Position in chart
Profile Response
Extract from user:
- -
name - Username - INLINECODE79 - Real name (if set)
- INLINECODE80 - Total scrobbles
- INLINECODE81 - Country
- INLINECODE82 - Account creation date
- INLINECODE83 - Profile URL
Guardrails
- - Never log or expose API keys or session keys in output
- Rate limit: respect Last.fm's 5 requests/second limit
- Write operations must fail gracefully if
LASTFM_SESSION_KEY not set - All user inputs must be URL-encoded before API calls
- Only connect to
ws.audioscrobbler.com - no external endpoints - Handle missing data gracefully (e.g., no now playing, empty loved tracks)
- Validate period parameter is one of: 7day, 1month, 3month, 6month, 12month, overall
- Validate
recent limit is numeric and within 1–200
Error Handling
| Error Code | Meaning | Action |
|---|
| 10 | Invalid API key | Tell user to check INLINECODE87 |
| 6 |
Invalid parameters | Check required params are present |
| 29 | Rate limit exceeded | Wait and retry, inform user |
| 26 | Suspended API key | Direct user to Last.fm support |
| 4 | Authentication failed | Check session key for write ops |
Example Output Formats
Now Playing
CODEBLOCK0
Or if not currently playing:
CODEBLOCK1
Top Tracks
CODEBLOCK2
Profile
CODEBLOCK3
Setup Instructions
- 1. Get a Last.fm API key at https://www.last.fm/api/account/create
- Add to
~/.openclaw/openclaw.json:
CODEBLOCK4
- 3. For write operations, see INLINECODE89
Last.fm 个人资料技能
获取 Last.fm 用户收听数据,包括当前播放、按时间段划分的热门曲目/艺术家/专辑以及喜爱的曲目。当配置了 LASTFMSESSIONKEY 时,可选择支持写入操作(喜爱/取消喜爱曲目、记录收听记录)。
必需的环境变量
- - LASTFMAPIKEY:你的 Last.fm API 密钥(在 https://www.last.fm/api/account/create 获取)
- LASTFM_USERNAME:你的 Last.fm 用户名
可选的环境变量
- - LASTFMSESSIONKEY:写入操作(喜爱/取消喜爱、记录收听记录)所需
- LASTFMAPISECRET:签署写入操作(喜爱/取消喜爱、记录收听记录)所需
工作流程
- 1. 验证必需的环境变量是否存在
- 确保依赖项(jq、curl)可用
- 确定用户请求的命令
- 构建对 ws.audioscrobbler.com/2.0/ 的 API 请求
- 使用适当的方法和参数执行 HTTP GET 请求
- 解析 JSON 响应并格式化输出给用户
支持的命令
读取操作(无需认证)
| 命令 | 描述 | 示例 |
|---|
| now-playing、np | 当前或最近播放的曲目 | /lastfm np |
| top-tracks [时间段] |
按时间段的热门曲目 | /lastfm top-tracks 7day |
| top-artists [时间段] | 按时间段的热门艺术家 | /lastfm top-artists 1month |
| top-albums [时间段] | 按时间段的热门专辑 | /lastfm top-albums overall |
| loved | 喜爱的曲目 | /lastfm loved |
| recent [数量] | 最近播放的曲目(默认 10 首) | /lastfm recent 20 |
| profile | 用户个人资料信息 | /lastfm profile |
时间段
- - 7day - 最近 7 天
- 1month - 最近 30 天
- 3month - 最近 90 天
- 6month - 最近 180 天
- 12month - 最近一年
- overall - 全部时间(未指定时的默认值)
写入操作(需认证)
| 命令 | 描述 | 示例 |
|---|
| love <艺术家> <曲目> | 喜爱一首曲目 | /lastfm love Radiohead Creep |
| unlove <艺术家> <曲目> |
取消喜爱一首曲目 | /lastfm unlove Radiohead Creep |
API 请求构建
基础 URL:https://ws.audioscrobbler.com/2.0/
所有请求的必需参数:
- - apikey:来自 LASTFMAPI_KEY 的值
- format:json
- method:API 方法名称
用户特定请求还需要:
- - user:来自 LASTFM_USERNAME 的值
方法参数
| 方法 | 附加参数 |
|---|
| user.getInfo | user |
| user.getRecentTracks |
user、limit(可选) |
| user.getTopTracks | user、period(可选) |
| user.getTopArtists | user、period(可选) |
| user.getTopAlbums | user、period(可选) |
| user.getLovedTracks | user |
| track.love | artist、track、sk(会话密钥) |
| track.unlove | artist、track、sk(会话密钥) |
响应解析
当前播放响应
从 recenttracks.track[0] 中提取:
- - 如果 @attr.nowplaying === true:正在播放
- artist.#text - 艺术家名称
- name - 曲目名称
- album.#text - 专辑名称
热门项目响应
从以下位置提取数组:
- - toptracks.track[] 用于热门曲目
- topartists.artist[] 用于热门艺术家
- topalbums.album[] 用于热门专辑
每个项目包括:
- - name - 项目名称
- playcount - 播放次数
- artist.name - 艺术家(用于曲目/专辑)
- @attr.rank - 在排行榜中的位置
个人资料响应
从 user 中提取:
- - name - 用户名
- realname - 真实姓名(如果设置)
- playcount - 总收听记录数
- country - 国家
- registered - 账户创建日期
- url - 个人资料 URL
安全限制
- - 切勿在输出中记录或暴露 API 密钥或会话密钥
- 速率限制:遵守 Last.fm 每秒 5 次请求的限制
- 如果未设置 LASTFMSESSIONKEY,写入操作必须优雅地失败
- 所有用户输入在 API 调用前必须进行 URL 编码
- 仅连接到 ws.audioscrobbler.com - 不连接外部端点
- 优雅地处理缺失数据(例如,无当前播放、喜爱的曲目为空)
- 验证时间段参数必须为以下之一:7day、1month、3month、6month、12month、overall
- 验证 recent 限制为数字且在 1–200 范围内
错误处理
| 错误代码 | 含义 | 操作 |
|---|
| 10 | 无效的 API 密钥 | 告知用户检查 LASTFMAPIKEY |
| 6 |
无效参数 | 检查必需参数是否存在 |
| 29 | 超出速率限制 | 等待并重试,告知用户 |
| 26 | API 密钥被暂停 | 引导用户联系 Last.fm 支持 |
| 4 | 认证失败 | 检查写入操作的会话密钥 |
示例输出格式
当前播放
🎵 正在播放:
曲目名称 - 艺术家名称
来自专辑名称
或者如果当前未播放:
🎵 上次播放:
曲目名称 - 艺术家名称
收听时间:[时间戳]
热门曲目
🎵 热门曲目(7 天):
- 1. 曲目一 - 艺术家一(42 次播放)
- 曲目二 - 艺术家二(38 次播放)
- 曲目三 - 艺术家三(31 次播放)
...
个人资料
🎵 Last.fm 个人资料:用户名
📊 共 15,432 次收听记录
🌍 英国
📅 会员自:2002 年 11 月
🔗 last.fm/user/用户名
设置说明
- 1. 在 https://www.last.fm/api/account/create 获取 Last.fm API 密钥
- 添加到 ~/.openclaw/openclaw.json:
json5
{
skills: {
entries: {
lastfm: {
enabled: true,
env: {
LASTFMAPIKEY: 你的API密钥,
LASTFM_USERNAME: 你的用户名
}
}
}
}
}
- 3. 对于写入操作,请参阅 {baseDir}/references/auth-guide.md