#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);
}