Interface to the Music Player Daemon.
- About this egg
This extension allows convenient access to the tcp interface of MPD.
Connecting to MPD and obtaining connection/server information
- (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 CONNprocedure
Closes the connection to MPD. CONN should not be used anymore after calling this function.
- mpd-connection? CONNprocedure
Returns #t if CONN is an MPD connection object, #f otherwise.
- mpd-host CONNprocedure
Returns the hostname field of the MPD connection object CONN.
- mpd-port CONNprocedure
Returns the port field of the MPD connection object CONN.
- mpd-password CONNprocedure
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 CONNprocedure
Returns the version field of the MPD connection object CONN which contains the version number received by the MPD server.
- clear-error! CONNprocedure
Clears the current error message (which is returned by (get-status)). This is also done by any command that starts playback.
- get-stats CONNprocedure
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 CONNprocedure
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! CONNprocedure
- get-commands CONNprocedure
Returns a list of commands the current user has access to.
- play! CONN #!optional SONG TIMEprocedure
Start playing at song SONG (or the first in playlist) at TIME (in seconds).
- next-song! CONNprocedure
Play the next song in the playlist.
- previous-song! CONNprocedure
Play the previous song in the playlist.
- stop! CONNprocedure
- pause! CONN PAUSE?procedure
Pause if PAUSE? is true, resume playing otherwise.
- set-options! CONN #!rest OPTSprocedure
Set playback options. Options are: #:crossfade, #:random, #:repeat and #:volume and they can be mapped to arguments.
Managing output devices
- get-output-devices CONNprocedure
Returns a list of alists describing the available output devices.
- enable-output-device! CONN IDprocedure
Enables the output device with id ID.
- disable-output-device! CONN IDprocedure
Disables the output device with id ID.
Querying and modifying the current playlist
- get-playlist CONN #!optional IDprocedure
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 CONNprocedure
Returns an alist with information about the current song (the same information that (get-playlist) returns).
- get-playlist-changes CONN VERSIONprocedure
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 PATHprocedure
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 TOprocedure
Move song at position FROM to TO. The playlist version is incremented by 1.
- swap-songs! CONN SONG1 SONG2procedure
Swap position of the two songs.
- remove-song! CONN SONGprocedure
Remove the song SONG (position or ID) from playlist. The playlist version is incremented by 1.
- shuffle-playlist! CONNprocedure
Shuffles the current playlist and increments the playlist version by 1.
- clear-playlist! CONNprocedure
Clears the current playlist, incrementing playlist version by 1.
Managing stored playlist
- load-playlist! CONN PLAYLISTprocedure
Loads the playlist named "PLAYLIST.m3u" from the playlist directory. The playlist version is incremented by the number of songs added.
- remove-playlist! CONN PLAYLISTprocedure
Removes the playlist named "PLAYLIST.m3u" from the playlist directory.
- save-playlist! CONN PLAYLISTprocedure
Saves the current playlist to "PLAYLIST.m3u" in the playlist directory.
Querying/Updating song database
- find-songs CONN TYPE STRINGprocedure
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 SEARCHSTRINGprocedure
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 #!optional PATHprocedure
Like (list-directory/r), with FULL as #t. The data is returned as a list of alists.
- update-song-database! CONN #!optional PATHprocedure
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 (import (chicken base)) (import (chicken format)) (import (srfi 18)) (import mpd-client) (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))
About this egg
This egg is hosted on the CHICKEN Subversion repository:
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
- Convert elapsed time to number, current track as string [Vasilij Schneidermann]
- Port to C5 [Vasilij Schneidermann]
- 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.