2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Net_MPD deals with socket interaction with MPD to ease the
7 * use of MPD in web applications.
12 * @category Networking
13 * @author Graham Christensen <graham.christensen@itrebal.com>
14 * @copyright 2006 Graham Christensen
15 * @license PHP License 3.01
20 * API for the playlist portion of Music Player Daemon commands
22 * Used for maintaining, creating, and utilizing playlists in MPD
24 * @category Networking
26 * @author Graham Christensen <graham.christensen@itrebal.com>
27 * @copyright 2006 Graham Christensen
28 * @license http://www.php.net/license/3_01.txt
31 class Net_MPD_Playlist extends Net_MPD_Common
34 * List playlists in specified directory
36 * @param $dir string directory path, optional
37 * @return bool true on success int on failure
39 public function getPlaylists($dir = '')
41 $out = $this->runCommand('lsinfo', $dir);
42 return $out['playlist'];
46 * Search for data in the playlist
48 * @param array $params array('search_field' => 'search for')
49 * @param bool $caseSensitive True for case sensitivity, false for not [default false]
52 public function find($params, $caseSensitive = false)
55 foreach($params as $key => $value) {
59 $cmd = $caseSensitive ? 'playlistfind' : 'playlistsearch';
61 $out = $this->runCommand($cmd, $prms);
62 if (!isset($out['file'])) {
68 /* Tests whether playlistfind is avilable. If playlistfind
69 * is available playlistsearch is as well
73 public function hasFind() {
74 return $this->hasCommand("playlistfind");
78 * Add file to playlist
80 * @param $file string filename
83 public function addSong($file)
85 $this->runCommand('add', $file);
96 public function clear()
98 $this->runCommand('clear');
105 * Gets the current song and related information
107 * @return array of data
109 public function getCurrentSong()
111 $out = $this->runCommand('currentsong');
112 if (!isset($out['file'][0])) {
115 return $out['file'][0];
121 * Delete song from playlist
123 * @param $song int song position in playlist
126 public function deleteSong($song)
128 $this->runCommand('delete', $song);
135 * Delete song from playlist by song Id
137 * @param $id int song Id
140 public function deleteSongId($id)
142 $this->runCommand('deleteid', $id);
149 * Loads a playlist into the current playlist
151 * @param $playlist string playlist name
154 public function loadPlaylist($playlist)
156 $this->runCommand('load', $playlist);
163 * Move song in the playlist
165 * @param $from int song position in the playlist
166 * @param $to int song position to move it to
169 public function moveSong($from, $to)
171 $this->runCommand('move', array($from, $to));
178 * Move song in the playlist by Id
180 * @param $from int song Id
181 * @param $to int song Id to move it to
184 public function moveSongId($fromId, $toId)
186 $this->runCommand('moveid', array($fromId, $toId));
193 * Displays metadata for songs in the playlist by position Id
195 * @param $song int song position, optional
196 * @return array of song metadata
198 public function getPlaylistInfo($song = null)
200 $out = $this->runCommand('playlistinfo', $song, 0);
201 return isset($out['file']) ? $out['file'] : array();
207 * Displays metadata for songs in the playlist
209 * @param $song int song Id, optional
210 * @return array of song metadata
212 public function getPlaylistInfoId($song = null)
214 return $this->runCommand('playlistid', $song);
220 * Get playlist changes
222 * @param $version int playlist version
223 * @param $limit boolean true to limit return
224 * to only position and id
226 * @return array of changes
228 public function getChanges($version, $limit = false)
230 $cmd = $limit ? 'plchangesposid' : 'plchanges';
232 return $this->runCommand($cmd, $version);
240 * @param $playlist string playlist name
243 public function deletePlaylist($playlist)
245 $this->runCommand('rm', $playlist);
254 * @param $playlist string playlist name
257 public function savePlaylist($playlist)
259 $this->runCommand('save', $playlist);
266 * Shuffle the playlist
270 public function shuffle()
272 $this->runCommand('shuffle');
279 * Swap song by position in the playlist
281 * @param $song1 int song position from
282 * @param $song2 int song position to
285 public function swapSong($song1, $song2)
287 $this->runCommand('swap', array($song1, $song2));
294 * Swaps a song with another song, by Id
296 * @param $song1 int Id of the first song
297 * @param $song2 int Id of the second song
300 public function swapSongId($songId1, $songId2)
302 $this->runCommand('swapid', array($songId1, $songId2));