Use persistent connections and fix issue with random mode detection

This commit is contained in:
Lucas Verney 2016-05-28 19:08:09 +02:00
parent 113340884e
commit f1a88818b6
2 changed files with 4 additions and 8 deletions

2
bliss

@ -1 +1 @@
Subproject commit 39fe24d79f2fa4e253a29e66f5f7c0c33e4b84d5 Subproject commit 4781124ff177fa1eb649b9b74993a0ae28b1e501

View File

@ -26,7 +26,7 @@ class PersistentMPDClient(mpd.MPDClient):
https://github.com/schamp/PersistentMPDClient/blob/master/PersistentMPDClient.py https://github.com/schamp/PersistentMPDClient/blob/master/PersistentMPDClient.py
""" """
def __init__(self, socket=None, host=None, port=None): def __init__(self, socket=None, host=None, port=None):
super(PersistentMPDClient, self).__init__() super().__init__()
self.socket = socket self.socket = socket
self.host = host self.host = host
self.port = port self.port = port
@ -45,10 +45,7 @@ class PersistentMPDClient(mpd.MPDClient):
if hasattr(super(PersistentMPDClient, self), cmd): if hasattr(super(PersistentMPDClient, self), cmd):
super_fun = super(PersistentMPDClient, self).__getattribute__(cmd) super_fun = super(PersistentMPDClient, self).__getattribute__(cmd)
new_fun = self.try_cmd(super_fun) new_fun = self.try_cmd(super_fun)
print("Setting interceptor for {}".format(cmd))
setattr(self, cmd, new_fun) setattr(self, cmd, new_fun)
else:
print("Attr {} not available!".format(cmd))
# create a wrapper for a function (such as an MPDClient # create a wrapper for a function (such as an MPDClient
# member function) that will verify a connection (and # member function) that will verify a connection (and
@ -120,8 +117,7 @@ def main(queue_length):
mpd_port = 6600 mpd_port = 6600
# Connect to MPD² # Connect to MPD²
client = PersistentMPDClient() client = PersistentMPDClient(host=mpd_host, port=mpd_port)
client.connect(mpd_host, mpd_port)
if mpd_password is not None: if mpd_password is not None:
client.password(mpd_password) client.password(mpd_password)
# Connect to db # Connect to db
@ -134,7 +130,7 @@ def main(queue_length):
# Ensure random is not enabled # Ensure random is not enabled
status = client.status() status = client.status()
if status["random"] != 0: if int(status["random"]) != 0:
logging.warning("Random mode is enabled. Are you sure you want it?") logging.warning("Random mode is enabled. Are you sure you want it?")
# Take the last song from current playlist and iterate from it # Take the last song from current playlist and iterate from it