Wednesday, January 15, 2014

cmus player on-screen display in python

I'm actively using the C* music player (cmus) as my main music player on my working machine. It's a powerful console music player which suits best especially I mainly work in consoles. However it would be convenient if there is on-screen display (OSD) on my Gnome desktop when I am working on another window/console.

Here is a version implemented in python using the notify-send program:

status_display.sh

#!/bin/sh ~/.cmus/status_notify.py "$@" > ~/.cmus/statusinfo&
status_notify.py

#!/usr/bin/env python """ ============================================ CMUS status update program using notify-send ============================================ Example status update as program's parameter list status playing file /data/music/Zeb-Jesterized/12-Zeb-Spy From Cairo.mp3 artist Zeb album Jesterized tracknumber 12 title Spy From Cairo date 2000 duration 322 Usage: Create a shell script at ~/.cmus/status_display_program.sh and 'chmod +x' it: #!/bin/sh program1 "$@" & (replace program1 with path to this script) In CMUS: :set status_display_program=/home/user/.cmus/status_display_program.sh Reference: http://cmus.sourceforge.net/wiki/doku.php?id=status_display_programs """ import sys, os from subprocess import call if __name__ == '__main__': # basic checking if len(sys.argv) % 2 != 1 or len(sys.argv) < 2 \ or sys.argv[1] != 'status': raise Exception('please set this program as CMUS status update program') # make it a dict s = sys.argv[1:] status = dict(zip(s[::2], s[1::2])) osd_info = "[%s] %s (%s-%s)" % \ ( status['status'], os.path.basename(status['file']), status['artist'], status['title'] ) # --hint parameter is for gnome-shell's buggy notification.. anyway call(['notify-send', '--hint=int:transient:1', osd_info])

No comments:

Post a Comment