diff --git a/mpd-np.py b/mpd-np.py new file mode 100644 index 0000000..aff0e1c --- /dev/null +++ b/mpd-np.py @@ -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