Don't create new socket for every MPD query

This commit is contained in:
siikamiika 2014-03-08 03:05:01 +02:00
parent 07fbfc6640
commit 850501430d

View File

@ -41,6 +41,8 @@ class MPD(IntervalModule):
host = "localhost"
port = 6600
s = socket.create_connection((host, port))
s.recv(8192)
format = "{title} {status}"
format_sparse = None
status = {
@ -65,14 +67,10 @@ class MPD(IntervalModule):
self.format_sparse = self.format
def run(self):
with socket.create_connection((self.host, self.port)) as s:
# Skip "OK MPD ..."
s.recv(8192)
fdict = {}
status = self._mpd_command(s, "status")
currentsong = self._mpd_command(s, "currentsong")
status = self._mpd_command(self.s, "status")
currentsong = self._mpd_command(self.s, "currentsong")
fdict = {
"pos": int(status.get("song", 0)) + 1,