From 404c9ea3488c00b4cec4ffa6312c769ac12de737 Mon Sep 17 00:00:00 2001 From: Christopher Ganas Date: Sun, 4 Jan 2015 16:07:25 -0500 Subject: [PATCH] Updated spotify module to check for metadata on start. --- i3pystatus/spotify.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/i3pystatus/spotify.py b/i3pystatus/spotify.py index 8e26435..a4a97bb 100644 --- a/i3pystatus/spotify.py +++ b/i3pystatus/spotify.py @@ -29,7 +29,11 @@ class Spotify(Module): def main_loop(self): """ Mainloop blocks so we thread it.""" self.player = Playerctl.Player() - self.player.on('metadata', self.on_track_change) + self.player.on('metadata', self.set_status) + + if self.player.props.status != "": + self.set_status(self.player) + main = GLib.MainLoop() main.run() @@ -44,18 +48,20 @@ class Spotify(Module): "color": "#FF0000" } - def on_track_change(self, player, e): + def set_status(self, player, e=None): artist = player.get_artist() title = player.get_title() album = player.get_album() volume = player.props.volume - time = e["mpris:length"] / 60.0e6 - minutes = math.floor(time) - seconds = round(time % 1 * 60) - if seconds < 10: - seconds = "0" + str(seconds) - length = "{}:{}".format(minutes, seconds) + length = "" + if e is not None: + time = e["mpris:length"] / 60.0e6 + minutes = math.floor(time) + seconds = round(time % 1 * 60) + if seconds < 10: + seconds = "0" + str(seconds) + length = "{}:{}".format(minutes, seconds) self.output = { "full_text": self.format.format(