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,18 +48,20 @@ 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
time = e["mpris:length"] / 60.0e6 length = ""
minutes = math.floor(time) if e is not None:
seconds = round(time % 1 * 60) time = e["mpris:length"] / 60.0e6
if seconds < 10: minutes = math.floor(time)
seconds = "0" + str(seconds) seconds = round(time % 1 * 60)
length = "{}:{}".format(minutes, seconds) if seconds < 10:
seconds = "0" + str(seconds)
length = "{}:{}".format(minutes, seconds)
self.output = { self.output = {
"full_text": self.format.format( "full_text": self.format.format(