ClawSkills logoClawSkills

Last.fm

访问 Last.fm 收听历史、音乐统计和发现数据。查询最近曲目、热门艺人/专辑/曲目、喜爱的曲目、相似艺人和全球榜单。

介绍

# Last.fm API Skill

访问 Last.fm 听歌历史、音乐统计和发现功能。

## 配置

**必需的环境变量**(添加到你的 Shell 配置文件或可选的 `~/.clawdbot/.env` 中): - `LASTFM_API_KEY` — 你的 Last.fm API 密钥([在此获取](https://www.last.fm/api/account/create)) - `LASTFM_USER` — 你的 Last.fm 用户名

**基础 URL**: `http://ws.audioscrobbler.com/2.0/` **文档**: https://lastfm-docs.github.io/api-docs/

## 示例输出

这是 17 年以上的听歌记录(Scrobbling)的样子:

``` Total scrobbles: 519,778 Unique artists: 13,763 Unique tracks: 68,435 Unique albums: 33,637

Top Artists (all time): • System of a Down (52,775 plays) • Eminem (15,400 plays) • Dashboard Confessional (10,166 plays) • Edguy (10,161 plays) • Metallica (9,927 plays)

Top Tracks (all time): • System of a Down - Aerials (1,405 plays) • System of a Down - Toxicity (1,215 plays) • System of a Down - Sugar (1,149 plays) • System of a Down - Chop Suey (1,116 plays) • System of a Down - Prison Song (1,102 plays) ```

## 快速参考

所有请求均使用 GET,并包含以下基础参数: ``` ?api_key=$LASTFM_API_KEY&format=json&user=$LASTFM_USER ```

### 用户端点

#### 最近曲目(正在播放 / 最近播放过) ```bash 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` 的曲目正在播放 - 返回:艺术家、曲目名称、专辑、时间戳、图片

#### 用户信息(个人资料统计) ```bash curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json" ``` - 返回:播放次数、艺术家数量、曲目数量、专辑数量、注册日期

#### 热门艺术家 ```bash 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

#### 热门专辑 ```bash curl -s "http://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json&period=7day&limit=10" ```

#### 热门曲目 ```bash 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" ```

#### 喜爱曲目 ```bash curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getlovedtracks&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json&limit=10" ```

#### 每周榜单 ```bash # Weekly artist chart curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getweeklyartistchart&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json"

# Weekly track chart curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getweeklytrackchart&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json"

# Weekly album chart curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getweeklyalbumchart&user=$LASTFM_USER&api_key=$LASTFM_API_KEY&format=json" ```

### 艺术家/曲目/专辑信息

#### 艺术家信息 ```bash 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` 可包含该艺术家对应用户的播放次数

#### 相似艺术家 ```bash curl -s "http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=Tame+Impala&api_key=$LASTFM_API_KEY&format=json&limit=10" ```

#### 艺术家热门曲目 ```bash curl -s "http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&artist=Tame+Impala&api_key=$LASTFM_API_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=$LASTFM_API_KEY&format=json&username=$LASTFM_USER" ```

#### 相似曲目 ```bash 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" ```

#### 专辑信息 ```bash 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" ```

### 搜索

#### 搜索艺术家 ```bash curl -s "http://ws.audioscrobbler.com/2.0/?method=artist.search&artist=tame&api_key=$LASTFM_API_KEY&format=json&limit=5" ```

#### 搜索曲目 ```bash curl -s "http://ws.audioscrobbler.com/2.0/?method=track.search&track=elephant&api_key=$LASTFM_API_KEY&format=json&limit=5" ```

#### 搜索专辑 ```bash curl -s "http://ws.audioscrobbler.com/2.0/?method=album.search&album=currents&api_key=$LASTFM_API_KEY&format=json&limit=5" ```

### 榜单(全球)

```bash # Top artists globally curl -s "http://ws.audioscrobbler.com/2.0/?method=chart.gettopartists&api_key=$LASTFM_API_KEY&format=json&limit=10"

# Top tracks globally curl -s "http://ws.audioscrobbler.com/2.0/?method=chart.gettoptracks&api_key=$LASTFM_API_KEY&format=json&limit=10" ```

### 标签

```bash # Top albums for a tag/genre curl -s "http://ws.audioscrobbler.com/2.0/?method=tag.gettopalbums&tag=psychedelic&api_key=$LASTFM_API_KEY&format=json&limit=10"

# Top artists for a tag curl -s "http://ws.audioscrobbler.com/2.0/?method=tag.gettopartists&tag=brazilian&api_key=$LASTFM_API_KEY&format=json&limit=10" ```

## 实用的 jq 过滤器

关于 JSON 处理,请参阅 [ClawdHub 上的 jq 技能](https://clawdhub.com/skills/jq)。

```bash # Recent tracks: artist - track jq '.recenttracks.track[] | "\(.artist["#text"]) - \(.name)"'

# Top artists: name (playcount) jq '.topartists.artist[] | "\(.name) (\(.playcount))"'

# Check if currently playing jq '.recenttracks.track[0] | if .["@attr"].nowplaying == "true" then "Now playing: \(.artist["#text"]) - \(.name)" else "Last played: \(.artist["#text"]) - \(.name)" end' ```

## 注意事项

- 只读端点不需要身份验证(仅需 API 密钥) - 速率限制:请保持合理,未记录硬性限制 - 对艺术家/曲目/专辑名称进行 URL 编码(空格 → `+` 或 `%20`) - 图片尺寸包括:small、medium、large、extralarge

更多产品