Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
[[tags:egg]] == mpd-client Interface to the [[http://www.musicpd.org/|Music Player Daemon]]. [[toc:]] == Documentation This extension allows convenient access to the tcp interface of [[http://www.musicpd.org/|MPD]]. === Connecting to MPD and obtaining connection/server information <procedure>(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. <procedure>(disconnect CONN)</procedure> Closes the connection to MPD. {{CONN}} should not be used anymore after calling this function. <procedure>(mpd-connection? CONN)</procedure> Returns {{#t}} if {{CONN}} is an MPD connection object, {{#f}} otherwise. <procedure>(mpd-host CONN)</procedure> Returns the hostname field of the MPD connection object {{CONN}}. <procedure>(mpd-port CONN)</procedure> Returns the port field of the MPD connection object {{CONN}}. <procedure>(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. <procedure>(mpd-version CONN)</procedure> Returns the version field of the MPD connection object {{CONN}} which contains the version number received by the MPD server. <procedure>(ping CONN)</procedure> Sends a {{ping}} command to the MPD server, reconnecting if necessary. <procedure>(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. <procedure>(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> <procedure>(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> <procedure>(shutdown-server! CONN)</procedure> Kill MPD. <procedure>(get-commands CONN)</procedure> Returns a list of commands the current user has access to. === Controlling playback <procedure>(play! CONN #!optional SONG TIME)</procedure> Start playing at song {{SONG}} (or the first in playlist) at {{TIME}} (in seconds). <procedure>(next-song! CONN)</procedure> Play the next song in the playlist. <procedure>(previous-song! CONN)</procedure> Play the previous song in the playlist. <procedure>(stop! CONN)</procedure> Stop playback. <procedure>(pause! CONN PAUSE?)</procedure> Pause if {{PAUSE?}} is true, resume playing otherwise. <procedure>(set-options! CONN . OPTS)</procedure> Set playback options. Options are: {{#:crossfade}}, {{#:random}}, {{#:repeat}} and {{#:volume}} and they can be mapped to arguments. === Managing output devices <procedure>(get-output-devices CONN)</procedure> Returns a list of alists describing the available output devices. <procedure>(enable-output-device! CONN ID)</procedure> Enables the output device with id {{ID}}. <procedure>(disable-output-device! CONN ID)</procedure> Disables the output device with id {{ID}}. === Querying and modifying the current playlist <procedure>(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> <procedure>(get-current-song CONN)</procedure> Returns an alist with information about the current song (the same information that {{(get-playlist)}} returns). <procedure>(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)}}. <procedure>(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. <procedure>(move-song! CONN FROM TO)</procedure> Move song at position {{FROM}} to {{TO}}. The playlist version is incremented by 1. <procedure>(swap-songs! CONN SONG1 SONG2)</procedure> Swap position of the two songs. <procedure>(remove-song! CONN SONG)</procedure> Remove the song SONG (position or ID) from playlist. The playlist version is incremented by 1. <procedure>(shuffle-playlist! CONN)</procedure> Shuffles the current playlist and increments the playlist version by 1. <procedure>(clear-playlist! CONN)</procedure> Clears the current playlist, incrementing playlist version by 1. === Managing stored playlist <procedure>(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. <procedure>(remove-playlist! CONN PLAYLIST)</procedure> Removes the playlist named {{"PLAYLIST.m3u"}} from the playlist directory. <procedure>(save-playlist! CONN PLAYLIST)</procedure> Saves the current playlist to {{"PLAYLIST.m3u"}} in the playlist directory. === Querying/Updating song database <procedure>(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). <procedure>(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). <procedure>(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. <procedure>(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. <procedure>(list-directory CONN [PATH])</procedure> Like {{(list-directory/r)}}, with {{FULL}} as #t. The data is returned as a list of alists. <procedure>(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). == Examples #!/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 === Maintainer [[/users/wasamasa|wasamasa]] === Repository This egg is hosted on the CHICKEN Subversion repository: [[https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/mpd-client|https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/mpd-client]] If you want to check out the source code repository of this egg and you are not familiar with Subversion, see [[/egg-svn-checkout|this page]]. === Author [[http://www.nil.at/|Hans Bulfone]] === Version history ; 2.1 : Convert elapsed time to number, current track as string [Vasilij Schneidermann] ; 2.0 : Port to C5 [Vasilij Schneidermann] ; 1.12 : Added regex as a dependency; converted eggdoc documentation to wiki format [Ivan Raikov] ; 1.1 : Added new commands supported by recent versions of MPD ; 1.02 : Fixed a bug that caused playlists to be returned incorrectly by {{mpd:ls/info}} et al. ; 1.01 : Fixed typo in documentation ; 1.0 : Initial release === License 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.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you add 22 to 2?