Most Linux distributions include a native last.fm client that can perfectly scrobble music and display information about the current composition. But the authors of the players persistently ignore it, each time inventing their own bicycle.
The only solution found was in the form of a
patch for Rhythmbox . I was just looking for a player under GNOME, and this ultimately influenced the choice of the player.
But the time is running and recently I decided to move to mpd and the problem arose again.
Of course, for mpd there are scrobbling plugins too, but what I always lack in these implementations is: the
Love Track buttons so that you can mark your favorite tracks. Yes, and according to the ideology of Linux, chaining programs is indeed very correct.
')
On the website Last.FM, the protocol between the player and the client is not described anywhere, so I had to peek into the sources of that same patch for Rhythmbox and use Google Code Search.
And everything turned out.
Protocol
The exchange protocol between the player and the client is very simple. The client expects a line of view from the player
COMMAND parameter = value & parameter = value & ...The characters
& are escaped by themselves:
&& . After receiving the command, the client closes the connection and waits for a new connection and a new command.
The teams showed up the following:
START with parameters
- c - client id
- a - performer
- t - header
- b = album
- m - MusicBrains ID
- l - duration
- p - path to file
This team informs the client that we are starting to play a new track. After receiving this command, the client starts the countdown itself. Notify him of our progress is not required.
PAUSE ,
RESUME ,
STOP - all with a single parameter
c (see above)
Their purpose is obvious and they correspond to the commands in the player itself.
Implementation
Further does not present any difficulties: we regularly poll mpd (To communicate with mpd, the standard (from the repository)
python-mpd is used ), and if its state has changed, then we send the corresponding Last.FM command to the client. Even in the code, the log, client auto-launch and reconnect to mpd are implemented, if it suddenly falls off. Still do not reach the hands to screw the normal demonization.
The settings are eaten from /etc/mpdlastfm.conf or ~ / .mpdlastfm.conf in this format:
mpd_host = localhost # , mpd
mpd_port = 6600 #
mpd_root = /media/sys-work/music # .
log_file = /tmp/mpdlfm.log #
mpd_pass = secrepass #
Default values ​​(see in the code) can be omitted.
The code is commented, so I will not give it here, but
you can read it on paste.bin .
It has been spinning around for a month already, the main bugs have been fixed.

