Interface to the Music Player Daemon.
This extension allows convenient access to the tcp interface of MPD.
- (connect [HOST] [PORT] [PASSWORD]) procedure
Connects to the MPD instance running on HOST (defaults to localhost) at PORT (defaults to 6600). Optionally authenticates using PASSWORD. Returns an MPD connection object.
- (disconnect CONN) procedure
Closes the connection to MPD. CONN should not be used anymore after calling this function.
- (mpd-connection? CONN) procedure
Returns #t if CONN is an MPD connection object, #f otherwise.
- (mpd-host CONN) procedure
Returns the hostname field of the MPD connection object CONN.
- (mpd-port CONN) procedure
Returns the port field of the MPD connection object CONN.
- (mpd-password CONN) procedure
Returns the password field of the MPD connection object CONN. This is either a string containing the plain text password or #f if no authentication should be done.
- (mpd-version CONN) procedure
Returns the version field of the MPD connection object CONN which contains the version number received by the MPD server.
- (ping CONN) procedure
Sends a ping command to the MPD server, reconnecting if necessary.
- (clear-error! CONN) procedure
Clears the current error message (which is returned by (get-status)). This is also done by any command that starts playback.
- (get-stats CONN) procedure
Returns an alist containing various stats:
#;6> (pp (get-stats m)) ((artists . 183) (albums . 429) (songs . 6200) (uptime . 130260) (playtime . 49958) (db_playtime . 1773229) (db_update . 1152376960.0)) #;7>
- (get-status CONN) procedure
Return an alist describing the current status of MPD:
#;9> (pp (get-status m)) ((volume . 78) (repeat . #f) (random . #f) (playlist . 78) (playlistlength . 77) (xfade . 0) (state . play) (song . 12) (songid . 12) (time 31 623) (bitrate . 128) (audio 44100 16 2)) #;10>
- (shutdown-server! CONN) procedure
- (get-commands CONN) procedure
Returns a list of commands the current user has access to.
- (play-song! CONN #!optional SONG TIME) procedure
Start playing at song SONG (or the first in playlist) at TIME (in seconds).
- (next-song! CONN) procedure
Play the next song in the playlist.
- (previous-song! CONN) procedure
Play the previous song in the playlist.
- (stop! CONN) procedure
- (pause! CONN PAUSE?) procedure
Pause if PAUSE? is true, resume playing otherwise.
- (set-options! CONN . OPTS) procedure
Set playback options. Options are: #:crossfade, #:random, #:repeat and #:volume and they can be mapped to arguments.
- (get-output-devices CONN) procedure
Returns a list of alists describing the available output devices.
- (enable-output-device! CONN ID) procedure
Enables the output device with id ID.
- (disable-output-device! CONN ID) procedure
Disables the output device with id ID.
- (get-playlist CONN [ID]) procedure
Return a list of alists describing the songs in the current playlist. (Optionally only the song with id ID):
#;10> (pp (get-playlist m 12)) (((Id . 12) (Pos . 12) (Time . 623) (Title . "the leper affinity") (Track . 1) (Album . "blackwater park") (Artist . "opeth") (file . "metal/opeth/blackwater park/01 the leper affinity.mp3"))) #;11>
- (get-current-song CONN) procedure
Returns an alist with information about the current song (the same information that (get-playlist) returns).
- (get-playlist-changes CONN VERSION) procedure
Return a list of alists describing new songs since playlist version VERSION. Note: to detect songs that were deleted at the end of the playlist, use the playlistlength returned by (get-status).
- (add-song CONN PATH) procedure
Adds PATH (a string naming a file or directory) to the end of the current playlist. Directories are added recursively. Increments playlist version by 1 for each added song.
- (move-song! CONN FROM TO) procedure
Move song at position FROM to TO. The playlist version is incremented by 1.
- (swap-songs! CONN SONG1 SONG2) procedure
Swap position of the two songs.
- (remove-song! CONN SONG) procedure
Remove the song SONG (position or ID) from playlist. The playlist version is incremented by 1.
- (shuffle-playlist! CONN) procedure
Shuffles the current playlist and increments the playlist version by 1.
- (clear-playlist! CONN) procedure
Clears the current playlist, incrementing playlist version by 1.
- (load-playlist! CONN PLAYLIST) procedure
Loads the playlist named "PLAYLIST.m3u" from the playlist directory. The playlist version is incremented by the number of songs added.
- (remove-playlist! CONN PLAYLIST) procedure
Removes the playlist named "PLAYLIST.m3u" from the playlist directory.
- (save-playlist! CONN PLAYLIST) procedure
Saves the current playlist to "PLAYLIST.m3u" in the playlist directory.
- (find-songs CONN TYPE STRING) procedure
Searches for songs and returns a list of alists. TYPE is e.g. 'title, 'album or 'artist. STRING is the search string (which must match exactly).
- (search-songs CONN TYPE SEARCHSTRING) procedure
Returns a list of alists describing the matching songs. TYPE is e.g. 'title, 'album or 'artist. SEARCHSTRING is the string which is searched for (not case sensitive, doesn't need to be an exact match).
- (list-metadata CONN TYPE [LIMIT STRING]) procedure
Return a list of values of metadata TYPE (e.g. 'title, 'album or 'artist), optionally limited by LIMIT and STRING. E.g. (list-metadata m 'album 'artist "nevermore") to get a list of all albums by Nevermore.
- (list-directory/r CONN [PATH] [FULL #t]) procedure
Returns a list of all songs (below PATH, if given). If FULL is #t (default), list all metadata. If FULL is #f, return only filename metadata.
- (list-directory CONN [PATH]) procedure
Like (list-directory/r), with FULL as #t. The data is returned as a list of alists.
- (update-song-database! CONN [PATH]) procedure
Updates MPD's database, removing old songs and adding new songs. Optionally, the update process can be limited to PATH (a string naming a file or directory).
#!/usr/local/bin/csi -script (require-extension mpd-client srfi-18 utils) (define mpd (connect)) (define (get-mpd-status) (let ((status (get-status mpd))) (list (alist-ref 'songid status) (alist-ref 'state status)))) (define (get-songname id) (let ((info (car (get-playlist mpd id)))) (or (alist-ref 'Title info) (pathname-strip-directory (alist-ref 'file info))))) (let loop ((status (get-mpd-status)) (old-status #f)) (unless (equal? status old-status) (let ((song (car status)) (state (cadr status))) (cond ((eq? state 'play) (printf "Now playing: ~a\n" (if song (get-songname song) "(unknown song)"))) ((eq? state 'stop) (printf "STOP\n"))))) (thread-sleep! 1) (loop (get-mpd-status) status))
- Added regex as a dependency; converted eggdoc documentation to wiki format [Ivan Raikov]
- Added new commands supported by recent versions of MPD
- Fixed a bug that caused playlists to be returned incorrectly by mpd:ls/info et al.
- Fixed typo in documentation
- Initial release
Copyright (c) 2006-2007, Hans Bulfone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.