Some fixes for MPD Database Reader

This commit is contained in:
trollhase 2013-10-24 13:38:58 +02:00
parent 5ba42fb745
commit 631c14889e

View file

@ -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."