mirror of
https://github.com/beetbox/beets.git
synced 2026-01-09 09:22:55 +01:00
mpdupdate: Allow UNIX domain socket for MPD server
If the host configuration begins with a '/', it is assumed to reference a UNIX domain socket. This is similar to libmpdclient's behaviour.
This commit is contained in:
parent
dfda5a311d
commit
1bf8ae0a01
1 changed files with 8 additions and 7 deletions
|
|
@ -35,14 +35,16 @@ database_changed = False
|
|||
# easier.
|
||||
class BufferedSocket(object):
|
||||
"""Socket abstraction that allows reading by line."""
|
||||
def __init__(self, sep='\n'):
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
def __init__(self, host, port, sep='\n'):
|
||||
if host[0] == '/':
|
||||
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
self.sock.connect(host)
|
||||
else:
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.sock.connect((host, port))
|
||||
self.buf = ''
|
||||
self.sep = sep
|
||||
|
||||
def connect(self, host, port):
|
||||
self.sock.connect((host, port))
|
||||
|
||||
def readline(self):
|
||||
while self.sep not in self.buf:
|
||||
data = self.sock.recv(1024)
|
||||
|
|
@ -67,8 +69,7 @@ def update_mpd(host='localhost', port=6600, password=None):
|
|||
"""
|
||||
print('Updating MPD database...')
|
||||
|
||||
s = BufferedSocket()
|
||||
s.connect(host, port)
|
||||
s = BufferedSocket(host, port)
|
||||
resp = s.readline()
|
||||
if 'OK MPD' not in resp:
|
||||
print('MPD connection failed:', repr(resp))
|
||||
|
|
|
|||
Loading…
Reference in a new issue