musicpd namespace¶
- musicpd.CONNECTION_TIMEOUT = 30¶
Seconds before a connection attempt times out (overriden by MPD_TIMEOUT env. var.)
- musicpd.SOCKET_TIMEOUT = None¶
Socket timeout in second (Default is None for no timeout)
- class musicpd.MPDClient[source]¶
MPDClient instance will look for
MPD_HOST
/MPD_PORT
/XDG_RUNTIME_DIR
environment variables and set instance attributehost
,port
andpwd
accordingly. RegardingMPD_HOST
format to expose password refer MPD client manual mpc (1).Then
musicpd.MPDClient.connect
will usehost
andport
as defaults if not provided as args.Cf.
musicpd.MPDClient.connect
for details.>>> from os import environ >>> environ['MPD_HOST'] = 'pass@mpdhost' >>> cli = musicpd.MPDClient() >>> cli.pwd == environ['MPD_HOST'].split('@')[0] True >>> cli.host == environ['MPD_HOST'].split('@')[1] True >>> cli.connect() # will use host/port as set in MPD_HOST/MPD_PORT
- Variables
Warning
Instance attribute host/port/pwd
While
musicpd.MPDClient().host
andmusicpd.MPDClient().port
keep track of current connection host and port,musicpd.MPDClient().pwd
is set once with password extracted from environment variable. Callingmusicpd.MPDClient().password()
with a new password won’t updatemusicpd.MPDClient().pwd
value.Moreover,
musicpd.MPDClient().pwd
is only an helper attribute exposing password extracted fromMPD_HOST
environment variable, it will not be used as default value for thepassword()
method- mpd_timeout¶
Current connection timeout value, defaults to
CONNECTION_TIMEOUT
or env. var.MPD_TIMEOUT
if provided
- connect(host=None, port=None)[source]¶
Connects the MPD server
- Parameters
The connect method honors MPD_HOST/MPD_PORT environment variables.
The underlying socket also honors MPD_TIMEOUT environment variable and defaults to
musicpd.CONNECTION_TIMEOUT
(connect command only).If you want to have a timeout for each command once you got connected, set its value in
MPDClient.socket_timeout
(in second) or at module level inmusicpd.SOCKET_TIMEOUT
.Note
Default host/port
- property socket_timeout¶
Socket timeout in second (defaults to
SOCKET_TIMEOUT
). Use None to disable socket timout.
- disconnect()[source]¶
Closes the MPD connection. The client closes the actual socket, it does not use the ‘close’ request from MPD protocol (as suggested in documentation).
- fileno()[source]¶
Return the socket’s file descriptor (a small integer). This is useful with
select.select
.