Code

filelist: removed "path" attribute
[ncmpc.git] / src / mpdclient.c
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)
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;
119 /****************************************************************************/
120 /*** mpdclient functions ****************************************************/
121 /****************************************************************************/
123 static gint
124 mpdclient_handle_error(mpdclient_t *c)
126         enum mpd_error error = c->connection->error;
128         if (error == MPD_ERROR_SUCCESS)
129                 return 0;
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;
143 gint
144 mpdclient_finish_command(mpdclient_t *c)
146         mpd_finishCommand(c->connection);
147         return mpdclient_handle_error(c);
150 mpdclient_t *
151 mpdclient_new(void)
153         mpdclient_t *c;
155         c = g_malloc0(sizeof(mpdclient_t));
156         playlist_init(&c->playlist);
157         c->volume = MPD_STATUS_NO_VOLUME;
159         return c;
162 void
163 mpdclient_free(mpdclient_t *c)
165         mpdclient_disconnect(c);
167         mpdclient_playlist_free(&c->playlist);
169         g_list_free(c->error_callbacks);
170         g_list_free(c->playlist_callbacks);
171         g_list_free(c->browse_callbacks);
172         g_free(c);
175 gint
176 mpdclient_disconnect(mpdclient_t *c)
178         if (c->connection)
179                 mpd_closeConnection(c->connection);
180         c->connection = NULL;
182         if (c->status)
183                 mpd_freeStatus(c->status);
184         c->status = NULL;
186         playlist_clear(&c->playlist);
188         if (c->song)
189                 c->song = NULL;
191         return 0;
194 gint
195 mpdclient_connect(mpdclient_t *c,
196                   const gchar *host,
197                   gint port,
198                   gfloat _timeout,
199                   const gchar *password)
201         gint retval = 0;
203         /* close any open connection */
204         if( c->connection )
205                 mpdclient_disconnect(c);
207         /* connect to MPD */
208         c->connection = mpd_newConnection(host, port, _timeout);
209         if( c->connection->error )
210                 return error_cb(c, c->connection->error,
211                                 c->connection->errorStr);
213         /* send password */
214         if( password ) {
215                 mpd_sendPasswordCommand(c->connection, password);
216                 retval = mpdclient_finish_command(c);
217         }
218         c->need_update = TRUE;
220         return retval;
223 gint
224 mpdclient_update(mpdclient_t *c)
226         gint retval = 0;
228         c->volume = MPD_STATUS_NO_VOLUME;
230         if (MPD_ERROR(c))
231                 return -1;
233         /* free the old status */
234         if (c->status)
235                 mpd_freeStatus(c->status);
237         /* retrieve new status */
238         mpd_sendStatusCommand(c->connection);
239         c->status = mpd_getStatus(c->connection);
240         if ((retval=mpdclient_finish_command(c)))
241                 return retval;
243         if (c->updatingdb && c->updatingdb != c->status->updatingDb)
244                 mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
246         c->updatingdb = c->status->updatingDb;
247         c->volume = c->status->volume;
249         /* check if the playlist needs an update */
250         if (c->playlist.id != c->status->playlist) {
251                 if (playlist_is_empty(&c->playlist))
252                         retval = mpdclient_playlist_update_changes(c);
253                 else
254                         retval = mpdclient_playlist_update(c);
255         }
257         /* update the current song */
258         if (!c->song || c->status->songid != c->song->id) {
259                 c->song = playlist_get_song(c, c->status->song);
260         }
262         c->need_update = FALSE;
264         return retval;
268 /****************************************************************************/
269 /*** MPD Commands  **********************************************************/
270 /****************************************************************************/
272 gint
273 mpdclient_cmd_play(mpdclient_t *c, gint idx)
275 #ifdef ENABLE_SONG_ID
276         struct mpd_song *song = playlist_get_song(c, idx);
278         if (song)
279                 mpd_sendPlayIdCommand(c->connection, song->id);
280         else
281                 mpd_sendPlayIdCommand(c->connection, MPD_PLAY_AT_BEGINNING);
282 #else
283         mpd_sendPlayCommand(c->connection, idx);
284 #endif
285         c->need_update = TRUE;
286         return mpdclient_finish_command(c);
289 gint
290 mpdclient_cmd_pause(mpdclient_t *c, gint value)
292         mpd_sendPauseCommand(c->connection, value);
293         return mpdclient_finish_command(c);
296 gint
297 mpdclient_cmd_crop(mpdclient_t *c)
299         gint error;
300         mpd_Status *status;
301         bool playing;
302         int length, current;
304         mpd_sendStatusCommand(c->connection);
305         status = mpd_getStatus(c->connection);
306         error = mpdclient_finish_command(c);
307         if (error)
308                 return error;
310         playing = status->state == MPD_STATUS_STATE_PLAY ||
311                 status->state == MPD_STATUS_STATE_PAUSE;
312         length = status->playlistLength;
313         current = status->song;
315         mpd_freeStatus(status);
317         if (!playing || length < 2)
318                 return 0;
320         mpd_sendCommandListBegin( c->connection );
322         while (--length >= 0)
323                 if (length != current)
324                         mpd_sendDeleteCommand(c->connection, length);
326         mpd_sendCommandListEnd(c->connection);
328         return mpdclient_finish_command(c);
331 gint
332 mpdclient_cmd_stop(mpdclient_t *c)
334         mpd_sendStopCommand(c->connection);
335         return mpdclient_finish_command(c);
338 gint
339 mpdclient_cmd_next(mpdclient_t *c)
341         mpd_sendNextCommand(c->connection);
342         c->need_update = TRUE;
343         return mpdclient_finish_command(c);
346 gint
347 mpdclient_cmd_prev(mpdclient_t *c)
349         mpd_sendPrevCommand(c->connection);
350         c->need_update = TRUE;
351         return mpdclient_finish_command(c);
354 gint
355 mpdclient_cmd_seek(mpdclient_t *c, gint id, gint pos)
357         mpd_sendSeekIdCommand(c->connection, id, pos);
358         return mpdclient_finish_command(c);
361 gint
362 mpdclient_cmd_shuffle(mpdclient_t *c)
364         mpd_sendShuffleCommand(c->connection);
365         c->need_update = TRUE;
366         return mpdclient_finish_command(c);
369 gint
370 mpdclient_cmd_shuffle_range(mpdclient_t *c, guint start, guint end)
372         mpd_sendShuffleRangeCommand(c->connection, start, end);
373         c->need_update = TRUE;
374         return mpdclient_finish_command(c);
377 gint
378 mpdclient_cmd_clear(mpdclient_t *c)
380         gint retval = 0;
382         mpd_sendClearCommand(c->connection);
383         retval = mpdclient_finish_command(c);
384         /* call playlist updated callback */
385         mpdclient_playlist_callback(c, PLAYLIST_EVENT_CLEAR, NULL);
386         c->need_update = TRUE;
387         return retval;
390 gint
391 mpdclient_cmd_repeat(mpdclient_t *c, gint value)
393         mpd_sendRepeatCommand(c->connection, value);
394         return mpdclient_finish_command(c);
397 gint
398 mpdclient_cmd_random(mpdclient_t *c, gint value)
400         mpd_sendRandomCommand(c->connection, value);
401         return mpdclient_finish_command(c);
404 gint
405 mpdclient_cmd_single(mpdclient_t *c, gint value)
407         mpd_sendSingleCommand(c->connection, value);
408         return mpdclient_finish_command(c);
411 gint
412 mpdclient_cmd_consume(mpdclient_t *c, gint value)
414         mpd_sendConsumeCommand(c->connection, value);
415         return mpdclient_finish_command(c);
418 gint
419 mpdclient_cmd_crossfade(mpdclient_t *c, gint value)
421         mpd_sendCrossfadeCommand(c->connection, value);
422         return mpdclient_finish_command(c);
425 gint
426 mpdclient_cmd_db_update(mpdclient_t *c, const gchar *path)
428         gint ret;
430         mpd_sendUpdateCommand(c->connection, path ? path : "");
431         ret = mpdclient_finish_command(c);
433         if (ret == 0)
434                 /* set updatingDb to make sure the browse callback
435                    gets called even if the update has finished before
436                    status is updated */
437                 c->updatingdb = 1;
439         return ret;
442 gint
443 mpdclient_cmd_volume(mpdclient_t *c, gint value)
445         mpd_sendSetvolCommand(c->connection, value);
446         return mpdclient_finish_command(c);
449 gint mpdclient_cmd_volume_up(struct mpdclient *c)
451         if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME)
452                 return 0;
454         if (c->volume == MPD_STATUS_NO_VOLUME)
455                 c->volume = c->status->volume;
457         if (c->volume >= 100)
458                 return 0;
460         return mpdclient_cmd_volume(c, ++c->volume);
463 gint mpdclient_cmd_volume_down(struct mpdclient *c)
465         if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME)
466                 return 0;
468         if (c->volume == MPD_STATUS_NO_VOLUME)
469                 c->volume = c->status->volume;
471         if (c->volume <= 0)
472                 return 0;
474         return mpdclient_cmd_volume(c, --c->volume);
477 gint
478 mpdclient_cmd_add_path(mpdclient_t *c, const gchar *path_utf8)
480         mpd_sendAddCommand(c->connection, path_utf8);
481         return mpdclient_finish_command(c);
484 gint
485 mpdclient_cmd_add(mpdclient_t *c, const struct mpd_song *song)
487         gint retval = 0;
489         if( !song || !song->file )
490                 return -1;
492         /* send the add command to mpd */
493         mpd_sendAddCommand(c->connection, song->file);
494         if( (retval=mpdclient_finish_command(c)) )
495                 return retval;
497 #ifdef ENABLE_FANCY_PLAYLIST_MANAGMENT_CMD_ADD
498         /* add the song to playlist */
499         playlist_append(&c->playlist, song);
501         /* increment the playlist id, so we don't retrieve a new playlist */
502         c->playlist.id++;
504         /* call playlist updated callback */
505         mpdclient_playlist_callback(c, PLAYLIST_EVENT_ADD, (gpointer) song);
506 #else
507         c->need_update = TRUE;
508 #endif
510         return 0;
513 gint
514 mpdclient_cmd_delete(mpdclient_t *c, gint idx)
516         gint retval = 0;
517         struct mpd_song *song;
519         if (idx < 0 || (guint)idx >= playlist_length(&c->playlist))
520                 return -1;
522         song = playlist_get(&c->playlist, idx);
524         /* send the delete command to mpd */
525 #ifdef ENABLE_SONG_ID
526         mpd_sendDeleteIdCommand(c->connection, song->id);
527 #else
528         mpd_sendDeleteCommand(c->connection, idx);
529 #endif
530         if( (retval=mpdclient_finish_command(c)) )
531                 return retval;
533 #ifdef ENABLE_FANCY_PLAYLIST_MANAGMENT_CMD_DELETE
534         /* increment the playlist id, so we don't retrieve a new playlist */
535         c->playlist.id++;
537         /* remove the song from the playlist */
538         playlist_remove_reuse(&c->playlist, idx);
540         /* call playlist updated callback */
541         mpdclient_playlist_callback(c, PLAYLIST_EVENT_DELETE, (gpointer) song);
543         /* remove references to the song */
544         if (c->song == song) {
545                 c->song = NULL;
546                 c->need_update = TRUE;
547         }
549         mpd_freeSong(song);
551 #else
552         c->need_update = TRUE;
553 #endif
555         return 0;
558 gint
559 mpdclient_cmd_move(mpdclient_t *c, gint old_index, gint new_index)
561         gint n;
562         struct mpd_song *song1, *song2;
564         if (old_index == new_index || new_index < 0 ||
565             (guint)new_index >= c->playlist.list->len)
566                 return -1;
568         song1 = playlist_get(&c->playlist, old_index);
569         song2 = playlist_get(&c->playlist, new_index);
571         /* send the move command to mpd */
572 #ifdef ENABLE_SONG_ID
573         mpd_sendSwapIdCommand(c->connection, song1->id, song2->id);
574 #else
575         mpd_sendMoveCommand(c->connection, old_index, new_index);
576 #endif
577         if( (n=mpdclient_finish_command(c)) )
578                 return n;
580 #ifdef ENABLE_FANCY_PLAYLIST_MANAGMENT_CMD_MOVE
581         /* update the playlist */
582         playlist_swap(&c->playlist, old_index, new_index);
584         /* increment the playlist id, so we don't retrieve a new playlist */
585         c->playlist.id++;
587 #else
588         c->need_update = TRUE;
589 #endif
591         /* call playlist updated callback */
592         mpdclient_playlist_callback(c, PLAYLIST_EVENT_MOVE, (gpointer) &new_index);
594         return 0;
597 gint
598 mpdclient_cmd_save_playlist(mpdclient_t *c, const gchar *filename_utf8)
600         gint retval = 0;
602         mpd_sendSaveCommand(c->connection, filename_utf8);
603         if ((retval = mpdclient_finish_command(c)) == 0)
604                 mpdclient_browse_callback(c, BROWSE_PLAYLIST_SAVED, NULL);
605         return retval;
608 gint
609 mpdclient_cmd_load_playlist(mpdclient_t *c, const gchar *filename_utf8)
611         mpd_sendLoadCommand(c->connection, filename_utf8);
612         c->need_update = TRUE;
613         return mpdclient_finish_command(c);
616 gint
617 mpdclient_cmd_delete_playlist(mpdclient_t *c, const gchar *filename_utf8)
619         gint retval = 0;
621         mpd_sendRmCommand(c->connection, filename_utf8);
622         if ((retval = mpdclient_finish_command(c)) == 0)
623                 mpdclient_browse_callback(c, BROWSE_PLAYLIST_DELETED, NULL);
624         return retval;
628 /****************************************************************************/
629 /*** Callback management functions ******************************************/
630 /****************************************************************************/
632 static void
633 do_list_callbacks(mpdclient_t *c, GList *list, gint event, gpointer data)
635         while (list) {
636                 mpdc_list_cb_t fn = list->data;
638                 fn(c, event, data);
639                 list = list->next;
640         }
643 void
644 mpdclient_playlist_callback(mpdclient_t *c, int event, gpointer data)
646         do_list_callbacks(c, c->playlist_callbacks, event, data);
649 void
650 mpdclient_install_playlist_callback(mpdclient_t *c,mpdc_list_cb_t cb)
652         c->playlist_callbacks = g_list_append(c->playlist_callbacks, cb);
655 void
656 mpdclient_remove_playlist_callback(mpdclient_t *c, mpdc_list_cb_t cb)
658         c->playlist_callbacks = g_list_remove(c->playlist_callbacks, cb);
661 void
662 mpdclient_browse_callback(mpdclient_t *c, int event, gpointer data)
664         do_list_callbacks(c, c->browse_callbacks, event, data);
668 void
669 mpdclient_install_browse_callback(mpdclient_t *c,mpdc_list_cb_t cb)
671         c->browse_callbacks = g_list_append(c->browse_callbacks, cb);
674 void
675 mpdclient_remove_browse_callback(mpdclient_t *c, mpdc_list_cb_t cb)
677         c->browse_callbacks = g_list_remove(c->browse_callbacks, cb);
680 void
681 mpdclient_install_error_callback(mpdclient_t *c, mpdc_error_cb_t cb)
683         c->error_callbacks = g_list_append(c->error_callbacks, cb);
686 void
687 mpdclient_remove_error_callback(mpdclient_t *c, mpdc_error_cb_t cb)
689         c->error_callbacks = g_list_remove(c->error_callbacks, cb);
693 /****************************************************************************/
694 /*** Playlist management functions ******************************************/
695 /****************************************************************************/
697 /* update playlist */
698 gint
699 mpdclient_playlist_update(mpdclient_t *c)
701         mpd_InfoEntity *entity;
703         if (MPD_ERROR(c))
704                 return -1;
706         playlist_clear(&c->playlist);
708         mpd_sendPlaylistInfoCommand(c->connection,-1);
709         while ((entity = mpd_getNextInfoEntity(c->connection))) {
710                 if (entity->type == MPD_INFO_ENTITY_TYPE_SONG)
711                         playlist_append(&c->playlist, entity->info.song);
713                 mpd_freeInfoEntity(entity);
714         }
716         c->playlist.id = c->status->playlist;
717         c->song = NULL;
719         /* call playlist updated callbacks */
720         mpdclient_playlist_callback(c, PLAYLIST_EVENT_UPDATED, NULL);
722         return mpdclient_finish_command(c);
725 #ifdef ENABLE_PLCHANGES
727 /* update playlist (plchanges) */
728 gint
729 mpdclient_playlist_update_changes(mpdclient_t *c)
731         mpd_InfoEntity *entity;
733         if (MPD_ERROR(c))
734                 return -1;
736         mpd_sendPlChangesCommand(c->connection, c->playlist.id);
738         while ((entity = mpd_getNextInfoEntity(c->connection)) != NULL) {
739                 struct mpd_song *song = entity->info.song;
741                 if (song->pos >= 0 && (guint)song->pos < c->playlist.list->len) {
742                         /* update song */
743                         playlist_replace(&c->playlist, song->pos, song);
744                 } else {
745                         /* add a new song */
746                         playlist_append(&c->playlist, song);
747                 }
749                 mpd_freeInfoEntity(entity);
750         }
752         /* remove trailing songs */
753         while ((guint)c->status->playlistLength < c->playlist.list->len) {
754                 guint pos = c->playlist.list->len - 1;
756                 /* Remove the last playlist entry */
757                 playlist_remove(&c->playlist, pos);
758         }
760         c->song = NULL;
761         c->playlist.id = c->status->playlist;
763         mpdclient_playlist_callback(c, PLAYLIST_EVENT_UPDATED, NULL);
765         return 0;
768 #else
769 gint
770 mpdclient_playlist_update_changes(mpdclient_t *c)
772         return mpdclient_playlist_update(c);
774 #endif
777 /****************************************************************************/
778 /*** Filelist functions *****************************************************/
779 /****************************************************************************/
781 mpdclient_filelist_t *
782 mpdclient_filelist_get(mpdclient_t *c, const gchar *path)
784         mpdclient_filelist_t *filelist;
785         mpd_InfoEntity *entity;
787         mpd_sendLsInfoCommand(c->connection, path);
788         filelist = filelist_new();
789         if (path && path[0] && strcmp(path, "/"))
790                 /* add a dummy entry for ./.. */
791                 filelist_append(filelist, NULL);
793         while ((entity=mpd_getNextInfoEntity(c->connection))) {
794                 filelist_append(filelist, entity);
795         }
797         /* If there's an error, ignore it.  We'll return an empty filelist. */
798         mpdclient_finish_command(c);
800         filelist_sort_dir_play(filelist, compare_filelistentry);
802         return filelist;
805 mpdclient_filelist_t *
806 mpdclient_filelist_search(mpdclient_t *c,
807                           int exact_match,
808                           int table,
809                           gchar *filter_utf8)
811         mpdclient_filelist_t *filelist;
812         mpd_InfoEntity *entity;
814         if (exact_match)
815                 mpd_sendFindCommand(c->connection, table, filter_utf8);
816         else
817                 mpd_sendSearchCommand(c->connection, table, filter_utf8);
818         filelist = filelist_new();
820         while ((entity=mpd_getNextInfoEntity(c->connection)))
821                 filelist_append(filelist, entity);
823         if (mpdclient_finish_command(c)) {
824                 filelist_free(filelist);
825                 return NULL;
826         }
828         return filelist;
831 int
832 mpdclient_filelist_add_all(mpdclient_t *c, mpdclient_filelist_t *fl)
834         guint i;
836         if (filelist_is_empty(fl))
837                 return 0;
839         mpd_sendCommandListBegin(c->connection);
841         for (i = 0; i < filelist_length(fl); ++i) {
842                 filelist_entry_t *entry = filelist_get(fl, i);
843                 mpd_InfoEntity *entity  = entry->entity;
845                 if (entity && entity->type == MPD_INFO_ENTITY_TYPE_SONG) {
846                         struct mpd_song *song = entity->info.song;
848                         mpd_sendAddCommand(c->connection, song->file);
849                 }
850         }
852         mpd_sendCommandListEnd(c->connection);
853         return mpdclient_finish_command(c);
856 GList *
857 mpdclient_get_artists(mpdclient_t *c)
859         gchar *str = NULL;
860         GList *list = NULL;
862         mpd_sendListCommand(c->connection, MPD_TABLE_ARTIST, NULL);
863         while ((str = mpd_getNextArtist(c->connection)))
864                 list = g_list_append(list, (gpointer) str);
866         if (mpdclient_finish_command(c))
867                 return string_list_free(list);
869         return list;
872 GList *
873 mpdclient_get_albums(mpdclient_t *c, const gchar *artist_utf8)
875         gchar *str = NULL;
876         GList *list = NULL;
878         mpd_sendListCommand(c->connection, MPD_TABLE_ALBUM, artist_utf8);
879         while ((str = mpd_getNextAlbum(c->connection)))
880                 list = g_list_append(list, (gpointer) str);
882         if (mpdclient_finish_command(c))
883                 return string_list_free(list);
885         return list;