]> Joshua Wise's Git repositories - patchfork.git/blame_incremental - inc/Net/Net/MPD/Playlist.php
initial import from pitchfork-0.5.5
[patchfork.git] / inc / Net / Net / MPD / Playlist.php
... / ...
CommitLineData
1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3/**
4 * MPD Interaction API
5 *
6 * Net_MPD deals with socket interaction with MPD to ease the
7 * use of MPD in web applications.
8 *
9 * PHP Version 5
10 *
11 * @package Net_MPD
12 * @category Networking
13 * @author Graham Christensen <graham.christensen@itrebal.com>
14 * @copyright 2006 Graham Christensen
15 * @license PHP License 3.01
16 * @version CVS: $ID:$
17 */
18
19/**
20 * API for the playlist portion of Music Player Daemon commands
21 *
22 * Used for maintaining, creating, and utilizing playlists in MPD
23 *
24 * @category Networking
25 * @package Net_MPD
26 * @author Graham Christensen <graham.christensen@itrebal.com>
27 * @copyright 2006 Graham Christensen
28 * @license http://www.php.net/license/3_01.txt
29 * @vers
30 */
31class Net_MPD_Playlist extends Net_MPD_Common
32{
33 /**
34 * List playlists in specified directory
35 *
36 * @param $dir string directory path, optional
37 * @return bool true on success int on failure
38 */
39 public function getPlaylists($dir = '')
40 {
41 $out = $this->runCommand('lsinfo', $dir);
42 return $out['playlist'];
43 }
44
45 /**
46 * Search for data in the playlist
47 *
48 * @param array $params array('search_field' => 'search for')
49 * @param bool $caseSensitive True for case sensitivity, false for not [default false]
50 * @return array
51 */
52 public function find($params, $caseSensitive = false)
53 {
54 $prms = array();
55 foreach($params as $key => $value) {
56 $prms[] = $key;
57 $prms[] = $value;
58 }
59 $cmd = $caseSensitive ? 'playlistfind' : 'playlistsearch';
60
61 $out = $this->runCommand($cmd, $prms);
62 if (!isset($out['file'])) {
63 return array();
64 }
65 return $out['file'];
66 }
67
68 /* Tests whether playlistfind is avilable. If playlistfind
69 * is available playlistsearch is as well
70 *
71 * @return boolean
72 */
73 public function hasFind() {
74 return $this->hasCommand("playlistfind");
75 }
76
77 /**
78 * Add file to playlist
79 *
80 * @param $file string filename
81 * @return bool
82 */
83 public function addSong($file)
84 {
85 $this->runCommand('add', $file);
86 return true;
87 }
88
89
90
91 /**
92 * Clear the playlist
93 *
94 * @return bool
95 */
96 public function clear()
97 {
98 $this->runCommand('clear');
99 return true;
100 }
101
102
103
104 /**
105 * Gets the current song and related information
106 *
107 * @return array of data
108 */
109 public function getCurrentSong()
110 {
111 $out = $this->runCommand('currentsong');
112 if (!isset($out['file'][0])) {
113 return false;
114 }
115 return $out['file'][0];
116 }
117
118
119
120 /**
121 * Delete song from playlist
122 *
123 * @param $song int song position in playlist
124 * @return bool
125 */
126 public function deleteSong($song)
127 {
128 $this->runCommand('delete', $song);
129 return true;
130 }
131
132
133
134 /**
135 * Delete song from playlist by song Id
136 *
137 * @param $id int song Id
138 * @return bool
139 */
140 public function deleteSongId($id)
141 {
142 $this->runCommand('deleteid', $id);
143 return true;
144 }
145
146
147
148 /**
149 * Loads a playlist into the current playlist
150 *
151 * @param $playlist string playlist name
152 * @return bool
153 */
154 public function loadPlaylist($playlist)
155 {
156 $this->runCommand('load', $playlist);
157 return true;
158 }
159
160
161
162 /**
163 * Move song in the playlist
164 *
165 * @param $from int song position in the playlist
166 * @param $to int song position to move it to
167 * @return bool
168 */
169 public function moveSong($from, $to)
170 {
171 $this->runCommand('move', array($from, $to));
172 return true;
173 }
174
175
176
177 /**
178 * Move song in the playlist by Id
179 *
180 * @param $from int song Id
181 * @param $to int song Id to move it to
182 * @return bool
183 */
184 public function moveSongId($fromId, $toId)
185 {
186 $this->runCommand('moveid', array($fromId, $toId));
187 return true;
188 }
189
190
191
192 /**
193 * Displays metadata for songs in the playlist by position Id
194 *
195 * @param $song int song position, optional
196 * @return array of song metadata
197 */
198 public function getPlaylistInfo($song = null)
199 {
200 $out = $this->runCommand('playlistinfo', $song, 0);
201 return isset($out['file']) ? $out['file'] : array();
202 }
203
204
205
206 /**
207 * Displays metadata for songs in the playlist
208 *
209 * @param $song int song Id, optional
210 * @return array of song metadata
211 */
212 public function getPlaylistInfoId($song = null)
213 {
214 return $this->runCommand('playlistid', $song);
215 }
216
217
218
219 /**
220 * Get playlist changes
221 *
222 * @param $version int playlist version
223 * @param $limit boolean true to limit return
224 * to only position and id
225 *
226 * @return array of changes
227 */
228 public function getChanges($version, $limit = false)
229 {
230 $cmd = $limit ? 'plchangesposid' : 'plchanges';
231
232 return $this->runCommand($cmd, $version);
233 }
234
235
236
237 /**
238 * Delete a playlist
239 *
240 * @param $playlist string playlist name
241 * @return true
242 */
243 public function deletePlaylist($playlist)
244 {
245 $this->runCommand('rm', $playlist);
246 return true;
247 }
248
249
250
251 /**
252 * Save the playlist
253 *
254 * @param $playlist string playlist name
255 * @return bool
256 */
257 public function savePlaylist($playlist)
258 {
259 $this->runCommand('save', $playlist);
260 return true;
261 }
262
263
264
265 /**
266 * Shuffle the playlist
267 *
268 * @return true
269 */
270 public function shuffle()
271 {
272 $this->runCommand('shuffle');
273 return true;
274 }
275
276
277
278 /**
279 * Swap song by position in the playlist
280 *
281 * @param $song1 int song position from
282 * @param $song2 int song position to
283 * @return bool
284 */
285 public function swapSong($song1, $song2)
286 {
287 $this->runCommand('swap', array($song1, $song2));
288 return true;
289 }
290
291
292
293 /**
294 * Swaps a song with another song, by Id
295 *
296 * @param $song1 int Id of the first song
297 * @param $song2 int Id of the second song
298 * @return true
299 */
300 public function swapSongId($songId1, $songId2)
301 {
302 $this->runCommand('swapid', array($songId1, $songId2));
303 return true;
304 }
305}
306?>
This page took 0.024314 seconds and 4 git commands to generate.