aboutsummaryrefslogtreecommitdiff
path: root/i3/bin/i3status.py
diff options
context:
space:
mode:
Diffstat (limited to 'i3/bin/i3status.py')
-rwxr-xr-xi3/bin/i3status.py51
1 files changed, 48 insertions, 3 deletions
diff --git a/i3/bin/i3status.py b/i3/bin/i3status.py
index ce562b1..1a2d166 100755
--- a/i3/bin/i3status.py
+++ b/i3/bin/i3status.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
import json
from select import select
-from subprocess import Popen, PIPE
+from subprocess import check_output, Popen, PIPE
import sys
def remove_empty_outputs(obj):
@@ -33,6 +33,46 @@ def parse_kbdlayout(s):
color = '#cccccc'
return [{'full_text': s, 'color': color}]
+def print_album_and_artist(info, parentheses):
+ if 'album' in info:
+ if 'artist' in info:
+ if parentheses:
+ return info['album'] + ' (' + info['artist'] + ')'
+ else:
+ return info['album'] + ', ' + info['artist']
+ else:
+ return info['album']
+ elif 'artist' in info:
+ return info['artist']
+ else:
+ return None
+
+def get_cmus_song():
+ result = check_output(['cmus-remote', '-Q'])
+ info = {}
+ for line in result.split('\n'):
+ if line[:10] == 'tag title ':
+ info['title'] = line[10:]
+ elif line[:10] == 'tag album ':
+ info['album'] = line[10:]
+ elif line[:11] == 'tag artist ':
+ info['artist'] = line[11:]
+
+ album_and_artist = print_album_and_artist(info, 'title' not in info)
+ text = None
+ if album_and_artist is None:
+ if 'title' in info:
+ text = info['title']
+ elif 'title' in info:
+ text = info['title'] + ' (' + album_and_artist + ')'
+ else:
+ text = album_and_artist
+
+ if text is None:
+ return []
+ else:
+ return [{'full_text': text}]
+
def merge_status_items(*args):
return [item for sublist in args for item in sublist]
@@ -47,7 +87,7 @@ if __name__ == '__main__':
sys.stdout.write(i3stat.stdout.readline())
sys.stdout.write(i3stat.stdout.readline())
- stat, kbd, clg = [], [], []
+ stat, kbd, cmus = [], [], []
try:
stdouts = [p.stdout for p in [i3stat, kbdlayout]]
while True:
@@ -58,8 +98,13 @@ if __name__ == '__main__':
kbd = parse_kbdlayout(line)
elif f == i3stat.stdout:
stat = parse_i3stat(line)
+
+ try:
+ cmus = get_cmus_song()
+ except:
+ cmus = []
- print_i3stat(merge_status_items(kbd, clg, stat))
+ print_i3stat(merge_status_items(kbd, cmus, stat))
except Exception, e:
print(e)