piripherals.mpd module

class piripherals.mpd.MPD(maxvol=100, *args, **kwargs)[source]

Bases: object

Wrapper for MPDClient that adds

  • automatic reconnect on connection loss, see issue64.
  • custom methods
  • volume limit

It supports all methods of MPDClient.

Parameters:
  • maxvol (int) – volume limit
  • *args – args for MPDClient
  • **kwargs – kwargs for MPDClient
connect(*args, **kwargs)[source]

establish connection

disconnects if already connected, host and port are stored, will reconnect automatically if connection is lost

All parameters are passed to MPDClient.connect().

Parameters:
  • host (str) – hostname/ip/socket
  • port (int) – port, usually 6600
current_playlist()[source]
del_playlist(name)[source]

delete playlist

if playlist exists, this does nothing

Parameters:name (str) – name of the playlist to delete
disconnect()[source]

disconnect, disables auto reconnect

find_next(*a)[source]
find_prev(*a)[source]
has_playlist(name)[source]

check for playlist

Parameters:name (str) – name of the playlist to look for
Returns:true if playlist exists
Return type:bool
load_playlist(name)[source]

load a playlist

  • replaces current playlist with the named playlist
  • if the given playlist does not exists, this does nothing
Parameters:name (str) – name of the playlist to load
save_playlist(name)[source]

save current playlist

if playlist exists, it will be overwritten

Parameters:name (str) – name of the playlist
state()[source]

current playback state

Returns:stop, play, pause
Return type:str
toggle_play()[source]

play or pause

  • start playing if stopped or paused
  • pause if playing
volume(v=None)[source]

adjust volume

Parameters:v – int = absolute volume 0-100, str = absolute volume or relative volume change if prefixed with + or -
Returns:volume if v was omitted
Return type:int
class piripherals.mpd.MPDPlaylist(mpd, field='title')[source]

Bases: object

the current playlist

Parameters:
  • mpd (MPD) – MPD instance to get the playlist from
  • field (str) – metadata field to look for when getting metadata for an playlist entry. If this field is not present, play the track to retrieve the metadata, then switch back to previous state
find_next(field='album')[source]

find next song with different field

Find the next song, where field has a different value than the currently playing song. With field='album', this gets the beginning of the next album.

If there is only a single album in the playlist or the currently playing song is of the last album, None is returned.

Returns:# of playlist entry or None
Return type:int
find_prev(field='album')[source]

find previous song with different field

Find the previous song, where field has a different value than the currently playing song. With field='album', this gets the beginning of the previous album.

If there is only a single album in the playlist or the currently playing song is of the first album, None is returned.

Returns:# of playlist entry or None
Return type:int
get(i, field=None)[source]

get metadata of playlist entry

Parameters:
  • i (int) – # of playlist entry
  • field (str) – metadata field to look for, if omitted, self.field is used