diff options
| author | Pierre Guilbert <pierre@1000mercis.com> | 2015-03-31 11:43:13 +0200 |
|---|---|---|
| committer | Pierre Guilbert <pierre@1000mercis.com> | 2015-03-31 11:43:13 +0200 |
| commit | 1ac61292ef0b4a25283eb53661df96dceee274c2 (patch) | |
| tree | b0b64a05c264b733fba6d5e244244d92f2cc45b3 /py3status/modules/spotify.py | |
| parent | 53050c95eaa08b58c2726b49c7435893324c6388 (diff) | |
adding support for formating output of spotify module
Diffstat (limited to 'py3status/modules/spotify.py')
| -rw-r--r-- | py3status/modules/spotify.py | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/py3status/modules/spotify.py b/py3status/modules/spotify.py index a797bb3..f70afae 100644 --- a/py3status/modules/spotify.py +++ b/py3status/modules/spotify.py @@ -5,31 +5,58 @@ This module displays the current "artist - title" playing in Spotify. Last modified: 2015-03-26 Author: Pierre Guilbert <pierre@1000mercis.com> License: GNU GPL http://www.gnu.org/licenses/gpl.html + +You could conf it in your i3status.conf like so: + + + +spotify { + format = "{title} by {artist} -> {time}" +} + + """ from time import time -import dbus, dbus.proxies +import dbus + class Py3status: + """ + Confiuration parameters: + cache_timeout + Format of status string placeholders: + title - name of the song + artist - artiste name (first one) + album - album name + time - time duration of the song + """ # available configuration parameters cache_timeout = 0 + format = "{title}: {album} : {artist} : {time}" def getText(self): """ Get the current song metadatas (artist - title) """ - + bus = dbus.SessionBus() try: - self.__bus = bus.get_object('com.spotify.qt', '/') - self.player = dbus.Interface(self.__bus, 'org.freedesktop.MediaPlayer2') + self.__bus = bus.get_object('com.spotify.qt', '/') + self.player = dbus.Interface( + self.__bus, 'org.freedesktop.MediaPlayer2') title = self.player.GetMetadata().get('xesam:title') artist = self.player.GetMetadata().get('xesam:artist')[0] album = self.player.GetMetadata().get('xesam:album') - return title + " by " + artist + from datetime import timedelta + microtime = self.player.GetMetadata().get('mpris:length') + time = str(timedelta(microseconds=microtime)) + + return self.format.format(title=title, + artist=artist, album=album, time=time) except Exception: return "Spotify not running" @@ -40,7 +67,8 @@ class Py3status: response = {'full_text': ''} response['cached_until'] = time() + self.cache_timeout - response['full_text'] = self.getText() or 'py3status module not working as expected' + response['full_text'] = self.getText( + ) or 'py3status module not working as expected' return response |
