core/tags/album: Fix retrying MB5 query on error 503
Reusing the Mb5Query can have undesireable side effects, such as the error code not getting reset between queries. Fix this by allocating a new Mb5Query before evey request. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
c62a88ce09
commit
617088c89b
|
@ -76,62 +76,66 @@ static bool __album_foreach_fetch(struct album *album, Mb5Metadata metadata)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static bool __album_query_releaseid(struct album *album, Mb5Query *mb5,
|
||||
gchar *param)
|
||||
static bool __album_query_releaseid(struct album *album, gchar *param)
|
||||
{
|
||||
Mb5Metadata metadata = NULL;
|
||||
Mb5Metadata data = NULL;
|
||||
gchar *query = "query";
|
||||
tQueryResult result;
|
||||
unsigned int code;
|
||||
gchar error[256];
|
||||
bool ret = false;
|
||||
Mb5Query *mb5;
|
||||
|
||||
do {
|
||||
metadata = mb5_query_query(mb5, "release", "", "", 1, &query,
|
||||
¶m);
|
||||
result = mb5_query_get_lastresult(mb5);
|
||||
if (result != 0) {
|
||||
mb5 = mb5_query_new(OCARINA_NAME, NULL, 0);
|
||||
if (!mb5)
|
||||
break;
|
||||
|
||||
data = mb5_query_query(mb5, "release", "", "", 1, &query, ¶m);
|
||||
code = mb5_query_get_lasthttpcode(mb5);
|
||||
if (mb5_query_get_lastresult(mb5) != 0) {
|
||||
mb5_query_get_lasterrormessage(mb5, error, sizeof(error));
|
||||
g_printf("MusicBrainz: %s\n", error);
|
||||
}
|
||||
} while (result == 503);
|
||||
|
||||
if (metadata) {
|
||||
ret = __album_foreach_fetch(album, metadata);
|
||||
mb5_metadata_delete(metadata);
|
||||
mb5_query_delete(mb5);
|
||||
} while (code == 503);
|
||||
|
||||
if (data) {
|
||||
ret = __album_foreach_fetch(album, data);
|
||||
mb5_metadata_delete(data);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool __album_query_name(struct album *album, Mb5Query *mb5,
|
||||
gchar *extra, bool quoted)
|
||||
static bool __album_query_name(struct album *album, gchar *extra, bool quoted)
|
||||
{
|
||||
gchar *fmt = "release:%s%s%s%s";
|
||||
gchar *param = g_strdup_printf(fmt, quoted ? "\"" : "",
|
||||
quoted ? album->al_name : album->al_lower,
|
||||
quoted ? "\"" : "",
|
||||
extra ? extra : "");
|
||||
bool ret = __album_query_releaseid(album, mb5, param);
|
||||
bool ret = __album_query_releaseid(album, param);
|
||||
g_free(param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool __album_query_artist(struct album *album, Mb5Query *mb5, bool quoted)
|
||||
static bool __album_query_artist(struct album *album, bool quoted)
|
||||
{
|
||||
struct artist *artist = album->al_artist;
|
||||
gchar *fmt = " AND artist:%s%s%s";
|
||||
gchar *param = g_strdup_printf(fmt, quoted ? "\"" : "",
|
||||
quoted ? artist->ar_name : artist->ar_lower,
|
||||
quoted ? "\"" : "");
|
||||
bool ret = __album_query_name(album, mb5, param, !quoted);
|
||||
bool ret = __album_query_name(album, param, !quoted);
|
||||
g_free(param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool __album_query_year(struct album *album, Mb5Query *mb5)
|
||||
static bool __album_query_year(struct album *album)
|
||||
{
|
||||
gchar *param = g_strdup_printf(" AND date:%d", album->al_year);
|
||||
bool ret = __album_query_name(album, mb5, param, true);
|
||||
bool ret = __album_query_name(album, param, true);
|
||||
g_free(param);
|
||||
return ret;
|
||||
}
|
||||
|
@ -147,13 +151,13 @@ static bool __album_fetch_artwork(struct album *album)
|
|||
if (!mb5)
|
||||
return false;
|
||||
|
||||
if (album->al_artist && __album_query_artist(album, mb5, false))
|
||||
if (album->al_artist && __album_query_artist(album, true))
|
||||
goto out;
|
||||
if (album->al_artist && __album_query_artist(album, mb5, true))
|
||||
if (album->al_artist && __album_query_artist(album, false))
|
||||
goto out;
|
||||
if (album->al_year && __album_query_year(album, mb5))
|
||||
if (album->al_year && __album_query_year(album))
|
||||
goto out;
|
||||
__album_query_name(album, mb5, NULL, true);
|
||||
__album_query_name(album, NULL, true);
|
||||
|
||||
out:
|
||||
mb5_query_delete(mb5);
|
||||
|
|
Loading…
Reference in New Issue