Add spotify lister when open

This commit is contained in:
David Todd 2019-03-04 23:14:15 -06:00
parent f5b403b251
commit 4f31336cbc
2 changed files with 40 additions and 0 deletions

View File

@ -61,6 +61,11 @@ interval=persist
#interval=60 #interval=60
#command=~/bin/i3blocks/disk /home 🏠 #command=~/bin/i3blocks/disk /home 🏠
[spotify]
label=
color=#81b71a
interval=5
[window] [window]
interval=1 interval=1
label=🗔 label=🗔

35
i3/i3blocks/spotify Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env python
# Created by: https://github.com/firatakandere/i3blocks-spotify
import dbus
import os
import sys
try:
bus = dbus.SessionBus()
spotify = bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
if os.environ.get('BLOCK_BUTTON'):
control_iface = dbus.Interface(spotify, 'org.mpris.MediaPlayer2.Player')
if (os.environ['BLOCK_BUTTON'] == '1'):
control_iface.Previous()
elif (os.environ['BLOCK_BUTTON'] == '2'):
control_iface.PlayPause()
elif (os.environ['BLOCK_BUTTON'] == '3'):
control_iface.Next()
spotify_iface = dbus.Interface(spotify, 'org.freedesktop.DBus.Properties')
props = spotify_iface.Get('org.mpris.MediaPlayer2.Player', 'Metadata')
if (sys.version_info > (3, 0)):
print(str(props['xesam:artist'][0]) + " - " + str(props['xesam:title']))
else:
print(props['xesam:artist'][0] + " - " + props['xesam:title']).encode('utf-8')
exit
except dbus.exceptions.DBusException:
exit