Dotfiles for my tiling window manager + terminal workflow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
984 B

4 days ago
  1. #!/usr/bin/python
  2. import dbus
  3. import os
  4. import sys
  5. try:
  6. bus = dbus.SessionBus()
  7. spotify = bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
  8. if os.environ.get('BLOCK_BUTTON'):
  9. control_iface = dbus.Interface(spotify, 'org.mpris.MediaPlayer2.Player')
  10. if (os.environ['BLOCK_BUTTON'] == '1'):
  11. control_iface.Previous()
  12. elif (os.environ['BLOCK_BUTTON'] == '2'):
  13. control_iface.PlayPause()
  14. elif (os.environ['BLOCK_BUTTON'] == '3'):
  15. control_iface.Next()
  16. spotify_iface = dbus.Interface(spotify, 'org.freedesktop.DBus.Properties')
  17. props = spotify_iface.Get('org.mpris.MediaPlayer2.Player', 'Metadata')
  18. if (sys.version_info > (3, 0)):
  19. print(str(props['xesam:artist'][0]) + " - " + str(props['xesam:title']))
  20. else:
  21. print(props['xesam:artist'][0] + " - " + props['xesam:title']).encode('utf-8')
  22. exit
  23. except dbus.exceptions.DBusException:
  24. exit