MPD Protocol Version 0.11.0 2004 Warren Dukes Protocol Outline The MPD Protocol has Three Components: Commands, Responses, and Command Lists. All communication between the client and server uses the UTF-8 character encoding. Format of Commands Commands in MPD are specified begginning with the name of the command. The arguments of a command are delimitted by spaces and should be surrounded by double qutotation marks. The end of a command is delimitted by a return character '\n'.command "arg1" "arg2" Format of Responses The different response elements of a command are seperated by the return character '\n'. The last element of a response begin with either OK or ACK. Thus, if a command is successful, the end of the response is OK\n. If a command is unsuccessful ACK terminates the command with the following format:ACK {err#:cmd#} {command} some error messageerr# is an integer indicating the specific error that occured and cmd# is an integer indicating which command of the command list caused the error (See section 1.3 for more info on Command Lists). command gives the name of the command the error occurred on; however, its intended more for debugging persons (for human readability). some error message is also not intended to be parsed by clients but is intended more for debugging purposes. The other response elements are data. The data is seperated into a name and value pare by : . Thus, a possible command response containing data would be:Name1: Value1 Name2: Value2 OK Command Lists Command lists allow for a fast, effecient, and atomic execution of multiple commands. Command lists are initiated with either command_list_begin or command_list_ok_beginand are terminated with command_list_end.command_list_begin command1 arg1 arg2 command2 arg1 arg2 command3 arg1 arg2 command_list_end The responses for command executed with command lists are the same with the exception that anOK or ACK is not returned for each command. Instead a single OK or ACK is returned for the entire command list. An OK indicates that all the commands in the command list were successfully executed; while an ACK error is returned on the first unsuccessful command in the command list and none of the following commands in the command are executed. command_list_ok_begin responds with list_OK after each command is successfully completed. command_list_begin does not return anything between each command that is executed. Commands DB: Browsing, Searching, and Finding Browsing Responses Browsing Responses usually contain groups of several responses. These groups are either begin with file, directory, or playlist. Each of these response groups maybe followed by metadata, which always begin with a capital letter (A-Z). Here's an example of a complete browsing response:file: Directory/file.mp3 Artist: Muscian Album: Record Time: 23 directory: Directory/Subdirectory playlist: Directory/favorites OK directory and playlist have no metadata, however future versions of the MPD protocol may add metadata to either. Also, future versions of MPD may add othe response groups for browsing. Song Info Responses For query information on songs in the db (and the playlist), there is a common response for each song. The first response element is file. The remainng elements of the song info are one of the following metadata types: Artist, Album, Title, Track, Name, or Time. <literal>lsinfo</literal> lsinfo lsinfo directory lsinfo filelsinfo responds with info for the directory or file specified. If lsinfo is called without any arguments then the root directory is implied as the path. <literal>listallinfo</literal> listallinfo listallinfo directory listallinfo filelistallinfo is a recursive form of lsinfo <literal>listall</literal> listall listall directory listall filelistall is the same as listallinfo except that no metadata is returned. <literal>search</literal> search filename pattern search artist pattern search album pattern search title patternsearch respnds with the files that match the specified pattern with the specified data (either filename, artist, album, or title). <literal>find</literal> find artist match find album matchfind responds with the files whose artist or album are the same as match. <literal>list</literal> list artist list album list album someArtistlist responds with the list of albums or artists in the db. Playlist: Adding, Deleting, and Managment Additional Song Metadata In addition to the same song metadata returned when browsing, songs in a playlist have two additional metadata elements. Pos is the position in the playlist of the song and Id is the playlist id for a song (each song in the playlist has a unique Id, even if there is a duplicate entry for the same file).file: directory/song Artist: famousArtist Title: popularSong Num: 0 Id: 23 file: directory/song Artist: famouseArtist Title: popularSong Num: 1 Id: 132 Song ID's vs Playlist Position When implementing a client for MPD, the developer must keep in mind that multiple clients maybe manipulating the playlist simultaneously. Thus, its essential to use playlist song id's instead of the playlist position for manipulating the playlist. This is due to the fact that another client maybe moving, deleting, etc... songs in the playlist, thus changing the order and positions of songs in the playlist. Consequently, using song id's is a safer method for manipulating the playlist as the song id's do not depend on the order and positions of songs in the playlist. <literal>playlistinfo</literal> playlistinfo playlistinfo -1 playlistinfo positionplaylistinfo responds with the information about songs in the playlist. If no argument is passed to playlistinfo or an argument of -1 is passed, then every song in the playlist is returned. If a playlist position is passed to playlistinfo, then the information about the song at position is returned. Note: It's suggest that playlistid be used instead of playlistinfo. <literal>playlistid</literal> playlistid playlistid -1 playlistid idplaylistid is the same as playlistinfo except that using optional argument id causes the information for the song with the playlist song ID idto be returned. <literal>plchanges</literal> plchanges versionplchanges responds with the song information for songs that have changed since the playlist version version. Note, to detect songs that were removed at the end of the playlist, use the playlist length returned by status. <literal>deleteid</literal> deleteid iddeleteid removes the song with the playlist song id id from the playlist. <literal>delete</literal> delete positiondelete removes the song at the playlist position position from the playlist. Note: It's suggested that deleteid be used instead of delete. <literal>add</literal> add file add urladd appends the file or url to the end of the playlist <literal>moveid</literal> movid id position <literal>move</literal> move position position <literal>swapid</literal> swapid id1 id2 <literal>swap</literal> swap position1 position2 <literal>clear</literal> clear <literal>save</literal> save <literal>shuffle</literal> shuffle <literal>rm</literal> rm Status Queries <literal>status</literal> status <literal>currentsong</literal> currentsong Playback: Play, Pause, Stop, and Seek <literal>playid</literal> playid playid -1 playid id <literal>play</literal> play play -1 play position <literal>pause</literal> pause 0 pause 1 <literal>stop</literal> stop <literal>seekid</literal> seekid id seconds <literal>seek</literal> seek position seconds <literal>repeat</literal> repeat 0 repeat 1 <literal>random</literal> random 0 random 1 Miscellanous Commands <literal>password</literal> password psswd <literal>stats</literal> stats <literal>kill</literal> kill ACK Errors Common Errors Command Specific Guidelines