diff --git a/core/tags/album.c b/core/tags/album.c index 959a1ded..6250aee7 100644 --- a/core/tags/album.c +++ b/core/tags/album.c @@ -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; diff --git a/tests/core/tags/album.c b/tests/core/tags/album.c index f5d319f3..5c6b57ee 100644 --- a/tests/core/tags/album.c +++ b/tests/core/tags/album.c @@ -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"));