MOC and

The moc player itself doesn’t support scrobbling. But there is an option to execute an external command on each track change:

OnSongChange = "/path/to/external/command %a %t %d %r"

Arguments are substituted using current song (that is, the song that playing is changed to) info:

Each parameter will be properly escaped. Os course, if there no info about some of that parameters, an empty string will be passed.

Perfect script for above task can be found at Put it anywhere you like and make it executable.

$ chmod +x moc_submit_lastfm

Now it can be specified in the MOC confing file:

OnSongChange = "/path/to/moc_submit_lastfm --artist %a --title %t --length %d --album %r"

Next what will need is a scrobbler itself. The most common one under Linux and the one that is used by script is lastfmsubmitd. Upon installation it may ask user to fill some data like user name and password, and user group. The latter one by default is called lastfm. The only users who can sumbit info to are the ones who are present in group lastfm

$ sudo apt-get install lastfmsubmitd
$ sudo addgroup lastfm
$ sudo adduser $YOUR_USER lastfm # This will add user to the group

Now mocp should be completely restarted in order to re-read it’s config:

$ mocp -x && mocp

N.B.: Sometimes even if /etc/lastfmsubmitd.conf contains valid account info, no scrobbling data is send by lastfmsubmitd during being said that lastfmsubmitd: no account info found; exiting.. One reason for that is that conf file is not accessible by the deamon, usually due to its permissions: they’re 600 (that is, the only reader and writer is root) and should be set to 755 (that is, every user can read but only root is allowed to write). Also there might be need to set 777 permissions to pool dir /var/spool/lastfm.