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);
|
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);
|
Mb5ReleaseList list = mb5_metadata_get_releaselist(metadata);
|
||||||
gchar releaseid[40];
|
gchar releaseid[40];
|
||||||
Mb5Release release;
|
Mb5Release release;
|
||||||
CaaCoverArt *caa;
|
CaaCoverArt *caa;
|
||||||
|
bool ret = false;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
caa = caa_coverart_new(OCARINA_NAME);
|
caa = caa_coverart_new(OCARINA_NAME);
|
||||||
if (!caa)
|
if (!caa)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
for (i = 0; i < mb5_release_list_size(list); i++) {
|
for (i = 0; i < mb5_release_list_size(list); i++) {
|
||||||
release = mb5_release_list_item(list, i);
|
release = mb5_release_list_item(list, i);
|
||||||
if (!release)
|
if (!release)
|
||||||
break;
|
break;
|
||||||
mb5_release_get_id(release, releaseid, sizeof(releaseid));
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
caa_coverart_delete(caa);
|
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";
|
gchar *param, *query = "query";
|
||||||
Mb5Metadata metadata = NULL;
|
Mb5Metadata metadata = NULL;
|
||||||
tQueryResult result;
|
tQueryResult result;
|
||||||
gchar error[256];
|
gchar error[256];
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
if (album->al_artist != NULL)
|
param = g_strdup_printf("release:\"%s\" %s", album->al_name, extra);
|
||||||
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);
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
metadata = mb5_query_query(mb5, "release", "", "", 1, &query,
|
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);
|
} while (result == 503);
|
||||||
|
|
||||||
if (metadata) {
|
if (metadata) {
|
||||||
__album_foreach_fetch(album, metadata);
|
ret = __album_foreach_fetch(album, metadata);
|
||||||
mb5_metadata_delete(metadata);
|
mb5_metadata_delete(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(param);
|
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)
|
static bool __album_fetch_artwork(struct album *album)
|
||||||
|
@ -118,7 +131,13 @@ static bool __album_fetch_artwork(struct album *album)
|
||||||
if (!mb5)
|
if (!mb5)
|
||||||
return false;
|
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);
|
mb5_query_delete(mb5);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue