Basically, the way it works, is you hit /api/v1/pleroma/scrobble whenever you listen to a song, but the process can be automated. In the past, people would use Last.fm for this. You can hook Spotify, Pandora, WinAmp, and whatever else up to it.
I wrote a script that bridges Last.fm (which is supported by basically every music listening program and streaming service) into the Pleroma API: