music.mpd#

class platypush.plugins.music.mpd.MusicMpdPlugin(host, port=6600)[source]#

Bases: MusicPlugin

This plugin allows you to interact with an MPD/Mopidy music server. MPD (https://www.musicpd.org/) is a flexible server-side protocol/application for handling music collections and playing music, mostly aimed to manage local libraries. Mopidy (https://www.mopidy.com/) is an evolution of MPD, compatible with the original protocol and with support for multiple music sources through plugins (e.g. Spotify, TuneIn, Soundcloud, local files etc.).

NOTE: As of Mopidy 3.0 MPD is an optional interface provided by the mopidy-mpd extension. Make sure that you have the extension installed and enabled on your instance to use this plugin with your server.

Requires:

  • python-mpd2 (pip install python-mpd2)

__init__(host, port=6600)[source]#
Parameters:
  • host (str) – MPD IP/hostname

  • port (int) – MPD port (default: 6600)

add(resource, position=None)[source]#

Add a resource (track, album, artist, folder etc.) to the current playlist

Parameters:
  • resource (str) – Resource path or URI

  • position (int) – Position where the track(s) will be inserted (default: end of the playlist)

add_to_playlist(playlist, resources)[source]#

Add one or multiple resources to a playlist.

Parameters:
  • playlist (str) – Playlist name

  • resources (str or list[str]) – URI or path of the resource(s) to be added

back()[source]#

Go backward by 15 seconds

clear()[source]#

Clear the current playlist

consume(value=None)[source]#

Set consume mode

Parameters:

value (bool) – If set, set the consume state this value (true/false). Default: None (toggle current state)

current_track()[source]#
Returns:

The currently played track.

Example response:

output = {
    "file": "spotify:track:7CO5ADlDN3DcR2pwlnB14P",
    "time": "255",
    "artist": "Elbow",
    "album": "Little Fictions",
    "title": "Kindling",
    "date": "2017",
    "track": "10",
    "pos": "9",
    "id": "3061",
    "albumartist": "Elbow",
    "x-albumuri": "spotify:album:6q5KhDhf9BZkoob7uAnq19"
}
currentsong()[source]#

Legacy alias for current_track().

delete(positions)[source]#

Delete the playlist item(s) in the specified position(s).

Parameters:

positions (list[int]) – Positions of the tracks to be removed

Returns:

The modified playlist

find(filter: dict, *args, **kwargs)[source]#

Find in the database/library by filter.

Parameters:

filter – Search filter (e.g. {"artist": "Led Zeppelin", "album": "IV"})

Returns:

list[dict]

findadd(filter: dict, *args, **kwargs)[source]#

Find in the database/library by filter and add to the current playlist.

Parameters:

filter – Search filter (e.g. {"artist": "Led Zeppelin", "album": "IV"})

Returns:

list[dict]

forward()[source]#

Go forward by 15 seconds

get_playlist(playlist, with_tracks=False)[source]#

List the items in the specified playlist.

Parameters:
  • playlist (str) – Name of the playlist

  • with_tracks (bool) – If True then the list of tracks in the playlist will be returned as well (default: False).

get_playlists()[source]#
Returns:

The playlists available on the server as a list of dicts.

Example response:

output = [
    {
        "playlist": "Rock",
        "last-modified": "2018-06-25T21:28:19Z"
    },
    {
        "playlist": "Jazz",
        "last-modified": "2018-06-24T22:28:29Z"
    },
    {
        # ...
    }
]
listplaylist(name)[source]#

Deprecated alias for playlist().

listplaylistinfo(name)[source]#

Deprecated alias for playlist() with with_tracks=True.

listplaylists()[source]#

Deprecated alias for playlists().

load(playlist, play=True)[source]#

Load and play a playlist by name

Parameters:
  • playlist (str) – Playlist name

  • play (bool) – Start playback after loading the playlist (default: True)

lsinfo(uri=None)[source]#

Returns the list of playlists and directories on the server

move(from_pos, to_pos)[source]#

Move the playlist item in position <from_pos> to position <to_pos>

Parameters:
  • from_pos (int) – Track current position

  • to_pos (int) – Track new position

next()[source]#

Play the next track

pause()[source]#

Pause playback

pause_if_playing()[source]#

Pause playback only if it’s playing

play(resource=None)[source]#

Play a resource by path/URI

Parameters:

resource (str) – Resource path/URI

play_if_paused()[source]#

Play only if it’s paused (resume)

play_if_paused_or_stopped()[source]#

Play only if it’s paused or stopped

play_or_stop()[source]#

Play or stop (play state toggle)

play_pos(pos)[source]#

Play a track in the current playlist by position number

Parameters:

pos – Position number

playid(track_id)[source]#

Play a track by ID

Parameters:

track_id (str) – Track ID

playlist_move(playlist, from_pos, to_pos)[source]#

Change the position of a track in the specified playlist.

Parameters:
  • playlist (str) – Playlist name

  • from_pos (int) – Original track position

  • to_pos (int) – New track position

playlistadd(name, uri)[source]#

Deprecated alias for add_to_playlist().

playlistclear(name)[source]#

Clears all the elements from the specified playlist

Parameters:

name (str) – Playlist name

playlistdelete(name, pos)[source]#

Deprecated alias for remove_from_playlist().

playlistinfo()[source]#
Returns:

The tracks in the current playlist as a list of dicts.

Example output:

output = [
    {
        "file": "spotify:track:79VtgIoznishPUDWO7Kafu",
        "time": "355",
        "artist": "Elbow",
        "album": "Little Fictions",
        "title": "Trust the Sun",
        "date": "2017",
        "track": "3",
        "pos": "10",
        "id": "3062",
        "albumartist": "Elbow",
        "x-albumuri": "spotify:album:6q5KhDhf9BZkoob7uAnq19"
    },
    {
        "file": "spotify:track:3EzTre0pxmoMYRuhJKMHj6",
        "time": "219",
        "artist": "Elbow",
        "album": "Little Fictions",
        "title": "Gentle Storm",
        "date": "2017",
        "track": "2",
        "pos": "11",
        "id": "3063",
        "albumartist": "Elbow",
        "x-albumuri": "spotify:album:6q5KhDhf9BZkoob7uAnq19"
    },
]
playlistmove(name, from_pos, to_pos)[source]#

Deprecated alias for playlist_move().

plchanges(version)[source]#

Show what has changed on the current playlist since a specified playlist version number.

Parameters:

version (int) – Version number

Returns:

A list of dicts representing the songs being added since the specified version

previous()[source]#

Play the previous track

random(value=None)[source]#

Set random mode

Parameters:

value (bool) – If set, set the random state this value (true/false). Default: None (toggle current state)

remove_from_playlist(playlist, resources)[source]#

Remove one or multiple tracks from a playlist.

Parameters:
  • playlist (str) – Playlist name

  • resources (int or list[int]) – Position or list of positions to remove

rename(name, new_name)[source]#

Rename a playlist

Parameters:
  • name (str) – Original playlist name

  • new_name – New playlist name

repeat(value=None)[source]#

Set repeat mode

Parameters:

value (bool) – If set, set the repeat state this value (true/false). Default: None (toggle current state)

rm(playlist)[source]#

Permanently remove playlist(s) by name

Parameters:

playlist (str or list[str]) – Name or list of playlist names to remove

save(name)[source]#

Save the current tracklist to a new playlist with the specified name

Parameters:

name (str) – Name of the playlist

search(query: str | dict | None = None, filter: dict | None = None, *args, **kwargs)[source]#

Free search by filter.

Parameters:
  • query – Free-text query or search structured filter (e.g. {"artist": "Led Zeppelin", "album": "IV"}).

  • filter – Structured search filter (e.g. {"artist": "Led Zeppelin", "album": "IV"}) - same as query, it’s still here for back-compatibility reasons.

Returns:

list[dict]

searchadd(filter, *args, **kwargs)[source]#

Free search by filter and add the results to the current playlist.

Parameters:

filter – Search filter (e.g. {"artist": "Led Zeppelin", "album": "IV"})

Returns:

list[dict]

searchaddplaylist(name)[source]#

Search and add a playlist by (partial or full) name

Parameters:

name (str) – Playlist name, can be partial

seek(position)[source]#

Seek to the specified position

Parameters:

position – Seek position in seconds, or delta string (e.g. ‘+15’ or ‘-15’) to indicate a seek relative to the current position :type position: int

seekcur(value)[source]#

Seek to the specified position (DEPRECATED, use seek() instead).

Parameters:

value – Seek position in seconds, or delta string (e.g. ‘+15’ or ‘-15’) to indicate a seek relative to the current position :type value: int

set_volume(volume)[source]#

Set the volume.

Parameters:

volume (int) – Volume value (range: 0-100)

setvol(vol)[source]#

Set the volume (DEPRECATED, use set_volume() instead).

Parameters:

vol (int) – Volume value (range: 0-100)

shuffle()[source]#

Shuffles the current playlist

single(value=None)[source]#

Set single mode

Parameters:

value (bool) – If set, set the consume state this value (true/false). Default: None (toggle current state)

status()[source]#
Returns:

The current state.

Example response:

output = {
    "volume": "9",
    "repeat": "0",
    "random": "0",
    "single": "0",
    "consume": "0",
    "playlist": "52",
    "playlistlength": "14",
    "xfade": "0",
    "state": "play",
    "song": "9",
    "songid": "3061",
    "nextsong": "10",
    "nextsongid": "3062",
    "time": "161:255",
    "elapsed": "161.967",
    "bitrate": "320"
}
stop()[source]#

Stop playback

voldown(delta=10)[source]#

Turn down the volume

Parameters:

delta (int) – Volume down delta (default: -10%)

volup(delta=10)[source]#

Turn up the volume

Parameters:

delta (int) – Volume up delta (default: +10%)