1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2009 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
20 #include "mpdclient.h"
21 #include "screen_utils.h"
22 #include "config.h"
23 #include "options.h"
24 #include "strfsong.h"
25 #include "utils.h"
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <time.h>
30 #include <string.h>
32 #undef ENABLE_FANCY_PLAYLIST_MANAGMENT_CMD_ADD /* broken with song id's */
33 #define ENABLE_FANCY_PLAYLIST_MANAGMENT_CMD_DELETE
34 #define ENABLE_FANCY_PLAYLIST_MANAGMENT_CMD_MOVE
35 #define ENABLE_SONG_ID
36 #define ENABLE_PLCHANGES
38 #define BUFSIZE 1024
40 static bool
41 MPD_ERROR(const struct mpdclient *client)
42 {
43 return client == NULL || client->connection==NULL ||
44 client->connection->error != MPD_ERROR_SUCCESS;
45 }
47 /* filelist sorting functions */
48 static gint
49 compare_filelistentry(gconstpointer filelist_entry1,
50 gconstpointer filelist_entry2)
51 {
52 const mpd_InfoEntity *e1, *e2;
53 int n = 0;
55 e1 = ((const filelist_entry_t *)filelist_entry1)->entity;
56 e2 = ((const filelist_entry_t *)filelist_entry2)->entity;
58 if (e1 && e2 && e1->type == e2->type) {
59 switch (e1->type) {
60 case MPD_INFO_ENTITY_TYPE_DIRECTORY:
61 n = g_utf8_collate(e1->info.directory->path,
62 e2->info.directory->path);
63 break;
64 case MPD_INFO_ENTITY_TYPE_SONG:
65 break;
66 case MPD_INFO_ENTITY_TYPE_PLAYLISTFILE:
67 n = g_utf8_collate(e1->info.playlistFile->path,
68 e2->info.playlistFile->path);
69 }
70 }
71 return n;
72 }
74 /* sort by list-format */
75 gint
76 compare_filelistentry_format(gconstpointer filelist_entry1,
77 gconstpointer filelist_entry2)
78 {
79 const mpd_InfoEntity *e1, *e2;
80 char key1[BUFSIZE], key2[BUFSIZE];
81 int n = 0;
83 e1 = ((const filelist_entry_t *)filelist_entry1)->entity;
84 e2 = ((const filelist_entry_t *)filelist_entry2)->entity;
86 if (e1 && e2 &&
87 e1->type == MPD_INFO_ENTITY_TYPE_SONG &&
88 e2->type == MPD_INFO_ENTITY_TYPE_SONG) {
89 strfsong(key1, BUFSIZE, options.list_format, e1->info.song);
90 strfsong(key2, BUFSIZE, options.list_format, e2->info.song);
91 n = strcmp(key1,key2);
92 }
94 return n;
95 }
98 /* Error callbacks */
99 static gint
100 error_cb(mpdclient_t *c, gint error, const gchar *msg)
101 {
102 GList *list = c->error_callbacks;
104 if (list == NULL)
105 fprintf(stderr, "error [%d]: %s\n", (error & 0xFF), msg);
107 while (list) {
108 mpdc_error_cb_t cb = list->data;
109 if (cb)
110 cb(c, error, msg);
111 list = list->next;
112 }
114 mpd_clearError(c->connection);
115 return error;
116 }
119 /****************************************************************************/
120 /*** mpdclient functions ****************************************************/
121 /****************************************************************************/
123 gint
124 mpdclient_finish_command(mpdclient_t *c)
125 {
126 mpd_finishCommand(c->connection);
128 if (c->connection->error) {
129 gint error = c->connection->error;
131 if (error == MPD_ERROR_ACK &&
132 c->connection->errorCode == MPD_ACK_ERROR_PERMISSION &&
133 screen_auth(c) == 0)
134 return 0;
136 if (error == MPD_ERROR_ACK)
137 error = error | (c->connection->errorCode << 8);
139 error_cb(c, error, c->connection->errorStr);
140 return error;
141 }
143 return 0;
144 }
146 mpdclient_t *
147 mpdclient_new(void)
148 {
149 mpdclient_t *c;
151 c = g_malloc0(sizeof(mpdclient_t));
152 playlist_init(&c->playlist);
154 return c;
155 }
157 void
158 mpdclient_free(mpdclient_t *c)
159 {
160 mpdclient_disconnect(c);
162 mpdclient_playlist_free(&c->playlist);
164 g_list_free(c->error_callbacks);
165 g_list_free(c->playlist_callbacks);
166 g_list_free(c->browse_callbacks);
167 g_free(c);
168 }
170 gint
171 mpdclient_disconnect(mpdclient_t *c)
172 {
173 if (c->connection)
174 mpd_closeConnection(c->connection);
175 c->connection = NULL;
177 if (c->status)
178 mpd_freeStatus(c->status);
179 c->status = NULL;
181 playlist_clear(&c->playlist);
183 if (c->song)
184 c->song = NULL;
186 return 0;
187 }
189 gint
190 mpdclient_connect(mpdclient_t *c,
191 gchar *host,
192 gint port,
193 gfloat _timeout,
194 gchar *password)
195 {
196 gint retval = 0;
198 /* close any open connection */
199 if( c->connection )
200 mpdclient_disconnect(c);
202 /* connect to MPD */
203 c->connection = mpd_newConnection(host, port, _timeout);
204 if( c->connection->error )
205 return error_cb(c, c->connection->error,
206 c->connection->errorStr);
208 /* send password */
209 if( password ) {
210 mpd_sendPasswordCommand(c->connection, password);
211 retval = mpdclient_finish_command(c);
212 }
213 c->need_update = TRUE;
215 return retval;
216 }
218 gint
219 mpdclient_update(mpdclient_t *c)
220 {
221 gint retval = 0;
223 if (MPD_ERROR(c))
224 return -1;
226 /* free the old status */
227 if (c->status)
228 mpd_freeStatus(c->status);
230 /* retrieve new status */
231 mpd_sendStatusCommand(c->connection);
232 c->status = mpd_getStatus(c->connection);
233 if ((retval=mpdclient_finish_command(c)))
234 return retval;
236 if (c->updatingdb && c->updatingdb != c->status->updatingDb)
237 mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
239 c->updatingdb = c->status->updatingDb;
241 /* check if the playlist needs an update */
242 if (c->playlist.id != c->status->playlist) {
243 if (playlist_is_empty(&c->playlist))
244 retval = mpdclient_playlist_update_changes(c);
245 else
246 retval = mpdclient_playlist_update(c);
247 }
249 /* update the current song */
250 if (!c->song || c->status->songid != c->song->id) {
251 c->song = playlist_get_song(c, c->status->song);
252 }
254 c->need_update = FALSE;
256 return retval;
257 }
260 /****************************************************************************/
261 /*** MPD Commands **********************************************************/
262 /****************************************************************************/
264 gint
265 mpdclient_cmd_play(mpdclient_t *c, gint idx)
266 {
267 #ifdef ENABLE_SONG_ID
268 struct mpd_song *song = playlist_get_song(c, idx);
270 if (song)
271 mpd_sendPlayIdCommand(c->connection, song->id);
272 else
273 mpd_sendPlayIdCommand(c->connection, MPD_PLAY_AT_BEGINNING);
274 #else
275 mpd_sendPlayCommand(c->connection, idx);
276 #endif
277 c->need_update = TRUE;
278 return mpdclient_finish_command(c);
279 }
281 gint
282 mpdclient_cmd_pause(mpdclient_t *c, gint value)
283 {
284 mpd_sendPauseCommand(c->connection, value);
285 return mpdclient_finish_command(c);
286 }
288 gint
289 mpdclient_cmd_crop(mpdclient_t *c)
290 {
291 gint error;
292 mpd_Status *status;
293 bool playing;
294 int length, current;
296 mpd_sendStatusCommand(c->connection);
297 status = mpd_getStatus(c->connection);
298 error = mpdclient_finish_command(c);
299 if (error)
300 return error;
302 playing = status->state == MPD_STATUS_STATE_PLAY ||
303 status->state == MPD_STATUS_STATE_PAUSE;
304 length = status->playlistLength;
305 current = status->song;
307 mpd_freeStatus(status);
309 if (!playing || length < 2)
310 return 0;
312 mpd_sendCommandListBegin( c->connection );
314 while (--length >= 0)
315 if (length != current)
316 mpd_sendDeleteCommand(c->connection, length);
318 mpd_sendCommandListEnd(c->connection);
320 return mpdclient_finish_command(c);
321 }
323 gint
324 mpdclient_cmd_stop(mpdclient_t *c)
325 {
326 mpd_sendStopCommand(c->connection);
327 return mpdclient_finish_command(c);
328 }
330 gint
331 mpdclient_cmd_next(mpdclient_t *c)
332 {
333 mpd_sendNextCommand(c->connection);
334 c->need_update = TRUE;
335 return mpdclient_finish_command(c);
336 }
338 gint
339 mpdclient_cmd_prev(mpdclient_t *c)
340 {
341 mpd_sendPrevCommand(c->connection);
342 c->need_update = TRUE;
343 return mpdclient_finish_command(c);
344 }
346 gint
347 mpdclient_cmd_seek(mpdclient_t *c, gint id, gint pos)
348 {
349 mpd_sendSeekIdCommand(c->connection, id, pos);
350 return mpdclient_finish_command(c);
351 }
353 gint
354 mpdclient_cmd_shuffle(mpdclient_t *c)
355 {
356 mpd_sendShuffleCommand(c->connection);
357 c->need_update = TRUE;
358 return mpdclient_finish_command(c);
359 }
361 gint
362 mpdclient_cmd_shuffle_range(mpdclient_t *c, guint start, guint end)
363 {
364 mpd_sendShuffleRangeCommand(c->connection, start, end);
365 c->need_update = TRUE;
366 return mpdclient_finish_command(c);
367 }
369 gint
370 mpdclient_cmd_clear(mpdclient_t *c)
371 {
372 gint retval = 0;
374 mpd_sendClearCommand(c->connection);
375 retval = mpdclient_finish_command(c);
376 /* call playlist updated callback */
377 mpdclient_playlist_callback(c, PLAYLIST_EVENT_CLEAR, NULL);
378 c->need_update = TRUE;
379 return retval;
380 }
382 gint
383 mpdclient_cmd_repeat(mpdclient_t *c, gint value)
384 {
385 mpd_sendRepeatCommand(c->connection, value);
386 return mpdclient_finish_command(c);
387 }
389 gint
390 mpdclient_cmd_random(mpdclient_t *c, gint value)
391 {
392 mpd_sendRandomCommand(c->connection, value);
393 return mpdclient_finish_command(c);
394 }
396 gint
397 mpdclient_cmd_single(mpdclient_t *c, gint value)
398 {
399 mpd_sendSingleCommand(c->connection, value);
400 return mpdclient_finish_command(c);
401 }
403 gint
404 mpdclient_cmd_consume(mpdclient_t *c, gint value)
405 {
406 mpd_sendConsumeCommand(c->connection, value);
407 return mpdclient_finish_command(c);
408 }
410 gint
411 mpdclient_cmd_crossfade(mpdclient_t *c, gint value)
412 {
413 mpd_sendCrossfadeCommand(c->connection, value);
414 return mpdclient_finish_command(c);
415 }
417 gint
418 mpdclient_cmd_db_update(mpdclient_t *c, gchar *path)
419 {
420 gint ret;
422 mpd_sendUpdateCommand(c->connection, path ? path : "");
423 ret = mpdclient_finish_command(c);
425 if (ret == 0)
426 /* set updatingDb to make sure the browse callback
427 gets called even if the update has finished before
428 status is updated */
429 c->updatingdb = 1;
431 return ret;
432 }
434 gint
435 mpdclient_cmd_volume(mpdclient_t *c, gint value)
436 {
437 mpd_sendSetvolCommand(c->connection, value);
438 return mpdclient_finish_command(c);
439 }
441 gint
442 mpdclient_cmd_add_path(mpdclient_t *c, gchar *path_utf8)
443 {
444 mpd_sendAddCommand(c->connection, path_utf8);
445 return mpdclient_finish_command(c);
446 }
448 gint
449 mpdclient_cmd_add(mpdclient_t *c, struct mpd_song *song)
450 {
451 gint retval = 0;
453 if( !song || !song->file )
454 return -1;
456 /* send the add command to mpd */
457 mpd_sendAddCommand(c->connection, song->file);
458 if( (retval=mpdclient_finish_command(c)) )
459 return retval;
461 #ifdef ENABLE_FANCY_PLAYLIST_MANAGMENT_CMD_ADD
462 /* add the song to playlist */
463 playlist_append(&c->playlist, song);
465 /* increment the playlist id, so we don't retrieve a new playlist */
466 c->playlist.id++;
468 /* call playlist updated callback */
469 mpdclient_playlist_callback(c, PLAYLIST_EVENT_ADD, (gpointer) song);
470 #else
471 c->need_update = TRUE;
472 #endif
474 return 0;
475 }
477 gint
478 mpdclient_cmd_delete(mpdclient_t *c, gint idx)
479 {
480 gint retval = 0;
481 struct mpd_song *song;
483 if (idx < 0 || (guint)idx >= playlist_length(&c->playlist))
484 return -1;
486 song = playlist_get(&c->playlist, idx);
488 /* send the delete command to mpd */
489 #ifdef ENABLE_SONG_ID
490 mpd_sendDeleteIdCommand(c->connection, song->id);
491 #else
492 mpd_sendDeleteCommand(c->connection, idx);
493 #endif
494 if( (retval=mpdclient_finish_command(c)) )
495 return retval;
497 #ifdef ENABLE_FANCY_PLAYLIST_MANAGMENT_CMD_DELETE
498 /* increment the playlist id, so we don't retrieve a new playlist */
499 c->playlist.id++;
501 /* remove the song from the playlist */
502 playlist_remove_reuse(&c->playlist, idx);
504 /* call playlist updated callback */
505 mpdclient_playlist_callback(c, PLAYLIST_EVENT_DELETE, (gpointer) song);
507 /* remove references to the song */
508 if (c->song == song) {
509 c->song = NULL;
510 c->need_update = TRUE;
511 }
513 mpd_freeSong(song);
515 #else
516 c->need_update = TRUE;
517 #endif
519 return 0;
520 }
522 gint
523 mpdclient_cmd_move(mpdclient_t *c, gint old_index, gint new_index)
524 {
525 gint n;
526 struct mpd_song *song1, *song2;
528 if (old_index == new_index || new_index < 0 ||
529 (guint)new_index >= c->playlist.list->len)
530 return -1;
532 song1 = playlist_get(&c->playlist, old_index);
533 song2 = playlist_get(&c->playlist, new_index);
535 /* send the move command to mpd */
536 #ifdef ENABLE_SONG_ID
537 mpd_sendSwapIdCommand(c->connection, song1->id, song2->id);
538 #else
539 mpd_sendMoveCommand(c->connection, old_index, new_index);
540 #endif
541 if( (n=mpdclient_finish_command(c)) )
542 return n;
544 #ifdef ENABLE_FANCY_PLAYLIST_MANAGMENT_CMD_MOVE
545 /* update the playlist */
546 playlist_swap(&c->playlist, old_index, new_index);
548 /* increment the playlist id, so we don't retrieve a new playlist */
549 c->playlist.id++;
551 #else
552 c->need_update = TRUE;
553 #endif
555 /* call playlist updated callback */
556 mpdclient_playlist_callback(c, PLAYLIST_EVENT_MOVE, (gpointer) &new_index);
558 return 0;
559 }
561 gint
562 mpdclient_cmd_save_playlist(mpdclient_t *c, gchar *filename_utf8)
563 {
564 gint retval = 0;
566 mpd_sendSaveCommand(c->connection, filename_utf8);
567 if ((retval = mpdclient_finish_command(c)) == 0)
568 mpdclient_browse_callback(c, BROWSE_PLAYLIST_SAVED, NULL);
569 return retval;
570 }
572 gint
573 mpdclient_cmd_load_playlist(mpdclient_t *c, gchar *filename_utf8)
574 {
575 mpd_sendLoadCommand(c->connection, filename_utf8);
576 c->need_update = TRUE;
577 return mpdclient_finish_command(c);
578 }
580 gint
581 mpdclient_cmd_delete_playlist(mpdclient_t *c, gchar *filename_utf8)
582 {
583 gint retval = 0;
585 mpd_sendRmCommand(c->connection, filename_utf8);
586 if ((retval = mpdclient_finish_command(c)) == 0)
587 mpdclient_browse_callback(c, BROWSE_PLAYLIST_DELETED, NULL);
588 return retval;
589 }
592 /****************************************************************************/
593 /*** Callback management functions ******************************************/
594 /****************************************************************************/
596 static void
597 do_list_callbacks(mpdclient_t *c, GList *list, gint event, gpointer data)
598 {
599 while (list) {
600 mpdc_list_cb_t fn = list->data;
602 fn(c, event, data);
603 list = list->next;
604 }
605 }
607 void
608 mpdclient_playlist_callback(mpdclient_t *c, int event, gpointer data)
609 {
610 do_list_callbacks(c, c->playlist_callbacks, event, data);
611 }
613 void
614 mpdclient_install_playlist_callback(mpdclient_t *c,mpdc_list_cb_t cb)
615 {
616 c->playlist_callbacks = g_list_append(c->playlist_callbacks, cb);
617 }
619 void
620 mpdclient_remove_playlist_callback(mpdclient_t *c, mpdc_list_cb_t cb)
621 {
622 c->playlist_callbacks = g_list_remove(c->playlist_callbacks, cb);
623 }
625 void
626 mpdclient_browse_callback(mpdclient_t *c, int event, gpointer data)
627 {
628 do_list_callbacks(c, c->browse_callbacks, event, data);
629 }
632 void
633 mpdclient_install_browse_callback(mpdclient_t *c,mpdc_list_cb_t cb)
634 {
635 c->browse_callbacks = g_list_append(c->browse_callbacks, cb);
636 }
638 void
639 mpdclient_remove_browse_callback(mpdclient_t *c, mpdc_list_cb_t cb)
640 {
641 c->browse_callbacks = g_list_remove(c->browse_callbacks, cb);
642 }
644 void
645 mpdclient_install_error_callback(mpdclient_t *c, mpdc_error_cb_t cb)
646 {
647 c->error_callbacks = g_list_append(c->error_callbacks, cb);
648 }
650 void
651 mpdclient_remove_error_callback(mpdclient_t *c, mpdc_error_cb_t cb)
652 {
653 c->error_callbacks = g_list_remove(c->error_callbacks, cb);
654 }
657 /****************************************************************************/
658 /*** Playlist management functions ******************************************/
659 /****************************************************************************/
661 /* update playlist */
662 gint
663 mpdclient_playlist_update(mpdclient_t *c)
664 {
665 mpd_InfoEntity *entity;
667 if (MPD_ERROR(c))
668 return -1;
670 playlist_clear(&c->playlist);
672 mpd_sendPlaylistInfoCommand(c->connection,-1);
673 while ((entity = mpd_getNextInfoEntity(c->connection))) {
674 if (entity->type == MPD_INFO_ENTITY_TYPE_SONG)
675 playlist_append(&c->playlist, entity->info.song);
677 mpd_freeInfoEntity(entity);
678 }
680 c->playlist.id = c->status->playlist;
681 c->song = NULL;
683 /* call playlist updated callbacks */
684 mpdclient_playlist_callback(c, PLAYLIST_EVENT_UPDATED, NULL);
686 return mpdclient_finish_command(c);
687 }
689 #ifdef ENABLE_PLCHANGES
691 /* update playlist (plchanges) */
692 gint
693 mpdclient_playlist_update_changes(mpdclient_t *c)
694 {
695 mpd_InfoEntity *entity;
697 if (MPD_ERROR(c))
698 return -1;
700 mpd_sendPlChangesCommand(c->connection, c->playlist.id);
702 while ((entity = mpd_getNextInfoEntity(c->connection)) != NULL) {
703 struct mpd_song *song = entity->info.song;
705 if (song->pos >= 0 && (guint)song->pos < c->playlist.list->len) {
706 /* update song */
707 playlist_replace(&c->playlist, song->pos, song);
708 } else {
709 /* add a new song */
710 playlist_append(&c->playlist, song);
711 }
713 mpd_freeInfoEntity(entity);
714 }
716 /* remove trailing songs */
717 while ((guint)c->status->playlistLength < c->playlist.list->len) {
718 guint pos = c->playlist.list->len - 1;
720 /* Remove the last playlist entry */
721 playlist_remove(&c->playlist, pos);
722 }
724 c->song = NULL;
725 c->playlist.id = c->status->playlist;
727 mpdclient_playlist_callback(c, PLAYLIST_EVENT_UPDATED, NULL);
729 return 0;
730 }
732 #else
733 gint
734 mpdclient_playlist_update_changes(mpdclient_t *c)
735 {
736 return mpdclient_playlist_update(c);
737 }
738 #endif
741 /****************************************************************************/
742 /*** Filelist functions *****************************************************/
743 /****************************************************************************/
745 mpdclient_filelist_t *
746 mpdclient_filelist_get(mpdclient_t *c, const gchar *path)
747 {
748 mpdclient_filelist_t *filelist;
749 mpd_InfoEntity *entity;
751 mpd_sendLsInfoCommand(c->connection, path);
752 filelist = filelist_new(path);
753 if (path && path[0] && strcmp(path, "/"))
754 /* add a dummy entry for ./.. */
755 filelist_append(filelist, NULL);
757 while ((entity=mpd_getNextInfoEntity(c->connection))) {
758 filelist_append(filelist, entity);
759 }
761 /* If there's an error, ignore it. We'll return an empty filelist. */
762 mpdclient_finish_command(c);
764 filelist_sort_dir_play(filelist, compare_filelistentry);
766 return filelist;
767 }
769 mpdclient_filelist_t *
770 mpdclient_filelist_search(mpdclient_t *c,
771 int exact_match,
772 int table,
773 gchar *filter_utf8)
774 {
775 mpdclient_filelist_t *filelist;
776 mpd_InfoEntity *entity;
778 if (exact_match)
779 mpd_sendFindCommand(c->connection, table, filter_utf8);
780 else
781 mpd_sendSearchCommand(c->connection, table, filter_utf8);
782 filelist = filelist_new(NULL);
784 while ((entity=mpd_getNextInfoEntity(c->connection)))
785 filelist_append(filelist, entity);
787 if (mpdclient_finish_command(c)) {
788 filelist_free(filelist);
789 return NULL;
790 }
792 return filelist;
793 }
795 mpdclient_filelist_t *
796 mpdclient_filelist_update(mpdclient_t *c, mpdclient_filelist_t *filelist)
797 {
798 if (filelist != NULL) {
799 gchar *path = g_strdup(filelist->path);
801 filelist_free(filelist);
802 filelist = mpdclient_filelist_get(c, path);
803 g_free(path);
804 return filelist;
805 }
806 return NULL;
807 }
809 int
810 mpdclient_filelist_add_all(mpdclient_t *c, mpdclient_filelist_t *fl)
811 {
812 guint i;
814 if (filelist_is_empty(fl))
815 return 0;
817 mpd_sendCommandListBegin(c->connection);
819 for (i = 0; i < filelist_length(fl); ++i) {
820 filelist_entry_t *entry = filelist_get(fl, i);
821 mpd_InfoEntity *entity = entry->entity;
823 if (entity && entity->type == MPD_INFO_ENTITY_TYPE_SONG) {
824 struct mpd_song *song = entity->info.song;
826 mpd_sendAddCommand(c->connection, song->file);
827 }
828 }
830 mpd_sendCommandListEnd(c->connection);
831 return mpdclient_finish_command(c);
832 }
834 GList *
835 mpdclient_get_artists(mpdclient_t *c)
836 {
837 gchar *str = NULL;
838 GList *list = NULL;
840 mpd_sendListCommand(c->connection, MPD_TABLE_ARTIST, NULL);
841 while ((str = mpd_getNextArtist(c->connection)))
842 list = g_list_append(list, (gpointer) str);
844 if (mpdclient_finish_command(c))
845 return string_list_free(list);
847 return list;
848 }
850 GList *
851 mpdclient_get_albums(mpdclient_t *c, gchar *artist_utf8)
852 {
853 gchar *str = NULL;
854 GList *list = NULL;
856 mpd_sendListCommand(c->connection, MPD_TABLE_ALBUM, artist_utf8);
857 while ((str = mpd_getNextAlbum(c->connection)))
858 list = g_list_append(list, (gpointer) str);
860 if (mpdclient_finish_command(c))
861 return string_list_free(list);
863 return list;
864 }