Last.fm API Skill
Access Last.fm listening history, music stats, and discovery.
Configuration
Required env vars (add to your shell profile or optionally ~/.clawdbot/.env):
- -
LASTFM_API_KEY — your Last.fm API key (get one here) - INLINECODE2 — your Last.fm username
Base URL: http://ws.audioscrobbler.com/2.0/
Docs: https://lastfm-docs.github.io/api-docs/
Example Output
Here's what 17+ years of scrobbling looks like:
CODEBLOCK0
Quick Reference
All requests use GET with these base params:
CODEBLOCK1
User Endpoints
Recent Tracks (what's playing / recently played)
curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json&limit=10"
- - First track with
@attr.nowplaying=true is currently playing - Returns: artist, track name, album, timestamp, images
User Info (profile stats)
curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json"
- - Returns: playcount, artistcount, trackcount, album_count, registered date
Top Artists
curl -s "http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json&period=7day&limit=10"
- -
period: overall | 7day | 1month | 3month | 6month | 12month
Top Albums
CODEBLOCK5
Top Tracks
CODEBLOCK6
Loved Tracks
CODEBLOCK7
Weekly Charts
CODEBLOCK8
Artist/Track/Album Info
Artist Info
curl -s "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Tame+Impala&api_key=$LASTFM_API_KEY&format=json&username=$LASTFM_USER"
- - Adding
username includes user's playcount for that artist
Similar Artists
CODEBLOCK10
Artist Top Tracks
CODEBLOCK11
Track Info
CODEBLOCK12
Similar Tracks
CODEBLOCK13
Album Info
CODEBLOCK14
Search
Search Artists
CODEBLOCK15
Search Tracks
CODEBLOCK16
Search Albums
CODEBLOCK17
Charts (Global)
CODEBLOCK18
Tags
CODEBLOCK19
Useful jq Filters
For JSON processing, see the jq skill on ClawdHub.
CODEBLOCK20
Notes
- - No auth needed for read-only endpoints (just API key)
- Rate limit: be reasonable, no hard limit documented
- URL-encode artist/track/album names (spaces →
+ or %20) - Images come in sizes: small, medium, large, extralarge
Last.fm API 技能
访问 Last.fm 收听历史、音乐统计和发现。
配置
所需环境变量(添加到您的 shell 配置文件或可选地添加到 ~/.clawdbot/.env):
- - LASTFMAPIKEY — 您的 Last.fm API 密钥(在此获取)
- LASTFMUSER — 您的 Last.fm 用户名
基础 URL:http://ws.audioscrobbler.com/2.0/
文档:https://lastfm-docs.github.io/api-docs/
示例输出
以下是 17 年以上的收听记录示例:
总收听次数:519,778
独特艺术家:13,763
独特曲目:68,435
独特专辑:33,637
热门艺术家(全部时间):
• System of a Down(52,775 次播放)
• Eminem(15,400 次播放)
• Dashboard Confessional(10,166 次播放)
• Edguy(10,161 次播放)
• Metallica(9,927 次播放)
热门曲目(全部时间):
• System of a Down - Aerials(1,405 次播放)
• System of a Down - Toxicity(1,215 次播放)
• System of a Down - Sugar(1,149 次播放)
• System of a Down - Chop Suey(1,116 次播放)
• System of a Down - Prison Song(1,102 次播放)
快速参考
所有请求均使用 GET 方法,并包含以下基础参数:
?apikey=$LASTFMAPIKEY&format=json&user=$LASTFMUSER
用户端点
最近曲目(正在播放/最近播放)
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=$LASTFM
USER&apikey=$LASTFM
APIKEY&format=json&limit=10
- - 第一个带有 @attr.nowplaying=true 的曲目为当前正在播放
- 返回:艺术家、曲目名称、专辑、时间戳、图片
用户信息(个人资料统计)
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=$LASTFM
USER&apikey=$LASTFM
APIKEY&format=json
- - 返回:播放次数、艺术家数量、曲目数量、专辑数量、注册日期
热门艺术家
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=$LASTFM
USER&apikey=$LASTFM
APIKEY&format=json&period=7day&limit=10
- - period:overall | 7day | 1month | 3month | 6month | 12month
热门专辑
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user=$LASTFM
USER&apikey=$LASTFM
APIKEY&format=json&period=7day&limit=10
热门曲目
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=$LASTFM
USER&apikey=$LASTFM
APIKEY&format=json&period=7day&limit=10
喜爱的曲目
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=user.getlovedtracks&user=$LASTFM
USER&apikey=$LASTFM
APIKEY&format=json&limit=10
每周排行榜
bash
每周艺术家排行榜
curl -s http://ws.audioscrobbler.com/2.0/?method=user.getweeklyartistchart&user=$LASTFM
USER&apikey=$LASTFM
APIKEY&format=json
每周曲目排行榜
curl -s http://ws.audioscrobbler.com/2.0/?method=user.getweeklytrackchart&user=$LASTFM
USER&apikey=$LASTFM
APIKEY&format=json
每周专辑排行榜
curl -s http://ws.audioscrobbler.com/2.0/?method=user.getweeklyalbumchart&user=$LASTFM
USER&apikey=$LASTFM
APIKEY&format=json
艺术家/曲目/专辑信息
艺术家信息
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Tame+Impala&api
key=$LASTFMAPI
KEY&format=json&username=$LASTFMUSER
- - 添加 username 参数可包含该艺术家的用户播放次数
相似艺术家
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=Tame+Impala&api
key=$LASTFMAPI_KEY&format=json&limit=10
艺术家热门曲目
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&artist=Tame+Impala&api
key=$LASTFMAPI_KEY&format=json&limit=10
曲目信息
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=track.getinfo&artist=Tame+Impala&track=The+Less+I+Know+The+Better&api
key=$LASTFMAPI
KEY&format=json&username=$LASTFMUSER
相似曲目
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=track.getsimilar&artist=Tame+Impala&track=Elephant&api
key=$LASTFMAPI_KEY&format=json&limit=10
专辑信息
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=album.getinfo&artist=Tame+Impala&album=Currents&api
key=$LASTFMAPI
KEY&format=json&username=$LASTFMUSER
搜索
搜索艺术家
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=artist.search&artist=tame&api
key=$LASTFMAPI_KEY&format=json&limit=5
搜索曲目
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=track.search&track=elephant&api
key=$LASTFMAPI_KEY&format=json&limit=5
搜索专辑
bash
curl -s http://ws.audioscrobbler.com/2.0/?method=album.search&album=currents&api
key=$LASTFMAPI_KEY&format=json&limit=5
排行榜(全局)
bash
全局热门艺术家
curl -s http://ws.audioscrobbler.com/2.0/?method=chart.gettopartists&api
key=$LASTFMAPI_KEY&format=json&limit=10
全局热门曲目
curl -s http://ws.audioscrobbler.com/2.0/?method=chart.gettoptracks&api
key=$LASTFMAPI_KEY&format=json&limit=10
标签
bash
标签/流派的热门专辑
curl -s http://ws.audioscrobbler.com/2.0/?method=tag.gettopalbums&tag=psychedelic&api
key=$LASTFMAPI_KEY&format=json&limit=10
标签的热门艺术家
curl -s http://ws.audioscrobbler.com/2.0/?method=tag.gettopartists&tag=brazilian&api
key=$LASTFMAPI_KEY&format=json&limit=10
实用的 jq 过滤器
有关 JSON 处理,请参阅 ClawdHub 上的 jq 技能。
bash
最近曲目:艺术家 - 曲目
jq .recenttracks.track[] | \(.artist[#text]) - \(.name)
热门艺术家:名称(播放次数)
jq .topartists.artist[] | \(.name) (\(.playcount))
检查当前是否正在播放
jq .recenttracks.track[0] | if .[@attr].nowplaying == true then 正在播放:\(.artist[#text]) - \(.name) else 最近播放:\(.artist[#text]) - \(.name) end
注意事项