53 lines
1.1 KiB
Python
53 lines
1.1 KiB
Python
"""
|
|
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
|