mpd-np.py --- little now playing script, for irssi or whatever
This commit is contained in:
parent
5456aa2728
commit
1539569958
52
mpd-np.py
Normal file
52
mpd-np.py
Normal 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
|
Loading…
Reference in New Issue
Block a user