time=$(dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.mbmp /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.getPositionInSeconds)
Substitute "Spotify" for "mbmp" in the command. MBMP is a homegrown thing, but does have an mpris interface.
]]>For the length of the current track:
length = int(metadata['mpris:length'])
mins = length / 1000000 // 60
seconds = length / 1000000 % 60
For the position that is always 0:
position = spotify_properties.Get("org.mpris.MediaPlayer2.Player","Position")
So I have been trying to write a shell script with my shallow knowledge to control spotify and see what is currently playing on my i3blocks sidebar. I successfully binded some keys for play/pause-next-previous. And also wrote a python script using dbus library to get current track's information such as song name, artist album.
import dbus
import sys
session_bus = dbus.SessionBus()
spotify_bus = session_bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
spotify_properties = dbus.Interface(spotify_bus, "org.freedesktop.DBus.Properties")
metadata = spotify_properties.Get("org.mpris.MediaPlayer2.Player","Metadata")
print(str(metadata['xesam:artist'][0]), '~', metadata['xesam:title'])
Now I would like to display the progress of the current track. For instance 1:02 / 5:12.
But I have no idea how I can access it. Any ideas on how I can somehow print such information?
Thanks!!!
]]>