summaryrefslogtreecommitdiff
path: root/nephilim/mpclient.py
diff options
context:
space:
mode:
authorAnton Khirnov <wyskas@gmail.com>2009-03-14 20:44:52 +0100
committerAnton Khirnov <wyskas@gmail.com>2009-03-14 20:44:52 +0100
commit5fcc05296c289c458f95815ea3eba3a48ee2938b (patch)
treeb3ce34e21ad4dde89a01fe084541f71fb60c3eef /nephilim/mpclient.py
parent647ca2cb8e69beb309cfe3babd9f56a994a7669b (diff)
Add basic support for password authentication.
Diffstat (limited to 'nephilim/mpclient.py')
-rw-r--r--nephilim/mpclient.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/nephilim/mpclient.py b/nephilim/mpclient.py
index c367204..0635a16 100644
--- a/nephilim/mpclient.py
+++ b/nephilim/mpclient.py
@@ -1,6 +1,7 @@
from PyQt4 import QtCore
import mpd
import socket
+import logging
from song import Song
@@ -24,8 +25,9 @@ class MPClient(QtCore.QObject):
self._cur_lib = []
self._cur_playlist = []
- def connect_mpd(self, host, port):
- """Connect to MPD@host:port. Returns Tue at success, False otherwise."""
+ def connect_mpd(self, host, port, password = None):
+ """Connect to MPD@host:port, optionally using password.
+ Returns Tue at success, False otherwise."""
if self._client:
return True
try:
@@ -35,6 +37,9 @@ class MPClient(QtCore.QObject):
self._client = None
return False
+ if password:
+ self.password(password)
+
self._status = MPClient._status
self._update_lib()
self._update_playlist()
@@ -52,6 +57,14 @@ class MPClient(QtCore.QObject):
self._client.disconnect()
self._client = None
+ def password(self, password):
+ """Use the password to authenticate with MPD."""
+ try:
+ self._client.password(password)
+ logging.info('Successfully authenticated')
+ except mpd.CommandError:
+ logging.error('Incorrect password.')
+
def is_connected(self):
"""Returns True if connected to MPD, False otherwise."""
return self._client != None