add support for MPD connects via AF_UNIX sockets

A port number equal to 0 now lets the mpd module interpret the host as
a path to a socket.
This commit is contained in:
Philipp Edelmann 2016-01-22 23:24:18 +09:00
parent 3234897409
commit 45377b12c3

View File

@ -31,7 +31,7 @@ class MPD(IntervalModule):
settings = ( settings = (
("host"), ("host"),
("port", "MPD port"), ("port", "MPD port. If set to 0, host will we interpreted as a Unix socket."),
("format", "formatp string"), ("format", "formatp string"),
("status", "Dictionary mapping pause, play and stop to output"), ("status", "Dictionary mapping pause, play and stop to output"),
("color", "The color of the text"), ("color", "The color of the text"),
@ -64,7 +64,11 @@ class MPD(IntervalModule):
try: try:
sock.send((command + "\n").encode("utf-8")) sock.send((command + "\n").encode("utf-8"))
except Exception as e: except Exception as e:
self.s = socket.create_connection((self.host, self.port)) if self.port != 0:
self.s = socket.create_connection((self.host, self.port))
else:
self.s = socket.socket(family=socket.AF_UNIX)
self.s.connect(self.host)
sock = self.s sock = self.s
sock.recv(8192) sock.recv(8192)
sock.send((command + "\n").encode("utf-8")) sock.send((command + "\n").encode("utf-8"))