From 631c14889ed0684a0ca9ebbe4c491961f0d745df Mon Sep 17 00:00:00 2001 From: trollhase Date: Thu, 24 Oct 2013 13:38:58 +0200 Subject: [PATCH] Some fixes for MPD Database Reader --- mpddbreader.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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."