From 4f31336cbc9512729940b3a2198b1d5182bee640 Mon Sep 17 00:00:00 2001 From: David Todd Date: Mon, 4 Mar 2019 23:14:15 -0600 Subject: [PATCH] Add spotify lister when open --- i3/i3blocks.conf | 5 +++++ i3/i3blocks/spotify | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 i3/i3blocks/spotify diff --git a/i3/i3blocks.conf b/i3/i3blocks.conf index 96ba1bf..0987204 100644 --- a/i3/i3blocks.conf +++ b/i3/i3blocks.conf @@ -61,6 +61,11 @@ interval=persist #interval=60 #command=~/bin/i3blocks/disk /home 🏠 +[spotify] +label= +color=#81b71a +interval=5 + [window] interval=1 label=🗔 diff --git a/i3/i3blocks/spotify b/i3/i3blocks/spotify new file mode 100755 index 0000000..12f7ea6 --- /dev/null +++ b/i3/i3blocks/spotify @@ -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 + +