protocol.rst 43.8 KB
Newer Older
1 2 3
########
Protocol
########
4 5

General protocol syntax
6
***********************
7 8 9 10

Protocol overview
=================

11
The :program:`MPD` command protocol exchanges
12 13 14 15 16
line-based text records between client and server over TCP.
Once the client is connected to the server, they conduct a
conversation until the client closes the connection. The
conversation flow is always initiated by the client.

17 18 19
All data between the client and the server is encoded in
UTF-8.

20 21 22 23 24 25
The client transmits a command sequence, terminated by the
newline character ``\n``.  The server will
respond with one or more lines, the last of which will be a
completion code.

When the client connects to the server, the server will answer
26
with the following line::
27

28
 OK MPD version
29 30 31 32 33 34 35 36 37

where ``version`` is a version identifier such as
0.12.2.  This version identifier is the version of the protocol
spoken, not the real version of the daemon.  (There is no way to
retrieve this real version identifier from the connection.)

Requests
========

38 39 40
.. code-block:: none

 COMMAND [ARG...]
41 42 43 44 45 46 47 48 49 50 51 52 53 54

If arguments contain spaces, they should be surrounded by double
quotation marks.

Argument strings are separated from the command and any other
arguments by linear white-space (' ' or '\\t').

Responses
=========

A command returns ``OK`` on completion or
``ACK some error`` on failure.  These
denote the end of command execution.

55 56 57 58 59 60 61 62 63 64 65 66 67
Some commands return more data before the response ends with ``OK``.
Each line is usually in the form ``NAME: VALUE``.  Example::

  foo: bar
  OK

.. _binary:

Binary Responses
----------------

Some commands can return binary data.  This is initiated by a line
containing ``binary: 1234`` (followed as usual by a newline).  After
68 69
that, the specified number of bytes of binary data follows, then a
newline, and finally the ``OK`` line.  Example::
70 71 72

  foo: bar
  binary: 42
73 74
  <42 bytes>
  OK
75 76


77 78 79 80 81 82 83
Failure responses
-----------------

The nature of the error can be gleaned from the information
that follows the ``ACK``.
``ACK`` lines are of the form:

84 85 86
.. code-block:: none

 ACK [error@command_listNum] {current_command} message_text
87 88 89 90 91 92 93 94 95

These responses are generated by a call to
``commandError``. They contain four separate
terms. Let's look at each of them:

- ``error``: numeric value of one
  of the ``ACK_ERROR`` constants defined
  in `src/protocol/Ack.hxx`.

96 97 98
- ``command_listNum``: offset of the command that caused the error in
  a :ref:`Command List <command_lists>`.  An error will always cause a
  command list to terminate at the command that causes the error.
99

100 101
- ``current_command``: name of the command, in a :ref:`Command List
  <command_lists>`, that was executing when the error occurred.
102 103 104 105 106

- ``message_text``:
  some (hopefully) informative text that describes the
  nature of the error.

107 108
An example might help.  Consider the following sequence
sent from the client to the server::
109

110 111 112 113 114
 command_list_begin
 volume 86
 play 10240
 status
 command_list_end
115

116
The server responds with::
117

118
 ACK [50@1] {play} song doesn't exist: "10240"
119

120 121 122 123 124
This tells us that the play command, which was the second in the list
(the first or only command is numbered 0), failed with error 50.  The
number 50 translates to ``ACK_ERROR_NO_EXIST`` -- the song doesn't
exist.  This is reiterated by the message text which also tells us
which song doesn't exist.
125 126 127 128 129 130 131 132 133 134 135 136

.. _command_lists:

Command lists
=============

To facilitate faster adding of files etc. you can pass a list
of commands all at once using a command list.  The command
list begins with `command_list_begin` or
`command_list_ok_begin` and ends with
`command_list_end`.

137 138 139
It does not execute any commands until the list has ended.  The
response is a concatentation of all individual responses.
On success for all commands,
140 141 142 143 144 145 146 147 148 149
``OK`` is returned.  If a command
fails, no more commands are executed and the appropriate
``ACK`` error is returned. If
`command_list_ok_begin` is used,
``list_OK`` is returned for each
successful command executed in the command list.

Ranges
======

150 151 152 153
Some commands (e.g. :ref:`delete <command_delete>`) allow specifying a
range in the form ``START:END`` (the ``END`` item is not included in
the range, similar to ranges in the Python programming language).  If
``END`` is omitted, then the maximum possible value is assumed.
154 155 156 157 158 159

.. _filter_syntax:

Filters
=======

160 161 162
All commands which search for songs (e.g. :ref:`find <command_find>`
and :ref:`searchadd <command_searchadd>`) share a common filter
syntax::
163

164
 find EXPRESSION
165

166 167
``EXPRESSION`` is a string enclosed in parantheses which can be one
of:
168

169 170 171 172
- ``(TAG == 'VALUE')``: match a tag value; if there are multiple
  values of the given type, at least one must match.
  ``(TAG != 'VALUE')``: mismatch a tag value; if there are multiple
  values of the given type, none of them must match.
173
  The special tag ``any`` checks all
174
  tag types.
175
  ``AlbumArtist`` looks for
176 177 178
  ``VALUE`` in ``AlbumArtist``
  and falls back to ``Artist`` tags if
  ``AlbumArtist`` does not exist.
179
  ``VALUE`` is what to find.
180 181 182
  An empty value string means: match only if the given tag type does
  not exist at all; this implies that negation with an empty value
  checks for the existence of the given tag type.
183

184 185 186
- ``(TAG contains 'VALUE')`` checks if the given value is a substring
  of the tag value.

187 188 189 190 191
- ``(TAG =~ 'VALUE')`` and ``(TAG !~ 'VALUE')`` use a Perl-compatible
  regular expression instead of doing a simple string comparison.
  (This feature is only available if :program:`MPD` was compiled with
  :file:`libpcre`)

192 193 194 195 196 197 198 199 200 201 202
- ``(file == 'VALUE')``: match the full song URI
  (relative to the music directory).

- ``(base 'VALUE')``: restrict the search to
  songs in the given directory (relative to the music
  directory).

- ``(modified-since 'VALUE')``: compares the
  file's time stamp with the given value (ISO 8601 or UNIX
  time stamp).

203 204 205
- ``(AudioFormat == 'SAMPLERATE:BITS:CHANNELS')``: compares the audio
  format with the given value.  See :ref:`audio_output_format` for a
  detailed explanation.
206 207 208

- ``(AudioFormat =~ 'SAMPLERATE:BITS:CHANNELS')``:
  matches the audio format with the given mask (i.e. one
209
  or more attributes may be ``*``).
210

211 212 213
- ``(!EXPRESSION)``: negate an expression.  Note that each expression
  must be enclosed in parantheses, e.g. :code:`(!(artist == 'VALUE'))`
  (which is equivalent to :code:`(artist != 'VALUE')`)
214 215

- ``(EXPRESSION1 AND EXPRESSION2 ...)``: combine two or
216 217 218
  more expressions with logical "and".  Note that each expression must
  be enclosed in parantheses, e.g. :code:`((artist == 'FOO') AND
  (album == 'BAR'))`
219

220 221 222
The :command:`find` commands are case sensitive, which
:command:`search` and related commands ignore case.

223
Prior to MPD 0.21, the syntax looked like this::
224

225
 find TYPE VALUE
226

227 228 229 230 231 232 233 234 235 236 237
Escaping String Values
----------------------

String values are quoted with single or double quotes, and special
characters within those values must be escaped with the backslash
(``\``).  Keep in mind that the backslash is also the escape character
on the protocol level, which means you may need to use double
backslash.

Example expression which matches an artist named ``foo'bar"``::

238
 (Artist == "foo\'bar\"")
239 240 241

At the protocol level, the command must look like this::

242
 find "(Artist == \"foo\\'bar\\\"\")"
243 244 245 246 247 248 249 250 251 252 253 254 255 256

The double quotes enclosing the artist name must be escaped because
they are inside a double-quoted ``find`` parameter.  The single quote
inside that artist name must be escaped with two backslashes; one to
escape the single quote, and another one because the backslash inside
the string inside the parameter needs to be escaped as well.  The
double quote has three confusing backslashes: two to build one
backslash, and another one to escape the double quote on the protocol
level.  Phew!

To reduce confusion, you should use a library such as `libmpdclient
<https://www.musicpd.org/libs/libmpdclient/>`_ which escapes command
arguments for you.

257 258 259 260 261
.. _tags:

Tags
====

262
The following tags are supported by :program:`MPD`:
263

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
* **artist**: the artist name. Its meaning is not well-defined; see "*composer*" and "*performer*" for more specific tags.
* **artistsort**: same as artist, but for sorting. This usually omits prefixes such as "The".
* **album**: the album name.
* **albumsort**: same as album, but for sorting.
* **albumartist**: on multi-artist albums, this is the artist name which shall be used for the whole album. The exact meaning of this tag is not well-defined.
* **albumartistsort**: same as albumartist, but for sorting.
* **title**: the song title.
* **track**: the decimal track number within the album.
* **name**: a name for this song. This is not the song title. The exact meaning of this tag is not well-defined. It is often used by badly configured internet radio stations with broken tags to squeeze both the artist name and the song title in one tag.
* **genre**: the music genre.
* **date**: the song's release date. This is usually a 4-digit year.
* **composer**: the artist who composed the song.
* **performer**: the artist who performed the song.
* **comment**: a human-readable comment about this song. The exact meaning of this tag is not well-defined.
* **disc**: the decimal disc number in a multi-disc album.
279
* **label**: the name of the label or publisher.
280 281 282 283 284 285 286
* **musicbrainz_artistid**: the artist id in the `MusicBrainz <https://picard.musicbrainz.org/docs/mappings/>`_ database.
* **musicbrainz_albumid**: the album id in the `MusicBrainz <https://picard.musicbrainz.org/docs/mappings/>`_ database.
* **musicbrainz_albumartistid**: the album artist id in the `MusicBrainz <https://picard.musicbrainz.org/docs/mappings/>`_ database.
* **musicbrainz_trackid**: the track id in the `MusicBrainz <https://picard.musicbrainz.org/docs/mappings/>`_ database.
* **musicbrainz_releasetrackid**: the release track id in the `MusicBrainz <https://picard.musicbrainz.org/docs/mappings/>`_ database.
* **musicbrainz_workid**: the work id in the `MusicBrainz <https://picard.musicbrainz.org/docs/mappings/>`_ database.

287
There can be multiple values for some of these tags.  For
288
example, :program:`MPD` may return multiple
289 290 291 292 293 294 295 296
lines with a ``performer`` tag.  A tag value is
a UTF-8 string.

.. _other_metadata:

Other Metadata
==============

297 298
The response to :ref:`lsinfo <command_lsinfo>` and similar commands
may contain :ref:`song tags <tags>` and other metadata, specifically:
299 300 301 302 303 304 305 306

- ``duration``: the duration of the song in
  seconds; may contain a fractional part.

- ``time``: like ``duration``,
  but as integer value.  This is deprecated and is only here
  for compatibility with older clients.  Do not use.

307 308 309 310 311 312
- ``Range``: if this is a queue item referring only to a portion of
  the song file, then this attribute contains the time range in the
  form ``START-END`` or ``START-`` (open ended); both ``START`` and
  ``END`` are time stamps within the song in seconds (may contain a
  fractional part).  Example: ``60-120`` plays only the second minute;
  "``180`` skips the first three minutes.
313 314 315 316

- ``Format``: the audio format of the song
  (or an approximation to a format supported by MPD and the
  decoder plugin being used).  When playing this file, the
317
  ``audio`` value in the :ref:`status <command_status>`
318 319 320 321 322 323 324 325
  response should be the same.

- ``Last-Modified``: the time stamp of the
  last modification of the underlying file in ISO 8601
  format.  Example:
  "*2008-09-28T20:04:57Z*"

Recipes
326
*******
327 328 329 330

Queuing
=======

331 332 333
Often, users run :program:`MPD` with :ref:`random <command_random>`
enabled, but want to be able to insert songs "before" the rest of the
playlist.  That is commonly called "queuing".
334

335 336 337 338 339
:program:`MPD` implements this by allowing the client to specify a
"priority" for each song in the playlist (commands :ref:`priod
<command_prio>` and :ref:`priodid <command_prioid>`).  A higher
priority means that the song is going to be played before the other
songs.
340

341
In "random" mode, :program:`MPD` maintains an
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
internal randomized sequence of songs.  In this sequence,
songs with a higher priority come first, and all songs with
the same priority are shuffled (by default, all songs are
shuffled, because all have the same priority "0").  When you
increase the priority of a song, it is moved to the front of
the sequence according to its new priority, but always after
the current one.  A song that has been played already (it's
"before" the current song in that sequence) will only be
scheduled for repeated playback if its priority has become
bigger than the priority of the current song.  Decreasing the
priority of a song will move it farther to the end of the
sequence.  Changing the priority of the current song has no
effect on the sequence.  During playback, a song's priority is
reset to zero.

Command reference
358
*****************
359 360 361 362 363 364 365

.. note:: For manipulating playlists and playing, there are two sets of
   commands.  One set uses the song id of a song in the playlist,
   while another set uses the playlist position of the song. The
   commands using song ids should be used instead of the commands
   that manipulate and control playback based on playlist
   position. Using song ids is a safer method when multiple
366
   clients are interacting with :program:`MPD`.
367

368
Querying :program:`MPD`'s status
369 370
================================

371
:command:`clearerror`
372 373 374
    Clears the current error message in status (this is also
    accomplished by any command that starts playback).

375
:command:`currentsong`
376 377 378
    Displays the song info of the current song (same song that
    is identified in status).

379 380 381
.. _command_idle:

:command:`idle [SUBSYSTEMS...]` [#since_0_14]_
382
    Waits until there is a noteworthy change in one or more
383
    of :program:`MPD`'s subsystems.  As soon
384 385 386 387
    as there is one, it lists all changed systems in a line
    in the format ``changed:
    SUBSYSTEM``, where SUBSYSTEM is one of the
    following:
388 389

    - ``database``: the song database has been modified after :ref:`update <command_update>`.
390 391
    - ``update``: a database update has started or finished.  If the database was modified during the update, the ``database`` event is also emitted.
    - ``stored_playlist``: a stored playlist has been modified, renamed, created or deleted
392
    - ``playlist``: the queue (i.e. the current playlist) has been modified
393 394 395 396 397 398 399 400
    - ``player``: the player has been started, stopped or seeked
    - ``mixer``: the volume has been changed
    - ``output``: an audio output has been added, removed or modified (e.g. renamed, enabled or disabled)
    - ``options``: options like repeat, random, crossfade, replay gain
    - ``partition``: a partition was added, removed or changed
    - ``sticker``: the sticker database has been modified.
    - ``subscription``: a client has subscribed or unsubscribed to a channel
    - ``message``: a message was received on a channel this client is subscribed to; this event is only emitted when the queue is empty
401 402 403 404 405

    Change events accumulate, even while the connection is not in
    "idle" mode; no events gets lost while the client is doing
    something else with the connection.  If an event had already
    occurred since the last call, the new :ref:`idle <command_idle>`
406
    command will return immediately.
407

408 409 410 411 412
    While a client is waiting for `idle`
    results, the server disables timeouts, allowing a client
    to wait for events as long as mpd runs.  The
    `idle` command can be canceled by
    sending the command `noidle` (no other
413
    commands are allowed). :program:`MPD`
414 415 416
    will then leave `idle` mode and print
    results immediately; might be empty at this time.
    If the optional ``SUBSYSTEMS`` argument
417
    is used, :program:`MPD` will only send
418 419 420
    notifications when something changed in one of the
    specified subsytems.

421 422 423
.. _command_status:

:command:`status`
424 425
    Reports the current status of the player and the volume
    level.
426

427 428
    - ``volume``: ``0-100`` (deprecated: ``-1`` if the volume cannot
      be determined)
429 430
    - ``repeat``: ``0`` or ``1``
    - ``random``: ``0`` or ``1``
431
    - ``single`` [#since_0_15]_: ``0``, ``1``, or ``oneshot`` [#since_0_21]_
432
    - ``consume`` [#since_0_15]_: ``0`` or ``1``
433 434
    - ``playlist``: 31-bit unsigned integer, the playlist version number
    - ``playlistlength``: integer, the length of the playlist
435
    - ``state``: ``play``, ``stop``, or ``pause``
436 437
    - ``song``: playlist song number of the current song stopped on or playing
    - ``songid``: playlist songid of the current song stopped on or playing
438 439
    - ``nextsong`` [#since_0_15]_: playlist song number of the next song to be played
    - ``nextsongid`` [#since_0_15]_: playlist songid of the next song to be played
440
    - ``time``: total time elapsed (of current playing/paused song) in seconds
441
      (deprecated, use ``elapsed`` instead)
442 443
    - ``elapsed`` [#since_0_16]_: Total time elapsed within the
      current song in seconds, but with higher resolution.
444
    - ``duration`` [#since_0_20]_: Duration of the current song in seconds.
445 446 447 448
    - ``bitrate``: instantaneous bitrate in kbps
    - ``xfade``: ``crossfade`` in seconds
    - ``mixrampdb``: ``mixramp`` threshold in dB
    - ``mixrampdelay``: ``mixrampdelay`` in seconds
449 450 451
    - ``audio``: The format emitted by the decoder plugin during
      playback, format: ``samplerate:bits:channels``.  See
      :ref:`audio_output_format` for a detailed explanation.
452 453 454
    - ``updating_db``: ``job id``
    - ``error``: if there is an error, returns message here

455 456 457 458
    :program:`MPD` may omit lines which have no (known) value.  Older
    :program:`MPD` versions used to have a "magic" value for
    "unknown", e.g. ":samp:`volume: -1`".

459
:command:`stats`
460
    Displays statistics.
461

462 463 464 465
    - ``artists``: number of artists
    - ``albums``: number of albums
    - ``songs``: number of songs
    - ``uptime``: daemon uptime in seconds
466
    - ``db_playtime``: sum of all song times in the database in seconds
467 468 469 470 471 472
    - ``db_update``: last db update in UNIX time
    - ``playtime``: time length of music played

Playback options
================

473
:command:`consume {STATE}` [#since_0_15]_
474 475 476 477
    Sets consume state to ``STATE``,
    ``STATE`` should be 0 or 1.
    When consume is activated, each song played is removed from playlist.

478
:command:`crossfade {SECONDS}`
479 480
    Sets crossfading between songs.

481
:command:`mixrampdb {deciBels}`
482 483
    Sets the threshold at which songs will be overlapped. Like crossfading but doesn't fade the track volume, just overlaps. The songs need to have MixRamp tags added by an external tool. 0dB is the normalized maximum volume so use negative values, I prefer -17dB. In the absence of mixramp tags crossfading will be used. See http://sourceforge.net/projects/mixramp

484
:command:`mixrampdelay {SECONDS}`
485 486
    Additional time subtracted from the overlap calculated by mixrampdb. A value of "nan" disables MixRamp overlapping and falls back to crossfading.

487 488 489
.. _command_random:

:command:`random {STATE}`
490 491 492
    Sets random state to ``STATE``,
    ``STATE`` should be 0 or 1.

493
:command:`repeat {STATE}`
494 495 496
    Sets repeat state to ``STATE``,
    ``STATE`` should be 0 or 1.

497 498 499
.. _command_setvol:

:command:`setvol {VOL}`
500 501 502
    Sets volume to ``VOL``, the range of
    volume is 0-100.

503
:command:`single {STATE}` [#since_0_15]_
504
    Sets single state to ``STATE``,
505
    ``STATE`` should be ``0``, ``1`` or ``oneshot`` [#since_0_20]_.
506 507 508
    When single is activated, playback is stopped after current song, or
    song is repeated if the 'repeat' mode is enabled.

509
:command:`replay_gain_mode {MODE}` [#since_0_16]_
510
    Sets the replay gain mode.  One of
511 512 513 514
    ``off``,
    ``track``,
    ``album``,
    ``auto``
515 516 517 518 519 520 521
    .
    Changing the mode during playback may take several
    seconds, because the new settings does not affect the
    buffered data.
    This command triggers the
    ``options`` idle event.

522
:command:`replay_gain_status`
523 524 525 526
    Prints replay gain options.  Currently, only the
    variable ``replay_gain_mode`` is
    returned.

527
:command:`volume {CHANGE}`
528
    Changes volume by amount ``CHANGE``.
529
    Deprecated, use :ref:`setvol <command_setvol>` instead.
530 531 532 533

Controlling playback
====================

534
:command:`next`
535 536
    Plays next song in the playlist.

537
:command:`pause {PAUSE}`
538 539
    Toggles pause/resumes playing, ``PAUSE`` is 0 or 1.

540 541 542
    The use of pause command without the PAUSE argument is deprecated.

:command:`play [SONGPOS]`
543 544 545
    Begins playing the playlist at song number
    ``SONGPOS``.

546
:command:`playid [SONGID]`
547 548 549
    Begins playing the playlist at song
    ``SONGID``.

550
:command:`previous`
551 552
    Plays previous song in the playlist.

553
:command:`seek {SONGPOS} {TIME}`
554 555 556 557
    Seeks to the position ``TIME`` (in
    seconds; fractions allowed) of entry
    ``SONGPOS`` in the playlist.

558
:command:`seekid {SONGID} {TIME}`
559 560 561 562
    Seeks to the position ``TIME`` (in
    seconds; fractions allowed) of song
    ``SONGID``.

563
:command:`seekcur {TIME}`
564 565
    Seeks to the position ``TIME`` (in
    seconds; fractions allowed) within the current song.  If
566
    prefixed by ``+`` or ``-``, then the time is relative to the
567 568
    current playing position.

569
:command:`stop`
570 571
    Stops playing.

572 573 574 575 576 577 578 579 580 581 582 583 584 585
The Queue
=========

.. note:: The "queue" used to be called "current playlist" or just
          "playlist", but that was deemed confusing, because
          "playlists" are also files containing a sequence of songs.
          Those "playlist files" or "stored playlists" can be
          :ref:`loaded into the queue <command_load>` and the queue
          can be :ref:`saved into a playlist file <command_save>`, but
          they are not to be confused with the queue.

          Many of the command names in this section reflect the old
          naming convention, but for the sake of compatibility, we
          cannot rename commands.
586

587 588 589
There are two ways to address songs within the queue: by their
position and by their id.

590
The position is a 0-based index.  It is unstable by design: if you
591 592 593 594 595 596 597 598 599 600 601 602
move, delete or insert songs, all following indices will change, and a
client can never be sure what song is behind a given index/position.

Song ids on the other hand are stable: an id is assigned to a song
when it is added, and will stay the same, no matter how much it is
moved around.  Adding the same song twice will assign different ids to
them, and a deleted-and-readded song will have a new id.  This way, a
client can always be sure the correct song is being used.

Many commands come in two flavors, one for each address type.
Whenever possible, ids should be used.

603
:command:`add {URI}`
604 605 606 607
    Adds the file ``URI`` to the playlist
    (directories add recursively). ``URI``
    can also be a single file.

608 609 610
:command:`addid {URI} [POSITION]`
    Adds a song to the playlist (non-recursive) and returns the
    song id. ``URI`` is always a single file or  URL.  For example::
611

612 613 614
     addid "foo.mp3"
     Id: 999
     OK
615

616
:command:`clear`
617
    Clears the queue.
618

619 620 621
.. _command_delete:

:command:`delete [{POS} | {START:END}]`
622 623
    Deletes a song from the playlist.

624
:command:`deleteid {SONGID}`
625 626 627
    Deletes the song ``SONGID`` from the
    playlist

cotko's avatar
cotko committed
628
:command:`move [{FROM} | {START:END}] {TO}`
629
    Moves the song at ``FROM`` or range of songs
630
    at ``START:END`` [#since_0_15]_ to ``TO``
631 632
    in the playlist.

633
:command:`moveid {FROM} {TO}`
634 635 636 637 638 639
    Moves the song with ``FROM`` (songid) to
    ``TO`` (playlist index) in the
    playlist.  If ``TO`` is negative, it
    is relative to the current song in the playlist (if
    there is one).

640 641
:command:`playlist`

642
    Displays the queue.
643

644 645 646 647
    Do not use this, instead use :ref:`playlistinfo
    <command_playlistinfo>`.

:command:`playlistfind {TAG} {NEEDLE}`
648
    Finds songs in the queue with strict
649 650
    matching.

651
:command:`playlistid {SONGID}`
652 653 654 655
    Displays a list of songs in the playlist.
    ``SONGID`` is optional and specifies a
    single song to display info for.

656 657 658
.. _command_playlistinfo:

:command:`playlistinfo [[SONGPOS] | [START:END]]`
659 660 661
    Displays a list of all songs in the playlist, or if the optional
    argument is given, displays information only for the song
    ``SONGPOS`` or the range of songs
662
    ``START:END`` [#since_0_15]_
663

664
:command:`playlistsearch {TAG} {NEEDLE}`
665
    Searches case-insensitively for partial matches in the
666
    queue.
667

668
:command:`plchanges {VERSION} [START:END]`
669 670 671 672
    Displays changed songs currently in the playlist since
    ``VERSION``.  Start and end positions may
    be given to limit the output to changes in the given
    range.
673

674 675 676
    To detect songs that were deleted at the end of the
    playlist, use playlistlength returned by status command.

677
:command:`plchangesposid {VERSION} [START:END]`
678 679 680 681
    Displays changed songs currently in the playlist since
    ``VERSION``.  This function only
    returns the position and the id of the changed song, not
    the complete metadata. This is more bandwidth efficient.
682

683 684 685
    To detect songs that were deleted at the end of the
    playlist, use playlistlength returned by status command.

686 687 688
.. _command_prio:

:command:`prio {PRIORITY} {START:END...}`
689 690 691
    Set the priority of the specified songs.  A higher
    priority means that it will be played first when
    "random" mode is enabled.
692

693 694 695
    A priority is an integer between 0 and 255.  The default
    priority of new songs is 0.

696 697 698 699
.. _command_prioid:

:command:`prioid {PRIORITY} {ID...}`
    Same as :ref:`priod <command_prio>`,
700 701
    but address the songs with their id.

702
:command:`rangeid {ID} {START:END}` [#since_0_19]_
703
    Since :program:`MPD`
704 705 706 707 708 709 710 711
    0.19 Specifies the portion of the
    song that shall be played.  ``START`` and
    ``END`` are offsets in seconds
    (fractional seconds allowed); both are optional.
    Omitting both (i.e. sending just ":") means "remove the
    range, play everything".  A song that is currently
    playing cannot be manipulated this way.

712
:command:`shuffle [START:END]`
713
    Shuffles the queue.
714 715 716
    ``START:END`` is optional and specifies
    a range of songs.

717
:command:`swap {SONG1} {SONG2}`
718 719 720
    Swaps the positions of ``SONG1`` and
    ``SONG2``.

721
:command:`swapid {SONG1} {SONG2}`
722 723 724
    Swaps the positions of ``SONG1`` and
    ``SONG2`` (both song ids).

725
:command:`addtagid {SONGID} {TAG} {VALUE}`
726 727 728 729 730 731
    Adds a tag to the specified song.  Editing song tags is
    only possible for remote songs.  This change is
    volatile: it may be overwritten by tags received from
    the server, and the data is gone when the song gets
    removed from the queue.

732
:command:`cleartagid {SONGID} [TAG]`
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
    Removes tags from the specified song.  If
    ``TAG`` is not specified, then all tag
    values will be removed.  Editing song tags is only
    possible for remote songs.

Stored playlists
================

Playlists are stored inside the configured playlist directory.
They are addressed with their file name (without the directory
and without the `.m3u` suffix).

Some of the commands described in this section can be used to
run playlist plugins instead of the hard-coded simple
`m3u` parser.  They can access playlists in
748 749
the music directory (relative path including the suffix),
playlists in arbitrary location (absolute path including the suffix;
750
allowed only for clients that are connected via local socket), or
751 752
remote playlists (absolute URI with a supported scheme).

753
:command:`listplaylist {NAME}`
754 755 756
    Lists the songs in the playlist.  Playlist plugins are
    supported.

757
:command:`listplaylistinfo {NAME}`
758 759 760
    Lists the songs with metadata in the playlist.  Playlist
    plugins are supported.

761
:command:`listplaylists`
762 763 764 765 766 767 768
    Prints a list of the playlist directory.
    After each playlist name the server sends its last
    modification time as attribute "Last-Modified" in ISO
    8601 format.  To avoid problems due to clock differences
    between clients and the server, clients should not
    compare this value with their local clock.

769 770
.. _command_load:

771
:command:`load {NAME} [START:END]`
772 773 774 775
    Loads the playlist into the current queue.  Playlist
    plugins are supported.  A range may be specified to load
    only a part of the playlist.

776
:command:`playlistadd {NAME} {URI}`
777 778 779 780 781
    Adds ``URI`` to the playlist
    `NAME.m3u`.
    `NAME.m3u` will be created if it does
    not exist.

782
:command:`playlistclear {NAME}`
783 784
    Clears the playlist `NAME.m3u`.

785
:command:`playlistdelete {NAME} {SONGPOS}`
786 787 788
    Deletes ``SONGPOS`` from the
    playlist `NAME.m3u`.

789
:command:`playlistmove {NAME} {FROM} {TO}`
790 791 792 793
    Moves the song at position ``FROM`` in
    the playlist `NAME.m3u` to the
    position ``TO``.

794
:command:`rename {NAME} {NEW_NAME}`
795 796
    Renames the playlist `NAME.m3u` to `NEW_NAME.m3u`.

797
:command:`rm {NAME}`
798 799 800
    Removes the playlist `NAME.m3u` from
    the playlist directory.

801 802
.. _command_save:

803
:command:`save {NAME}`
804
    Saves the queue to
805 806 807 808 809
    `NAME.m3u` in the playlist directory.

The music database
==================

810
:command:`albumart {URI} {OFFSET}`
811 812 813 814 815
    Searches the directory the file ``URI``
    resides in and attempts to return a chunk of an album
    art image file at offset ``OFFSET``.
    Uses the filename "cover" with any of ".png, .jpg,
    .tiff, .bmp".
816

817 818
    Returns the file size and actual number
    of bytes read at the requested offset, followed
819
    by the chunk requested as raw bytes (see :ref:`binary`), then a
820
    newline and the completion code.
821 822 823 824 825 826

    Example::

     albumart
     size: 1024768
     binary: 8192
827 828
     <8192 bytes>
     OK
829 830

:command:`count {FILTER} [group {GROUPTYPE}]`
831 832
    Count the number of songs and their total playtime in
    the database matching ``FILTER`` (see
833
    :ref:`Filters <filter_syntax>`).  The
834
    following prints the number of songs whose title matches
835 836 837 838
    "Echoes"::

     count title Echoes

839 840 841 842
    The *group* keyword may be used to
    group the results by a tag.  The first following example
    prints per-artist counts while the next prints the
    number of songs whose title matches "Echoes" grouped by
843 844 845 846
    artist::

     count group artist
     count title Echoes group artist
847

848 849 850 851
    A group with an empty value contains counts of matching song which
    don't this group tag.  It exists only if at least one such song is
    found.

852 853 854
.. _command_find:

:command:`find {FILTER} [sort {TYPE}] [window {START:END}]`
855
    Search the database for songs matching
856 857
    ``FILTER`` (see :ref:`Filters <filter_syntax>`).

858 859 860 861 862 863 864 865 866 867 868 869
    ``sort`` sorts the result by the
    specified tag.  The sort is descending if the tag is
    prefixed with a minus ('-').
    Without ``sort``, the
    order is undefined.  Only the first tag value will be
    used, if multiple of the same type exist.  To sort by
    "Artist", "Album" or "AlbumArtist", you should specify
    "ArtistSort", "AlbumSort" or "AlbumArtistSort" instead.
    These will automatically fall back to the former if
    "\*Sort" doesn't exist.  "AlbumArtist" falls back to just
    "Artist".  The type "Last-Modified" can sort by file
    modification time.
870

871 872 873 874 875
    ``window`` can be used to query only a
    portion of the real response.  The parameter is two
    zero-based record numbers; a start number and an end
    number.

876 877 878
.. _command_findadd:

:command:`findadd {FILTER}`
879
    Search the database for songs matching
880
    ``FILTER`` (see :ref:`Filters <filter_syntax>`) and add them to
881
    the queue.  Parameters have the same meaning as for
882
    :ref:`find <command_find>`.
883

884 885 886
.. _command_list:

:command:`list {TYPE} {FILTER} [group {GROUPTYPE}]`
887 888
    Lists unique tags values of the specified type.
    ``TYPE`` can be any tag supported by
889
    :program:`MPD`.
890 891

    Additional arguments may specify a :ref:`filter <filter_syntax>`.
892 893
    The *group* keyword may be used
    (repeatedly) to group the results by one or more tags.
894

895
    The following example lists all album names,
896 897 898 899
    grouped by their respective (album) artist::

     list album group albumartist

900 901 902 903
    ``list file`` was implemented in an early :program:`MPD` version,
    but does not appear to make a lot of sense.  It still works (to
    avoid breaking compatibility), but is deprecated.

904
.. _command_listall:
905

906
:command:`listall [URI]`
907 908
    Lists all songs and directories in
    ``URI``.
909

910
    Do not use this command.  Do not manage a client-side
911
    copy of :program:`MPD`'s database.  That
912 913
    is fragile and adds huge overhead.  It will break with
    large databases.  Instead, query
914
    :program:`MPD` whenever you need
915 916
    something.

917 918 919 920
.. _command_listallinfo:

:command:`listallinfo [URI]`
    Same as :ref:`listall <command_listall>`,
921
    except it also returns metadata info in the same format
922 923
    as :ref:`lsinfo <command_lsinfo>`

924
    Do not use this command.  Do not manage a client-side
925
    copy of :program:`MPD`'s database.  That
926 927
    is fragile and adds huge overhead.  It will break with
    large databases.  Instead, query
928
    :program:`MPD` whenever you need
929 930
    something.

931
:command:`listfiles {URI}`
932 933
    Lists the contents of the directory
    ``URI``, including files are not
934
    recognized by :program:`MPD`.
935 936 937 938 939 940
    ``URI`` can be a path relative to the
    music directory or an URI understood by one of the
    storage plugins.  The response contains at least one
    line for each directory entry with the prefix "file: "
    or "directory: ", and may be followed by file attributes
    such as "Last-Modified" and "size".
941

942 943 944 945
    For example, "smb://SERVER" returns a list of all shares
    on the given SMB/CIFS server; "nfs://servername/path"
    obtains a directory listing from the NFS server.

946 947
.. _command_lsinfo:

kaliko's avatar
kaliko committed
948
:command:`lsinfo [URI]`
949 950 951 952 953
    Lists the contents of the directory
    ``URI``.  The response contains records
    starting with ``file``,
    ``directory`` or
    ``playlist``, each followed by metadata
954 955
    (:ref:`tags <tags>` or :ref:`other metadata <other_metadata>`).

956 957 958
    When listing the root directory, this currently returns
    the list of stored playlists.  This behavior is
    deprecated; use "listplaylists" instead.
959

960 961
    This command may be used to list metadata of remote
    files (e.g. URI beginning with "http://" or "smb://").
962

963
    Clients that are connected via local socket may
964 965 966
    use this command to read the tags of an arbitrary local
    file (URI is an absolute path).

967
:command:`readcomments {URI}`
968 969 970
    Read "comments" (i.e. key-value pairs) from the file
    specified by "URI".  This "URI" can be a path relative
    to the music directory or an absolute path.
971

972 973
    This command may be used to list metadata of remote
    files (e.g. URI beginning with "http://" or "smb://").
974

975 976 977
    The response consists of lines in the form "KEY: VALUE".
    Comments with suspicious characters (e.g. newlines) are
    ignored silently.
978

979 980 981 982
    The meaning of these depends on the codec, and not all
    decoder plugins support it.  For example, on Ogg files,
    this lists the Vorbis comments.

983 984 985
.. _command_search:

:command:`search {FILTER} [sort {TYPE}] [window {START:END}]`
986
    Search the database for songs matching
987 988
    ``FILTER`` (see :ref:`Filters <filter_syntax>`).  Parameters
    have the same meaning as for :ref:`find <command_find>`,
989 990
    except that search is not case sensitive.

991 992 993
.. _command_searchadd:

:command:`searchadd {FILTER}`
994
    Search the database for songs matching
995
    ``FILTER`` (see :ref:`Filters <filter_syntax>`) and add them to
996 997
    the queue.

998 999 1000
    Parameters have the same meaning as for :ref:`search <command_search>`.

:command:`searchaddpl {NAME} {FILTER}`
1001
    Search the database for songs matching
1002
    ``FILTER`` (see :ref:`Filters <filter_syntax>`) and add them to
1003
    the playlist named ``NAME``.
1004

1005 1006
    If a playlist by that name doesn't exist it is created.

1007 1008 1009 1010 1011
    Parameters have the same meaning as for :ref:`search <command_search>`.

.. _command_update:

:command:`update [URI]`
1012 1013
    Updates the music database: find new files, remove
    deleted files, update modified files.
1014

1015 1016 1017
    ``URI`` is a particular directory or
    song/file to update.  If you do not specify it,
    everything is updated.
1018 1019

    Prints ``updating_db: JOBID`` where
1020 1021
    ``JOBID`` is a positive number
    identifying the update job.  You can read the current
1022
    job id in the :ref:`status <command_status>`
1023 1024
    response.

1025 1026
:command:`rescan [URI]`
    Same as :ref:`update <command_update>`,
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
    but also rescans unmodified files.

Mounts and neighbors
====================

A "storage" provides access to files in a directory tree.  The
most basic storage plugin is the "local" storage plugin which
accesses the local file system, and there are plugins to
access NFS and SMB servers.

Multiple storages can be "mounted" together, similar to the
`mount` command on many operating
systems, but without cooperation from the kernel.  No
superuser privileges are necessary, beause this mapping exists
1041
only inside the :program:`MPD` process
1042

1043 1044 1045
.. _command_mount:

:command:`mount {PATH} {URI}`
1046
    Mount the specified remote storage URI at the given
1047 1048 1049 1050 1051 1052
    path.  Example::

     mount foo nfs://192.168.1.4/export/mp3

:command:`unmount {PATH}`
    Unmounts the specified path.  Example::
1053

1054
     unmount foo
1055

1056
:command:`listmounts`
1057 1058
    Queries a list of all mounts.  By default, this contains
    just the configured ``music_directory``.
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
    Example::

     listmounts
     mount:
     storage: /home/foo/music
     mount: foo
     storage: nfs://192.168.1.4/export/mp3
     OK

:command:`listneighbors`
1069 1070
    Queries a list of "neighbors" (e.g. accessible file
    servers on the local net).  Items on that list may be
1071 1072 1073 1074 1075 1076 1077
    used with the :ref:`mount <command_mount>`
    command.  Example::

     listneighbors
     neighbor: smb://FOO
     name: FOO (Samba 4.1.11-Debian)
     OK
1078 1079 1080 1081

Stickers
========

1082
"Stickers" [#since_0_15]_ are pieces of
1083
information attached to existing
1084
:program:`MPD` objects (e.g. song files,
1085 1086
directories, albums; but currently, they are only implemented for
song).  Clients can create arbitrary name/value
1087
pairs.  :program:`MPD` itself does not assume
1088 1089 1090 1091 1092
any special meaning in them.

The goal is to allow clients to share additional (possibly
dynamic) information about songs, which is neither stored on
the client (not available to other clients), nor stored in the
1093
song files (:program:`MPD` has no write
1094 1095 1096 1097 1098 1099 1100 1101 1102
access).

Client developers should create a standard for common sticker
names, to ensure interoperability.

Objects which may have stickers are addressed by their object
type ("song" for song objects) and their URI (the path within
the database for songs).

1103
:command:`sticker get {TYPE} {URI} {NAME}`
1104 1105
    Reads a sticker value for the specified object.

1106
:command:`sticker set {TYPE} {URI} {NAME} {VALUE}`
1107 1108 1109 1110
    Adds a sticker value to the specified object.  If a
    sticker item with that name already exists, it is
    replaced.

1111
:command:`sticker delete {TYPE} {URI} [NAME]`
1112 1113 1114 1115
    Deletes a sticker value from the specified object.  If
    you do not specify a sticker name, all sticker values
    are deleted.

1116
:command:`sticker list {TYPE} {URI}`
1117 1118
    Lists the stickers for the specified object.

1119
:command:`sticker find {TYPE} {URI} {NAME}`
1120 1121 1122 1123 1124
    Searches the sticker database for stickers with the
    specified name, below the specified directory (URI).
    For each matching song, it prints the URI and that one
    sticker's value.

1125
:command:`sticker find {TYPE} {URI} {NAME} = {VALUE}`
1126
    Searches for stickers with the given value.
1127

1128 1129 1130 1131 1132 1133
    Other supported operators are:
    "``<``", "``>``"

Connection settings
===================

1134
:command:`close`
1135 1136
    Closes the connection to :program:`MPD`.
    :program:`MPD` will try to send the
1137 1138 1139 1140
    remaining output buffer before it actually closes the
    connection, but that cannot be guaranteed.  This command
    will not generate a response.

1141 1142 1143
    Clients should not use this command; instead, they should just
    close the socket.

1144
:command:`kill`
1145
    Kills :program:`MPD`.
1146

1147 1148 1149 1150
    Do not use this command.  Send ``SIGTERM`` to :program:`MPD`
    instead, or better: let your service manager handle :program:`MPD`
    shutdown (e.g. :command:`systemctl stop mpd`).

1151
:command:`password {PASSWORD}`
1152 1153 1154 1155
    This is used for authentication with the server.
    ``PASSWORD`` is simply the plaintext
    password.

1156
:command:`ping`
1157 1158
    Does nothing but return "OK".

1159
:command:`tagtypes`
1160 1161 1162
    Shows a list of available tag types.  It is an
    intersection of the ``metadata_to_use``
    setting and this client's tag mask.
1163

1164 1165 1166 1167 1168 1169 1170
    About the tag mask: each client can decide to disable
    any number of tag types, which will be omitted from
    responses to this client.  That is a good idea, because
    it makes responses smaller.  The following
    ``tagtypes`` sub commands configure this
    list.

kaliko's avatar
kaliko committed
1171
:command:`tagtypes disable {NAME...}`
1172 1173 1174 1175
    Remove one or more tags from the list of tag types the
    client is interested in.  These will be omitted from
    responses to this client.

1176
:command:`tagtypes enable {NAME...}`
1177 1178 1179 1180
    Re-enable one or more tags from the list of tag types
    for this client.  These will no longer be hidden from
    responses to this client.

1181
:command:`tagtypes clear`
1182
    Clear the list of tag types this client is interested
1183
    in.  This means that :program:`MPD` will
1184 1185
    not send any tags to this client.

1186
:command:`tagtypes all`
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197
    Announce that this client is interested in all tag
    types.  This is the default setting for new clients.

Partition commands
==================

These commands allow a client to inspect and manage
"partitions".  A partition is one frontend of a multi-player
MPD process: it has separate queue, player and outputs.  A
client is assigned to one partition at a time.

1198
:command:`partition {NAME}`
1199 1200
    Switch the client to a different partition.

1201
:command:`listpartitions`
1202 1203 1204 1205 1206
    Print a list of partitions.  Each partition starts with
    a ``partition`` keyword and the
    partition's name, followed by information about the
    partition.

1207
:command:`newpartition {NAME}`
1208 1209 1210 1211 1212
    Create a new partition.

Audio output devices
====================

1213
:command:`disableoutput {ID}`
1214 1215
    Turns an output off.

1216
:command:`enableoutput {ID}`
1217 1218
    Turns an output on.

1219
:command:`toggleoutput {ID}`
1220 1221 1222
    Turns an output on or off, depending on the current
    state.

1223 1224 1225
.. _command_outputs:

:command:`outputs`
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
    Shows information about all outputs.
    
    ::

        outputid: 0
        outputname: My ALSA Device
        plugin: alsa
        outputenabled: 0
        attribute: dop=0
        OK

    Return information:
1238

1239 1240 1241 1242
    - ``outputid``: ID of the output. May change between executions
    - ``outputname``: Name of the output. It can be any.
    - ``outputenabled``: Status of the output. 0 if disabled, 1 if enabled.

1243
:command:`outputset {ID} {NAME} {VALUE}`
1244 1245
    Set a runtime attribute.  These are specific to the
    output plugin, and supported values are usually printed
1246
    in the :ref:`outputs <command_outputs>`
1247 1248 1249 1250 1251
    response.

Reflection
==========

1252
:command:`config`
1253 1254
    Dumps configuration values that may be interesting for
    the client.  This command is only permitted to "local"
1255
    clients (connected via local socket).
1256

1257 1258
    The following response attributes are available:

1259 1260 1261
    - ``music_directory``: The absolute path of the music directory.

:command:`commands`
1262 1263
    Shows which commands the current user has access to.

1264
:command:`notcommands`
1265 1266 1267
    Shows which commands the current user does not have
    access to.

1268
:command:`urlhandlers`
1269 1270
    Gets a list of available URL handlers.

1271
:command:`decoders`
1272
    Print a list of decoder plugins, followed by their
1273 1274 1275 1276 1277 1278 1279 1280
    supported suffixes and MIME types.  Example response::

     plugin: mad
     suffix: mp3
     suffix: mp2
     mime_type: audio/mpeg
     plugin: mpcdec
     suffix: mpc
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291

Client to client
================

Clients can communicate with each others over "channels".  A
channel is created by a client subscribing to it.  More than
one client can be subscribed to a channel at a time; all of
them will receive the messages which get sent to it.

Each time a client subscribes or unsubscribes, the global idle
event ``subscription`` is generated.  In
1292
conjunction with the :ref:`channels <command_channels>`
1293 1294 1295 1296 1297 1298
command, this may be used to auto-detect clients providing
additional services.

New messages are indicated by the ``message``
idle event.

1299
:command:`subscribe {NAME}`
1300 1301 1302 1303 1304
    Subscribe to a channel.  The channel is created if it
    does not exist already.  The name may consist of
    alphanumeric ASCII characters plus underscore, dash, dot
    and colon.

1305
:command:`unsubscribe {NAME}`
1306 1307
    Unsubscribe from a channel.

1308 1309 1310
.. _command_channels:

:command:`channels`
1311 1312 1313
    Obtain a list of all channels.  The response is a list
    of "channel:" lines.

1314
:command:`readmessages`
1315 1316 1317
    Reads messages for this client.  The response is a list
    of "channel:" and "message:" lines.

1318
:command:`sendmessage {CHANNEL} {TEXT}`
1319 1320
    Send a message to the specified channel.

1321
.. rubric:: Footnotes
1322

1323 1324 1325 1326 1327
.. [#since_0_14] Since :program:`MPD` 0.14
.. [#since_0_15] Since :program:`MPD` 0.15
.. [#since_0_16] Since :program:`MPD` 0.16
.. [#since_0_19] Since :program:`MPD` 0.20
.. [#since_0_20] Since :program:`MPD` 0.20
1328
.. [#since_0_21] Since :program:`MPD` 0.21