Updated spotify module to check for metadata on start.

This commit is contained in:
Christopher Ganas 2015-01-04 16:07:25 -05:00
parent 0ff58efc69
commit 404c9ea348

View File

@ -29,7 +29,11 @@ class Spotify(Module):
def main_loop(self): def main_loop(self):
""" Mainloop blocks so we thread it.""" """ Mainloop blocks so we thread it."""
self.player = Playerctl.Player() 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 = GLib.MainLoop()
main.run() main.run()
@ -44,12 +48,14 @@ class Spotify(Module):
"color": "#FF0000" "color": "#FF0000"
} }
def on_track_change(self, player, e): def set_status(self, player, e=None):
artist = player.get_artist() artist = player.get_artist()
title = player.get_title() title = player.get_title()
album = player.get_album() album = player.get_album()
volume = player.props.volume volume = player.props.volume
length = ""
if e is not None:
time = e["mpris:length"] / 60.0e6 time = e["mpris:length"] / 60.0e6
minutes = math.floor(time) minutes = math.floor(time)
seconds = round(time % 1 * 60) seconds = round(time % 1 * 60)