Make now_playing segment accept state symbols from arguments
This commit is contained in:
parent
37b1f967a2
commit
759b42a823
|
@ -896,29 +896,30 @@ Highlight groups used: ``email_alert_gradient`` (gradient), ``email_alert``.
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
|
||||||
class NowPlayingSegment(object):
|
STATE_SYMBOLS = {
|
||||||
STATE_SYMBOLS = {
|
'fallback': '♫',
|
||||||
'fallback': '♫',
|
'play': '▶',
|
||||||
'play': '▶',
|
'pause': '▮▮',
|
||||||
'pause': '▮▮',
|
'stop': '■',
|
||||||
'stop': '■',
|
}
|
||||||
}
|
|
||||||
|
|
||||||
def __call__(self, player='mpd', format='{state_symbol} {artist} - {title} ({total})', **kwargs):
|
|
||||||
|
class NowPlayingSegment(object):
|
||||||
|
def __call__(self, player='mpd', format='{state_symbol} {artist} - {title} ({total})', state_symbols=STATE_SYMBOLS, **kwargs):
|
||||||
player_func = getattr(self, 'player_{0}'.format(player))
|
player_func = getattr(self, 'player_{0}'.format(player))
|
||||||
stats = {
|
stats = {
|
||||||
'state': None,
|
'state': 'fallback',
|
||||||
'state_symbol': self.STATE_SYMBOLS['fallback'],
|
|
||||||
'album': None,
|
'album': None,
|
||||||
'artist': None,
|
'artist': None,
|
||||||
'title': None,
|
'title': None,
|
||||||
'elapsed': None,
|
'elapsed': None,
|
||||||
'total': None,
|
'total': None,
|
||||||
}
|
}
|
||||||
func_stats = player_func(**kwargs)
|
func_stats = player_func(state_symbol=state_symbols, **kwargs)
|
||||||
if not func_stats:
|
if not func_stats:
|
||||||
return None
|
return None
|
||||||
stats.update(func_stats)
|
stats.update(func_stats)
|
||||||
|
stats['state_symbol'] = state_symbols.get(stats['state'])
|
||||||
return format.format(**stats)
|
return format.format(**stats)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -965,7 +966,6 @@ class NowPlayingSegment(object):
|
||||||
state = self._convert_state(now_playing.get('status'))
|
state = self._convert_state(now_playing.get('status'))
|
||||||
return {
|
return {
|
||||||
'state': state,
|
'state': state,
|
||||||
'state_symbol': self.STATE_SYMBOLS.get(state),
|
|
||||||
'album': now_playing.get('album'),
|
'album': now_playing.get('album'),
|
||||||
'artist': now_playing.get('artist'),
|
'artist': now_playing.get('artist'),
|
||||||
'title': now_playing.get('title'),
|
'title': now_playing.get('title'),
|
||||||
|
@ -998,7 +998,6 @@ class NowPlayingSegment(object):
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
return {
|
return {
|
||||||
'state': status.get('state'),
|
'state': status.get('state'),
|
||||||
'state_symbol': self.STATE_SYMBOLS.get(status.get('state')),
|
|
||||||
'album': now_playing.get('album'),
|
'album': now_playing.get('album'),
|
||||||
'artist': now_playing.get('artist'),
|
'artist': now_playing.get('artist'),
|
||||||
'title': now_playing.get('title'),
|
'title': now_playing.get('title'),
|
||||||
|
@ -1027,7 +1026,6 @@ class NowPlayingSegment(object):
|
||||||
state = self._convert_state(status)
|
state = self._convert_state(status)
|
||||||
return {
|
return {
|
||||||
'state': state,
|
'state': state,
|
||||||
'state_symbol': self.STATE_SYMBOLS.get(state),
|
|
||||||
'album': info.get('xesam:album'),
|
'album': info.get('xesam:album'),
|
||||||
'artist': info.get('xesam:artist')[0],
|
'artist': info.get('xesam:artist')[0],
|
||||||
'title': info.get('xesam:title'),
|
'title': info.get('xesam:title'),
|
||||||
|
@ -1074,7 +1072,6 @@ class NowPlayingSegment(object):
|
||||||
return None
|
return None
|
||||||
return {
|
return {
|
||||||
'state': state,
|
'state': state,
|
||||||
'state_symbol': self.STATE_SYMBOLS.get(state),
|
|
||||||
'album': spotify_status[1],
|
'album': spotify_status[1],
|
||||||
'artist': spotify_status[2],
|
'artist': spotify_status[2],
|
||||||
'title': spotify_status[3],
|
'title': spotify_status[3],
|
||||||
|
|
Loading…
Reference in New Issue