Skip to content

Instantly share code, notes, and snippets.

@nihilismus
Last active December 12, 2020 11:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nihilismus/8116120 to your computer and use it in GitHub Desktop.
Save nihilismus/8116120 to your computer and use it in GitHub Desktop.
A Python script to get artist, album and title from cmus and send it to stdout. Useful for conky
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# For conky's configuration file ($HOME/.conkyrc):
# ${if_running cmus}
# ${execi 03 (conky-cmus.py)}
# ${endif}
from subprocess import check_output
from re import match, compile
cmus_remote = check_output(['cmus-remote', '-Q'], universal_newlines=True)
status = cmus_remote.split('\n')[0].split()[1]
if status == 'playing':
l = []
p = compile('tag (artist|album|title|date|genre|tracknumber) ')
for e in cmus_remote.split('\n'):
if p.match(e):
l.append(p.sub('', e).title())
# l[0] is the "Artist", l[1] is the "Album" and l[2] is the "Title"
print("Playing: {0} ({1}) - {2}".format(l[0], l[1], l[2]))
else:
print("Stopped")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment