diff --git a/mpddbreader.py b/mpddbreader.py index c0c56ca..c1d26b7 100644 --- a/mpddbreader.py +++ b/mpddbreader.py @@ -1,4 +1,5 @@ import socket +from sys import exit class LineReader(object): def __init__(self, source): @@ -12,7 +13,7 @@ class LineReader(object): return None self.buffer += data - pos = self.buffer.pos("\n") + pos = self.buffer.find("\n") line, self.buffer = self.buffer[:pos], self.buffer[pos+1:] return line @@ -71,10 +72,15 @@ class MPDConnection(object): if __name__ == '__main__': try: 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()): artist = song['artist'] if 'artist' in song else "Unknown" title = song['title'] if 'title' in song else "Unknown" - print "%s - %s" % (artist,song) + print "%s - %s" % (artist,title) finally: c.close() print "Terminated."