Some fixes for MPD Database Reader
This commit is contained in:
parent
5ba42fb745
commit
631c14889e
1 changed files with 8 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
import socket
|
import socket
|
||||||
|
from sys import exit
|
||||||
|
|
||||||
class LineReader(object):
|
class LineReader(object):
|
||||||
def __init__(self, source):
|
def __init__(self, source):
|
||||||
|
@ -12,7 +13,7 @@ class LineReader(object):
|
||||||
return None
|
return None
|
||||||
self.buffer += data
|
self.buffer += data
|
||||||
|
|
||||||
pos = self.buffer.pos("\n")
|
pos = self.buffer.find("\n")
|
||||||
line, self.buffer = self.buffer[:pos], self.buffer[pos+1:]
|
line, self.buffer = self.buffer[:pos], self.buffer[pos+1:]
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
@ -71,10 +72,15 @@ class MPDConnection(object):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
c = MPDConnection(('10.0.0.1',6600))
|
c = MPDConnection(('10.0.0.1',6600))
|
||||||
|
except Exception,e:
|
||||||
|
print "Could not connect: "+str(e)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
for song in c.run("listallinfo",HashListCommandReader()):
|
for song in c.run("listallinfo",HashListCommandReader()):
|
||||||
artist = song['artist'] if 'artist' in song else "Unknown"
|
artist = song['artist'] if 'artist' in song else "Unknown"
|
||||||
title = song['title'] if 'title' in song else "Unknown"
|
title = song['title'] if 'title' in song else "Unknown"
|
||||||
print "%s - %s" % (artist,song)
|
print "%s - %s" % (artist,title)
|
||||||
finally:
|
finally:
|
||||||
c.close()
|
c.close()
|
||||||
print "Terminated."
|
print "Terminated."
|
||||||
|
|
Loading…
Reference in a new issue