How to get the name of the music currently playing in spotify?

I'm trying to find a way to display the music that's currently playing in the terminal and show on my vim statusline, I imagine there some temp file with the current song name, anyone knows where can i find it?


Inspired by the sp-metadata function in sp, which is "a command-line client for Spotify's dbus interface" at https://gist.github.com/wandernauta/6800547, you can use the following command to get the track title:

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata | sed -n '/title/{n;p}' | cut -d '"' -f 2