From 2ea5104d429384e9720d3d49327294688baa8ee4 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 4 Jul 2016 20:35:22 -0400 Subject: [PATCH] core/tags/album: Fetch album art in the same step as metadata This will help prepare for running multiple queries to find a release. Signed-off-by: Anna Schumaker --- core/tags/album.c | 66 +++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/core/tags/album.c b/core/tags/album.c index ac369539..67f551e1 100644 --- a/core/tags/album.c +++ b/core/tags/album.c @@ -23,34 +23,6 @@ static inline void __album_deinit_file(struct cache_file *f) g_free(f->cf_name); } -static Mb5Metadata __album_query_releaseid(struct album *album, - Mb5Query *mb5) -{ - gchar *param, *query = "query"; - Mb5Metadata metadata = NULL; - tQueryResult result; - gchar error[256]; - - if (album->al_artist != NULL) - param = g_strdup_printf("release:\"%s\" AND artist:%s", - album->al_lower, album->al_artist->ar_lower); - else if (album->al_year != 0) - param = g_strdup_printf("release:\"%s\" AND date:%d", - album->al_lower, album->al_year); - else - param = g_strdup_printf("release:\"%s\"", album->al_lower); - - metadata = mb5_query_query(mb5, "release", "", "", 1, &query, ¶m); - result = mb5_query_get_lastresult(mb5); - if (result != 0) { - mb5_query_get_lasterrormessage(mb5, error, sizeof(error)); - g_printf("MusicBrainz: %s\n", error); - } - - g_free(param); - return metadata; -} - static bool __album_fetch_cover(struct album *album, gchar *releaseid, CaaCoverArt *caa) { @@ -101,9 +73,39 @@ static void __album_foreach_fetch(struct album *album, Mb5Metadata metadata) caa_coverart_delete(caa); } +static void __album_query_releaseid(struct album *album, Mb5Query *mb5) +{ + gchar *param, *query = "query"; + Mb5Metadata metadata = NULL; + tQueryResult result; + gchar error[256]; + + if (album->al_artist != NULL) + param = g_strdup_printf("release:\"%s\" AND artist:%s", + album->al_name, album->al_artist->ar_lower); + else if (album->al_year != 0) + param = g_strdup_printf("release:\"%s\" AND date:%d", + album->al_name, album->al_year); + else + param = g_strdup_printf("release:\"%s\"", album->al_name); + + metadata = mb5_query_query(mb5, "release", "", "", 1, &query, ¶m); + result = mb5_query_get_lastresult(mb5); + if (result != 0) { + mb5_query_get_lasterrormessage(mb5, error, sizeof(error)); + g_printf("MusicBrainz: %s\n", error); + } + + if (metadata) { + __album_foreach_fetch(album, metadata); + mb5_metadata_delete(metadata); + } + + g_free(param); +} + static bool __album_fetch_artwork(struct album *album) { - Mb5Metadata metadata; Mb5Query *mb5; bool ret; @@ -114,11 +116,7 @@ static bool __album_fetch_artwork(struct album *album) if (!mb5) return true; - metadata = __album_query_releaseid(album, mb5); - if (metadata) { - __album_foreach_fetch(album, metadata); - mb5_metadata_delete(metadata); - } + __album_query_releaseid(album, mb5); ret = mb5_query_get_lasthttpcode(mb5) != 503; mb5_query_delete(mb5);