A lightweight, reliable Go daemon that submits tracks played on Music Player Daemon (MPD) to Last.fm / Audioscrobbler.
To build, install the binary to ~/.local/bin, set up ~/.config/mpd-scrobbler/config.toml, and enable the user-level systemd service:
./install.shTo remove the service and binary:
./uninstall.shConfiguration values are evaluated with the following precedence:
- Command-line flags (highest priority)
- Environment variables (via
envflag) - TOML configuration file (
~/.config/mpd-scrobbler/config.tomlor path passed to-config/CONFIG) - Built-in defaults (lowest priority)
Copy config.example.toml to ~/.config/mpd-scrobbler/config.toml:
[mpd]
network = "tcp"
address = "127.0.0.1:6600"
password = ""
reconnect_interval = "5s"
[lastfm]
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
session_key = "YOUR_SESSION_KEY"
# Alternatively for username/password:
# username = "user"
# password = "password"
[scrobble]
min_length = "30s"
min_percent = 50
max_duration = "4m"
now_playing = true
[general]
dry_run = false
verbose = false| Flag | Environment Variable | TOML Key | Default | Description |
|---|---|---|---|---|
-config |
CONFIG |
- | ~/.config/mpd-scrobbler/config.toml |
Path to TOML config file |
-mpd.network |
MPD_NETWORK |
mpd.network |
tcp |
MPD network type (tcp or unix) |
-mpd.address |
MPD_ADDRESS |
mpd.address |
127.0.0.1:6600 |
MPD host:port or unix socket path |
-mpd.password |
MPD_PASSWORD |
mpd.password |
"" |
MPD password (optional) |
-mpd.reconnect-interval |
MPD_RECONNECT_INTERVAL |
mpd.reconnect_interval |
5s |
Delay between MPD reconnect attempts |
-lastfm.api-key |
LASTFM_API_KEY |
lastfm.api_key |
"" |
Last.fm API Key |
-lastfm.api-secret |
LASTFM_API_SECRET |
lastfm.api_secret |
"" |
Last.fm API Secret |
-lastfm.session-key |
LASTFM_SESSION_KEY |
lastfm.session_key |
"" |
Last.fm Session Key |
-lastfm.username |
LASTFM_USERNAME |
lastfm.username |
"" |
Last.fm Username (for mobile auth) |
-lastfm.password |
LASTFM_PASSWORD |
lastfm.password |
"" |
Last.fm Password (for mobile auth) |
-lastfm.auth |
LASTFM_AUTH |
- | false |
Run interactive terminal auth to get session key |
-scrobble.min-length |
SCROBBLE_MIN_LENGTH |
scrobble.min_length |
30s |
Minimum song duration to scrobble |
-scrobble.min-percent |
SCROBBLE_MIN_PERCENT |
scrobble.min_percent |
50 |
Required percentage of track played (1-100) |
-scrobble.max-duration |
SCROBBLE_MAX_DURATION |
scrobble.max_duration |
4m0s |
Maximum listen duration before scrobbling |
-scrobble.now-playing |
SCROBBLE_NOW_PLAYING |
scrobble.now_playing |
true |
Send 'Now Playing' updates |
-scrobble.backlog-file |
SCROBBLE_BACKLOG_FILE |
scrobble.backlog_file |
~/.local/state/mpd-scrobbler/backlog.jsonl |
Persistent offline append-only backlog file path |
-scrobble.backlog-limit |
SCROBBLE_BACKLOG_LIMIT |
scrobble.backlog_limit |
5000 |
Max offline tracks to store (0 to disable) |
-dry-run |
DRY_RUN |
general.dry_run |
false |
Test scrobbling logic without contacting Last.fm |
-verbose |
VERBOSE |
general.verbose |
false |
Enable verbose logging |
-
Log in to your Last.fm account and navigate to the API account creation page:
https://www.last.fm/api/account/create -
Fill out the application form:
- Contact email: Your email address.
- Application name: E.g.
mpd-scrobbler(or any name you prefer). - Application description: A short note, e.g.
MPD scrobbler daemon. - Callback URL: Leave this blank / empty!
Why leave Callback URL blank?
As a daemon/command-line tool,mpd-scrobbleruses desktop/out-of-band authorization rather than running a web redirect server. When the callback URL is left blank, Last.fm simply displays a confirmation screen ("Application authorized") in your browser after you click "Allow", and the daemon retrieves the session key directly once you confirm in the terminal. - Application homepage: Can be left empty or set to
https://localhostor your repository URL.
-
Click Submit.
-
Last.fm will generate and display:
- API Key (e.g.
0123456789abcdef0123456789abcdef) - Shared Secret (e.g.
fedcba9876543210fedcba9876543210)
- API Key (e.g.
Once you have your API Key and Secret, run mpd-scrobbler with the -lastfm.auth flag:
mpd-scrobbler \
-lastfm.api-key="YOUR_API_KEY" \
-lastfm.api-secret="YOUR_API_SECRET" \
-lastfm.authFollow the prompt:
- Open the printed authorization link in your web browser.
- Click "Yes, allow access" on Last.fm.
- Switch back to your terminal and press [ENTER].
- The daemon will print your Session Key (e.g.
abc123...).
Add this session key to your ~/.config/mpd-scrobbler/config.toml:
[lastfm]
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
session_key = "YOUR_SESSION_KEY"With the session key saved, the daemon stays authenticated permanently without needing your username or password.
Once installed via ./install.sh:
- Check status:
systemctl --user status mpd-scrobbler.service
- View live logs:
journalctl --user -u mpd-scrobbler -f
- Restart service:
systemctl --user restart mpd-scrobbler.service
Run the test suite:
go test -v ./...