Announcements

Help Wizard

Step 1

NEXT STEP

Bash script to show the current mm:ss in a playing track

Bash script to show the current mm:ss in a playing track

Hello all, 

So I have been trying to write a bash script with my shallow knowledge to control spotify and see what is currently playing on my 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!!!

 

Reply
0 Replies

Suggested posts