musicpd namespace¶
Python Music Player Daemon client library
- musicpd.VERSION = '0.9.2'¶
Module version
- musicpd.CONNECTION_TIMEOUT = 30¶
Seconds before a connection attempt times out (overriden by
MPD_TIMEOUTenv. var.)
- class musicpd.MPDClient[source]¶
MPDClient instance will look for
MPD_HOST/MPD_PORT/XDG_RUNTIME_DIRenvironment variables and set instance attributehost,portandpwdaccordingly.Then
musicpd.MPDClient.connectwill usehostandportas defaults if not provided as args.Regarding
MPD_HOSTformat to expose password refer this module documentation or MPD client manual mpc (1).>>> 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
Note
- default host:
use
MPD_HOSTenvironment variable if set, extract password if present,else use
XDG_RUNTIME_DIRto looks for an existing file in${XDG_RUNTIME_DIR:-/run/}/mpd/socketelse set host to
localhost
- default port:
use
MPD_PORTenvironment variable is setelse use
6600
Warning
Instance attribute host/port/pwd
While
musicpd.MPDClient.hostandmusicpd.MPDClient.portkeep track of current connection host and port,musicpd.MPDClient.pwdis set once with password extracted from environment variable. Calling MPS’s password method with a new password won’t updatemusicpd.MPDClient.pwdvalue.Moreover,
musicpd.MPDClient.pwdis only an helper attribute exposing password extracted fromMPD_HOSTenvironment variable, it will not be used as default value for the MPD’s password command.- mpd_timeout¶
Current connection timeout value, defaults to
CONNECTION_TIMEOUTor env. var.MPD_TIMEOUTif provided
- mpd_version¶
Protocol version as exposed by the server as a
strNote
This is the version of the protocol spoken, not the real version of the daemon.
- connect(host=None, port=None)[source]¶
Connects the MPD server
- Parameters:
If host/port are
Nonethe socket useshost/portattributes as defaults. Cf.MPDClientfor the logic behind default host/port.The underlying socket also honors
MPD_TIMEOUTenvironment variable and defaults tomusicpd.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.
- property socket_timeout¶
Socket timeout in second (defaults to
SOCKET_TIMEOUT). UseNoneto disable socket timout.- Setter:
Set the socket timeout (integer > 0)
- Type:
int or None
- 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.