Don't create new socket for every MPD query
This commit is contained in:
parent
07fbfc6640
commit
850501430d
@ -41,6 +41,8 @@ class MPD(IntervalModule):
|
|||||||
|
|
||||||
host = "localhost"
|
host = "localhost"
|
||||||
port = 6600
|
port = 6600
|
||||||
|
s = socket.create_connection((host, port))
|
||||||
|
s.recv(8192)
|
||||||
format = "{title} {status}"
|
format = "{title} {status}"
|
||||||
format_sparse = None
|
format_sparse = None
|
||||||
status = {
|
status = {
|
||||||
@ -65,14 +67,10 @@ class MPD(IntervalModule):
|
|||||||
self.format_sparse = self.format
|
self.format_sparse = self.format
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
with socket.create_connection((self.host, self.port)) as s:
|
|
||||||
# Skip "OK MPD ..."
|
|
||||||
s.recv(8192)
|
|
||||||
|
|
||||||
fdict = {}
|
fdict = {}
|
||||||
|
|
||||||
status = self._mpd_command(s, "status")
|
status = self._mpd_command(self.s, "status")
|
||||||
currentsong = self._mpd_command(s, "currentsong")
|
currentsong = self._mpd_command(self.s, "currentsong")
|
||||||
|
|
||||||
fdict = {
|
fdict = {
|
||||||
"pos": int(status.get("song", 0)) + 1,
|
"pos": int(status.get("song", 0)) + 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user