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 / lastfm_test.c
100644 167 lines (137 sloc) 4.246 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
156
157
158
159
160
161
162
163
164
165
166
167
#include "lastfm.h"
 
int call = 0;
 
static GCond* cond = NULL;
 
void increaseCall()
{
call++;
}
 
void decreaseCall()
{
call--;
 
if(call <= 0)
g_cond_broadcast(cond);
}
 
void void_func(gpointer user_data, GError* error)
{
const char* func_name = user_data;
if(error)
g_printerr("%s: [ERROR] %s\n", func_name, error->message);
else
g_print("%s: [OK]\n", func_name);
 
decreaseCall();
}
 
void utf8_func(const gchar* string, gpointer user_data, GError* error)
{
const char* func_name = user_data;
if(error)
g_printerr("%s: [ERROR] %s\n", func_name, error->message);
else
g_print("%s: [OK] %s\n", func_name, string);
 
decreaseCall();
}
 
void uint_func(guint count, gpointer user_data, GError* error)
{
const char* func_name = user_data;
if(error)
g_printerr("%s: [ERROR] %s\n", func_name, error->message);
else
g_print("%s: [OK] %u\n", func_name, count);
 
decreaseCall();
}
 
void boolean_func(gboolean success, gpointer user_data, GError* error)
{
const char* func_name = user_data;
if(error)
g_printerr("%s: [ERROR] %s\n", func_name, error->message);
else
g_print("%s: [OK] %s\n", func_name, success ? "TRUE" : "FALSE");
 
decreaseCall();
}
 
void dt_func(struct tm dt, gpointer user_data, GError* error)
{
const char* func_name = user_data;
if(error)
g_printerr("%s: [ERROR] %s\n", func_name, error->message);
else
{
char time_buffer[256];
strftime(time_buffer, 255, "%a, %d %b %Y %H:%M:%S %z", &dt);
 
g_print("%s: [OK] %s\n", func_name, time_buffer);
}
 
decreaseCall();
}
 
void multi_utf8_func(const gchar* string, gpointer user_data, GError* error, gboolean is_end)
{
if(is_end)
{
decreaseCall();
return;
}
 
const char* func_name = user_data;
if(error)
g_printerr("%s: [ERROR] %s\n", func_name, error->message);
else
g_print("%s: [OK] %s\n", func_name, string);
}
 
int main(int argc, const char* args[])
{
lastfm_init();
 
cond = g_cond_new();
static const char atst[] = "Nine Inch Nails";
 
increaseCall();
artist_get_musicbrainz_id(atst, utf8_func, "artist_get_musicbrainz_id");
 
//artist_get_name(atst, utf8_func, "artist_get_name");
//call++;
increaseCall();
artist_get_url(atst, utf8_func, "artist_get_url");
increaseCall();
artist_get_image_url(atst, IMAGE_LARGE, utf8_func, "artist_get_image_url");
increaseCall();
artist_get_play_count(atst, uint_func, "artist_get_play_count");
increaseCall();
artist_get_listener_count(atst, uint_func, "artist_get_listener_count");
increaseCall();
artist_is_streamable(atst, boolean_func, "artist_is_streamable");
increaseCall();
artist_get_summary(atst, utf8_func, "artist_get_summary");
increaseCall();
artist_get_description(atst, utf8_func, "artist_get_description");
increaseCall();
artist_get_published_date_time(atst, dt_func, "artist_get_published_date_time");
 
increaseCall();
createv(gchar, tags);
addv(gchar, tags, g_strdup("test1"));
addv(gchar, tags, g_strdup("test2"));
artist_add_tags(atst, (const gchar**)tags, void_func, "artist_add_tags");
 
increaseCall();
artist_remove_tag(atst, tags[0], void_func, "artist_remove_tag");
increaseCall();
artist_remove_tag(atst, tags[1], void_func, "artist_remove_tag");
destroyv(gchar, tags);
 
static const char albm[] = "With Teeth";
static const char mbid[] = "df025315-4897-4759-ba77-d2cd09b5b4b6";
 
increaseCall();
album_get_musicbrainz_id(atst, albm, utf8_func, "album_get_musicbrainz_id");
increaseCall();
album_get_name(mbid, utf8_func, "album_get_name");
increaseCall();
album_get_artist_name(mbid, utf8_func, "album_get_artist_name");
increaseCall();
album_get_url(atst, albm, utf8_func, "album_get_url");
increaseCall();
album_get_release_date_time(atst, albm, dt_func, "album_get_release_date_time");
increaseCall();
album_get_image_url(atst, albm, IMAGE_LARGE, utf8_func, "album_get_image_url");
increaseCall();
album_get_listener_count(atst, albm, uint_func, "album_get_listener_count");
increaseCall();
album_get_play_count(atst, albm, uint_func, "album_get_play_count");
increaseCall();
album_get_top_tags(atst, albm, multi_utf8_func, "album_get_top_tags");
 
GMutex* mutex = g_mutex_new();
g_cond_wait(cond, mutex);
g_mutex_free(mutex);
 
g_cond_free(cond);
lastfm_destroy();
 
return 0;
}