mpd-np.py --- little now playing script, for irssi or whatever

This commit is contained in:
Brian S. Stephan 2012-07-19 13:22:11 -05:00
parent 5456aa2728
commit 1539569958
1 changed files with 52 additions and 0 deletions

52
mpd-np.py Normal file
View File

@ -0,0 +1,52 @@
"""
mpd-np.py --- little now playing script, for irssi or whatever
"""
import pexpect
HOST = 'localhost'
PORT = 6600
songinfo = {}
def get_title(child):
try:
child.sendline('currentsong')
child.expect('Title: ([^\r]+)', timeout=5)
except pexpect.TIMEOUT:
return
songinfo['title'] = child.match.group(1)
def get_artist(child):
try:
child.sendline('currentsong')
child.expect('Artist: ([^\r]+)', timeout=5)
except pexpect.TIMEOUT:
return
songinfo['artist'] = child.match.group(1)
def get_album(child):
try:
child.sendline('currentsong')
child.expect('Album: ([^\r]+)', timeout=5)
except pexpect.TIMEOUT:
return
songinfo['album'] = child.match.group(1)
try:
child = pexpect.spawn('telnet ' + HOST + ' ' + str(PORT))
child.expect('OK MPD 0.17.0')
except pexpect.TIMEOUT:
pass
else:
get_title(child)
get_artist(child)
get_album(child)
print('{0:s} - [{1:s}] {2:s}'.format(songinfo['artist'], songinfo['album'], songinfo['title']))
# vi:tabstop=4:expandtab:autoindent