2 # -*- coding: utf-8 -*-
5 from socket import error as SocketError
8 from mpd import (MPDClient, CommandError)
9 except ImportError, err:
10 print 'ERROR: "%s"\n\nPlease install python-mpd module.\n' % err
14 def get_mpd_environ():#{{{
16 Retrieve MPD env. var.
18 con_id = dict({'host': 'localhost',
21 mpd_host_env = environ.get('MPD_HOST')
24 # mpd_host_env = ['pass', 'host'] because MPD_HOST=pass@host
25 mpd_host_env = mpd_host_env.split('@')
26 mpd_host_env.reverse()
27 con_id.update({'host': mpd_host_env[0]})
28 if len(mpd_host_env) > 1:
29 print 'passwd set in MPD_HOST'
30 passwd = mpd_host_env[1]
32 con_id.update({'port': int(environ.get('MPD_PORT', con_id.get('port')))})
33 return (con_id, passwd)#}}}
36 class MPDClass(object):
37 """Connect to MPD server
41 self.client = MPDClient()
43 def mpdConnect(self, con_id):#{{{
45 Simple wrapper to connect MPD.
48 self.client.connect(**con_id)
53 def mpdAuth(self, secret):#{{{
56 self.client.password(secret)
69 if __name__ == '__main__':
73 # vim: ai ts=4 sw=4 sts=4 expandtab