core/tags/album: Place multiple queries to find artwork
If searching for artist and album fails, then fall back on album and year or even just album name. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
b4218833c5
commit
c8ccf7b844
|
@ -49,45 +49,43 @@ static bool __album_fetch_cover(struct album *album, gchar *releaseid,
|
|||
return album_artwork_exists(album);
|
||||
}
|
||||
|
||||
static void __album_foreach_fetch(struct album *album, Mb5Metadata metadata)
|
||||
static bool __album_foreach_fetch(struct album *album, Mb5Metadata metadata)
|
||||
{
|
||||
Mb5ReleaseList list = mb5_metadata_get_releaselist(metadata);
|
||||
gchar releaseid[40];
|
||||
Mb5Release release;
|
||||
CaaCoverArt *caa;
|
||||
bool ret = false;
|
||||
unsigned int i;
|
||||
|
||||
caa = caa_coverart_new(OCARINA_NAME);
|
||||
if (!caa)
|
||||
return;
|
||||
return false;
|
||||
|
||||
for (i = 0; i < mb5_release_list_size(list); i++) {
|
||||
release = mb5_release_list_item(list, i);
|
||||
if (!release)
|
||||
break;
|
||||
mb5_release_get_id(release, releaseid, sizeof(releaseid));
|
||||
if (__album_fetch_cover(album, releaseid, caa))
|
||||
ret = __album_fetch_cover(album, releaseid, caa);
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
|
||||
caa_coverart_delete(caa);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __album_query_releaseid(struct album *album, Mb5Query *mb5)
|
||||
static bool __album_query_releaseid(struct album *album, Mb5Query *mb5,
|
||||
gchar *extra)
|
||||
{
|
||||
gchar *param, *query = "query";
|
||||
Mb5Metadata metadata = NULL;
|
||||
tQueryResult result;
|
||||
gchar error[256];
|
||||
bool ret = false;
|
||||
|
||||
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);
|
||||
param = g_strdup_printf("release:\"%s\" %s", album->al_name, extra);
|
||||
|
||||
do {
|
||||
metadata = mb5_query_query(mb5, "release", "", "", 1, &query,
|
||||
|
@ -100,11 +98,26 @@ static void __album_query_releaseid(struct album *album, Mb5Query *mb5)
|
|||
} while (result == 503);
|
||||
|
||||
if (metadata) {
|
||||
__album_foreach_fetch(album, metadata);
|
||||
ret = __album_foreach_fetch(album, metadata);
|
||||
mb5_metadata_delete(metadata);
|
||||
}
|
||||
|
||||
g_free(param);
|
||||
g_free(extra);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool __album_query_artist(struct album *album, Mb5Query *mb5)
|
||||
{
|
||||
gchar *fmt = "AND artist:%s";
|
||||
gchar *param = g_strdup_printf(fmt, album->al_artist->ar_lower);
|
||||
return __album_query_releaseid(album, mb5, param);
|
||||
}
|
||||
|
||||
static bool __album_query_year(struct album *album, Mb5Query *mb5)
|
||||
{
|
||||
gchar *param = g_strdup_printf("AND date:%d", album->al_year);
|
||||
return __album_query_releaseid(album, mb5, param);
|
||||
}
|
||||
|
||||
static bool __album_fetch_artwork(struct album *album)
|
||||
|
@ -118,7 +131,13 @@ static bool __album_fetch_artwork(struct album *album)
|
|||
if (!mb5)
|
||||
return false;
|
||||
|
||||
__album_query_releaseid(album, mb5);
|
||||
if (album->al_artist && __album_query_artist(album, mb5))
|
||||
goto out;
|
||||
if (album->al_year && __album_query_year(album, mb5))
|
||||
goto out;
|
||||
__album_query_releaseid(album, mb5, g_strdup(""));
|
||||
|
||||
out:
|
||||
mb5_query_delete(mb5);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue