名称: lastfm
描述: 访问 Last.fm 的收听历史、音乐统计数据及发现功能。可查询最近播放的曲目、热门艺人/专辑/曲目、收藏曲目、相似艺人及全球榜单。
访问 Last.fm 的收听历史、音乐统计数据及发现功能。
必需的环境变量(请添加到你的 shell 配置文件或可选的 ~/.clawdbot/.env 文件中):
- LASTFM_API_KEY — 你的 Last.fm API 密钥(在此获取)
- LASTFM_USER — 你的 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 方法,并包含以下基础参数:
?api_key=$LASTFM_API_KEY&format=json&user=$LASTFM_USER
curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json&limit=10"
@attr.nowplaying=true 的曲目为当前正在播放curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json"
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 | 12monthcurl -s "http://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json&period=7day&limit=10"
curl -s "http://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json&period=7day&limit=10"
curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getlovedtracks&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json&limit=10"
# 每周艺人榜单
curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getweeklyartistchart&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json"
# 每周曲目榜单
curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getweeklytrackchart&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json"
# 每周专辑榜单
curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getweeklyalbumchart&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json"
curl -s "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Tame+Impala&api_key=$LASTFM_API_KEY&format=json&username=$LASTFM_USER"
username 参数可包含该用户对该艺人的播放次数curl -s "http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=Tame+Impala&api_key=$LASTFM_API_KEY&format=json&limit=10"
curl -s "http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&artist=Tame+Impala&api_key=$LASTFM_API_KEY&format=json&limit=10"
curl -s "http://ws.audioscrobbler.com/2.0/?method=track.getinfo&artist=Tame+Impala&track=The+Less+I+Know+The+Better&api_key=$LASTFM_API_KEY&format=json&username=$LASTFM_USER"
curl -s "http://ws.audioscrobbler.com/2.0/?method=track.getsimilar&artist=Tame+Impala&track=Elephant&api_key=$LASTFM_API_KEY&format=json&limit=10"
curl -s "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&artist=Tame+Impala&album=Currents&api_key=$LASTFM_API_KEY&format=json&username=$LASTFM_USER"
curl -s "http://ws.audioscrobbler.com/2.0/?method=artist.search&artist=tame&api_key=$LASTFM_API_KEY&format=json&limit=5"
curl -s "http://ws.audioscrobbler.com/2.0/?method=track.search&track=elephant&api_key=$LASTFM_API_KEY&format=json&limit=5"
curl -s "http://ws.audioscrobbler.com/2.0/?method=album.search&album=currents&api_key=$LASTFM_API_KEY&format=json&limit=5"
# 全球热门艺人
curl -s "http://ws.audioscrobbler.com/2.0/?method=chart.gettopartists&api_key=$LASTFM_API_KEY&format=json&limit=10"
# 全球热门曲目
curl -s "http://ws.audioscrobbler.com/2.0/?method=chart.gettoptracks&api_key=$LASTFM_API_KEY&format=json&limit=10"
# 特定标签/流派的热门专辑
curl -s "http://ws.audioscrobbler.com/2.0/?method=tag.gettopalbums&tag=psychedelic&api_key=$LASTFM_API_KEY&format=json&limit=10"
# 特定标签的热门艺人
curl -s "http://ws.audioscrobbler.com/2.0/?method=tag.gettopartists&tag=brazilian&api_key=$LASTFM_API_KEY&format=json&limit=10"
如需处理 JSON 数据,请参考 ClawdHub 上的 jq 技能。
# 最近播放曲目:艺人 - 曲目
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'
+ 或 %20)