Update copyright notices
[libmpd.git] / example / artisttree / aatree.c
blob4650961e770efb311957986e2e7a875d49163640
1 /* libmpd (high level libmpdclient library)
2 * Copyright (C) 2004-2009 Qball Cow <qball@sarine.nl>
3 * Project homepage: http://gmpcwiki.sarine.nl/
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.
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <libmpd/libmpd.h>
24 int main(int argc, char **argv)
26 /* the main structure */
27 MpdObj *mo;
29 * A list that can hold the data that mpd returns
31 MpdData *data = NULL;
34 /* create a connection
35 * This defaults to:
36 * host=localhost
37 * port=6600
39 mo = mpd_new_default();
41 /* Make a connection and check for errors */
42 if(mpd_connect(mo))
45 * to print an error message, you need to connect the
46 * error signal and catch that
48 /* clean up the connection and free the space needed by mpdObj */
49 mpd_free(mo);
50 printf("Failed to connect\n");
51 return 1;
54 /* Get all artists *
55 * If the list is at the end, mpd_data_get_next will automatically free
56 * the list.
58 for(data = mpd_database_get_artists(mo);data != NULL; data = mpd_data_get_next(data))
60 /* check if the entry is of the correct type */
61 if(data->type == MPD_DATA_TYPE_TAG && data->tag_type == MPD_TAG_ITEM_ARTIST)
63 /* Another object to hold data */
64 MpdData *albums = NULL;
65 printf("%s\n", data->tag);
66 for(albums = mpd_database_get_albums(mo, data->tag);
67 albums != NULL;
68 albums = mpd_data_get_next(albums))
70 if(albums->type == MPD_DATA_TYPE_TAG && albums->tag_type == MPD_TAG_ITEM_ALBUM)
72 printf("\t%s\n", albums->tag);
82 /* clean up the connection and free the space needed by mpdObj */
83 mpd_free(mo);