Merge pull request #154 from fredj/spotify_format

[module/spotify] Add new format string parameter
This commit is contained in:
tobi-wan-kenobi 2017-08-04 18:15:56 +02:00 committed by GitHub
commit 1db8168724

View file

@ -6,6 +6,8 @@ Requires the following library:
* python-dbus
Parameters:
* spotify.format: Format string (defaults to "{artist} - {title}")
Available values are: {album}, {title}, {artist}, {trackNumber}
"""
import bumblebee.input
@ -24,6 +26,7 @@ class Module(bumblebee.engine.Module):
bumblebee.output.Widget(full_text=self.spotify)
)
self._song = ""
self._format = self.parameter("format", "{artist} - {title}")
cmd="dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify \
/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player."
@ -43,7 +46,10 @@ class Module(bumblebee.engine.Module):
spotify = bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
spotify_iface = dbus.Interface(spotify, 'org.freedesktop.DBus.Properties')
props = spotify_iface.Get('org.mpris.MediaPlayer2.Player', 'Metadata')
self._song = (str(props['xesam:artist'][0]) + " - " + str(props['xesam:title']))
self._song = self._format.format(album=str(props.get('xesam:album')),
title=str(props.get('xesam:title')),
artist=','.join(props.get('xesam:artist')),
trackNumber=str(props.get('xesam:trackNumber')))
except Exception:
self._song = ""