Hack:mpd osd
From Music Player Daemon Community Wiki
This code will poll at regular interval (10 seconds by default) if the song title has changed and display it by OSD.
- Code :
#!/usr/bin/env python
# print the current played song by OSD
# depend on python-mpdclient2 and osd_cat (xosd_bin package)
# version 0.1 (public domain)
import sys, os, time, socket
import mpdclient2
Poll_delay = 10
Height = 200
Width = 60
Color = 'green'
Delay = 6
Font = '-adobe-helvetica-bold-r-normal-*-*-%i-*-*-p-*-iso10646-1' % Height
Options = "-f %s -d %i -s 2 -c %s -A center" % (Font, Delay, Color)
def error(s):
print >> sys.stderr, s
def connect():
global Poll_delay
while 1:
try:
m = mpdclient2.connect()
error("Connected.")
try:
test_loop(m, Poll_delay)
except EOFError:
error( "Connection to mpd lost, retrying...")
except socket.error:
error( "Connection to mpd impossible, retrying...")
time.sleep(5)
def osd_print(s):
global Options, Width
# the osd library is broken on my system :p
cmd = "echo %s | fold -s -w %i | osd_cat %s" % (repr(s), Width, Options)
os.system(cmd)
def test_loop(m, delay):
cur = ""
while 1:
try:
t = m.currentsong().title
except AttributeError:
# no title, try with the name
try:
t = m.currentsong().name + " -- No title"
except AttributeError:
t = "No title"
if cur != t:
osd_print( t )
cur = t
time.sleep( delay )
connect()
