public
Description: Library to access lastfm via it's 2.0 api
Homepage: https://launchpad.net/liblastfm
Clone URL: git://github.com/LCID-Fire/liblastfm.git
Click here to lend your support to: liblastfm and make a donation at www.pledgie.com !
liblastfm / album.c
100644 155 lines (130 sloc) 5.219 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <glib.h>
#include "communication.h"
#include "album.h"
 
#define GET_INFO_METHOD_NAME "album.getInfo"
 
static lfmmethod const album_method_declarations[] =
{
//method name type //parameter
{"album.addTags", POST_METHOD, {{"artist"}, {"album"}, {"tags", utf8_array2csl}} },
    {GET_INFO_METHOD_NAME, GET_METHOD, {{"artist"}, {"album"} } },
    {"album.removeTag", POST_METHOD, {{"artist"}, {"album"}, {"tag"} } }
};
 
//enum has to be index of declarations
//changing this will break other code!
enum album_methods
{
add_tags,
get_info,
remove_tag
};
 
static lfmmethod mbid_method =
{
GET_INFO_METHOD_NAME,
GET_METHOD,
{{"mbid"}}
};
 
static const lfmget primary_methods[] =
{
//method //path to data data type
{&mbid_method, {"album", "name"}, DATA_UTF8},
{&mbid_method, {"album", "artist"}, DATA_UTF8},
{&album_method_declarations[get_info], {"album", "mbid"}, DATA_UTF8},
{&album_method_declarations[get_info], {"album", "url"}, DATA_URL},
{&album_method_declarations[get_info], {"album", "releasedate"}, DATA_DATE_TIME},
{&album_method_declarations[get_info], {"album", "image[size=small]"}, DATA_URL},
{&album_method_declarations[get_info], {"album", "image[size=medium]"}, DATA_URL},
{&album_method_declarations[get_info], {"album", "image[size=large]"}, DATA_URL},
{&album_method_declarations[get_info], {"album", "listeners"}, DATA_UINT},
{&album_method_declarations[get_info], {"album", "playcount"}, DATA_UINT},
};
 
enum primary_info
{
ALBUM_NAME,
ALBUM_ARTIST_NAME,
ALBUM_MUSICBRAINZ_ID,
ALBUM_URL,
ALBUM_RELEASEDATE,
ALBUM_IMAGE_SMALL,
ALBUM_IMAGE_MEDIUM,
ALBUM_IMAGE_LARGE,
ALBUM_LISTENER_COUNT,
ALBUM_PLAY_COUNT
};
 
static const lfmget related_methods[] =
{
{&album_method_declarations[get_info], {"album", "toptags", "tag", "name"}, DATA_TAGS},
{&album_method_declarations[add_tags], {}, DATA_VOID},
{&album_method_declarations[remove_tag], {}, DATA_VOID},
};
 
enum related_info
{
ALBUM_TOP_TAGS,
ALBUM_ADD_TAGS,
ALBUM_REMOVE_TAG
};
 
#define album_call_method_with_parameters(artist, album, call, callback, user_data, ...) \
call_method_with_parameters(call, callback, user_data, artist, album, __VA_ARGS__);
 
void album_get_info(const gchar* artist, const gchar* album, const lfmget* call, gpointer callback, gpointer user_data)
{
album_call_method_with_parameters(artist, album, call, callback, user_data, NULL);
}
 
void album_get_name(const gchar* musicbrainz_id, utf8_callback callback, gpointer user_data)
{
call_method_with_parameters(&primary_methods[ALBUM_NAME], callback, user_data, musicbrainz_id, NULL);
}
 
void album_get_artist_name(const gchar* musicbrainz_id, utf8_callback callback, gpointer user_data)
{
call_method_with_parameters(&primary_methods[ALBUM_ARTIST_NAME], callback, user_data, musicbrainz_id, NULL);
}
 
void album_get_musicbrainz_id(const gchar* artist, const gchar* album, utf8_callback callback, gpointer user_data)
{
album_get_info(artist, album, &primary_methods[ALBUM_MUSICBRAINZ_ID], callback, user_data);
}
 
void album_get_url(const gchar* artist, const gchar* album, url_callback callback, gpointer user_data)
{
album_get_info(artist, album, &primary_methods[ALBUM_URL], callback, user_data);
}
 
void album_get_release_date_time(const gchar* artist, const gchar* album, date_time_callback callback, gpointer user_data)
{
album_get_info(artist, album, &primary_methods[ALBUM_RELEASEDATE], callback, user_data);
}
 
void album_get_image_url(const gchar* artist, const gchar* album, const enum image_size size, url_callback callback, gpointer user_data)
{
const lfmget* call;
 
switch(size)
{
case IMAGE_LARGE:
call = &primary_methods[ALBUM_IMAGE_SMALL];
break;
case IMAGE_MEDIUM:
call = &primary_methods[ALBUM_IMAGE_MEDIUM];
break;
default:
call = &primary_methods[ALBUM_IMAGE_SMALL];
break;
}
 
album_get_info(artist, album, call, callback, user_data);
}
 
void album_get_listener_count(const gchar* artist, const gchar* album, uint_callback callback, gpointer user_data)
{
album_get_info(artist, album, &primary_methods[ALBUM_LISTENER_COUNT], callback, user_data);
}
 
void album_get_play_count(const gchar* artist, const gchar* album, uint_callback callback, gpointer user_data)
{
album_get_info(artist, album, &primary_methods[ALBUM_PLAY_COUNT], callback, user_data);
}
 
//
//Related information
//
 
void album_get_top_tags(const gchar* artist, const gchar* album, tags_callback callback, gpointer user_data)
{
album_get_info(artist, album, &related_methods[ALBUM_TOP_TAGS], callback, user_data);
}
 
void album_add_tags(const gchar* artist, const gchar* album, const gchar** tags, void_callback callback, gpointer user_data)
{
album_call_method_with_parameters(artist, album, &related_methods[ALBUM_ADD_TAGS], callback, user_data, tags, NULL);
}
 
void album_remove_tag(const gchar* artist, const gchar* album, const gchar* tag, void_callback callback, gpointer user_data)
{
album_call_method_with_parameters(artist, album, &related_methods[ALBUM_REMOVE_TAG], callback, user_data, tag, NULL);
}