core/tags/album: Add Artist ID to album keys

I need a way to represent the same album with different artists to
account for multi-artist albums.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-08-12 08:13:20 -04:00
parent 50db0db06a
commit a85a1df7de
2 changed files with 20 additions and 5 deletions

View File

@ -163,9 +163,12 @@ static bool __album_fetch_artwork(struct album *album)
return true;
}
static gchar *__album_key(const gchar *name, unsigned int year)
static gchar *__album_key(struct artist *artist, const gchar *name,
unsigned int year)
{
return g_strdup_printf("%u/%s", year, name);
if (!artist)
return g_strdup_printf("%u/%s", year, name);
return g_strdup_printf("%u/%u/%s", artist_index(artist), year, name);
}
static struct album *__album_alloc(gchar *name, unsigned int year)
@ -205,7 +208,8 @@ static void album_free(struct db_entry *dbe)
static gchar *album_key(struct db_entry *dbe)
{
return __album_key(ALBUM(dbe)->al_name, ALBUM(dbe)->al_year);
return __album_key(ALBUM(dbe)->al_artist, ALBUM(dbe)->al_name,
ALBUM(dbe)->al_year);
}
static struct db_entry *album_read(struct file *file)
@ -250,7 +254,7 @@ void album_db_deinit()
struct album *album_find(const gchar *name, unsigned int year)
{
gchar *key = __album_key(name, year);
gchar *key = __album_key(NULL, name, year);
struct album *album = ALBUM(db_find(&album_db, key));
g_free(key);
return album;

View File

@ -18,25 +18,36 @@ static void test_verify_empty(struct album *album)
static void test_verify_hyrule(struct album *album)
{
const struct db_ops *album_ops = test_album_ops();
gchar *key;
g_assert_cmpstr(album->al_name, ==, "Hyrule Symphony");
g_assert_cmpstr(album->al_tokens[0], ==, "hyrule");
g_assert_cmpstr(album->al_tokens[1], ==, "symphony");
g_assert_null(album->al_tokens[2]);
g_assert_null(album->al_alts[0]);
g_assert_cmpuint(album->al_year, ==, 1998);
g_assert_cmpstr_free(album_ops->dbe_key(&album->al_dbe), ==, "1998/Hyrule Symphony");
key = album_ops->dbe_key(&album->al_dbe);
if (album->al_artist)
g_assert_cmpstr_free(key, ==, "0/1998/Hyrule Symphony");
else
g_assert_cmpstr_free(key, ==, "1998/Hyrule Symphony");
}
static void test_album()
{
const struct db_ops *album_ops = test_album_ops();
struct album *album;
struct artist *koji;
struct file f;
idle_init();
koji = artist_find("Koji Kondo");
album = ALBUM(album_ops->dbe_alloc("1998/Hyrule Symphony"));
test_verify_hyrule(album);
album->al_artist = koji;
test_verify_hyrule(album);
g_assert_true( album_match_token(album, "hyrule"));
g_assert_true( album_match_token(album, "symphony"));
g_assert_false(album_match_token(album, "skyward"));