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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __album_query_releaseid(struct album *album, Mb5Query *mb5,
|
static bool __album_query_releaseid(struct album *album, gchar *param)
|
||||||
gchar *param)
|
|
||||||
{
|
{
|
||||||
Mb5Metadata metadata = NULL;
|
Mb5Metadata data = NULL;
|
||||||
gchar *query = "query";
|
gchar *query = "query";
|
||||||
tQueryResult result;
|
unsigned int code;
|
||||||
gchar error[256];
|
gchar error[256];
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
Mb5Query *mb5;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
metadata = mb5_query_query(mb5, "release", "", "", 1, &query,
|
mb5 = mb5_query_new(OCARINA_NAME, NULL, 0);
|
||||||
¶m);
|
if (!mb5)
|
||||||
result = mb5_query_get_lastresult(mb5);
|
break;
|
||||||
if (result != 0) {
|
|
||||||
|
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));
|
mb5_query_get_lasterrormessage(mb5, error, sizeof(error));
|
||||||
g_printf("MusicBrainz: %s\n", error);
|
g_printf("MusicBrainz: %s\n", error);
|
||||||
}
|
}
|
||||||
} while (result == 503);
|
|
||||||
|
|
||||||
if (metadata) {
|
mb5_query_delete(mb5);
|
||||||
ret = __album_foreach_fetch(album, metadata);
|
} while (code == 503);
|
||||||
mb5_metadata_delete(metadata);
|
|
||||||
|
if (data) {
|
||||||
|
ret = __album_foreach_fetch(album, data);
|
||||||
|
mb5_metadata_delete(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __album_query_name(struct album *album, Mb5Query *mb5,
|
static bool __album_query_name(struct album *album, gchar *extra, bool quoted)
|
||||||
gchar *extra, bool quoted)
|
|
||||||
{
|
{
|
||||||
gchar *fmt = "release:%s%s%s%s";
|
gchar *fmt = "release:%s%s%s%s";
|
||||||
gchar *param = g_strdup_printf(fmt, quoted ? "\"" : "",
|
gchar *param = g_strdup_printf(fmt, quoted ? "\"" : "",
|
||||||
quoted ? album->al_name : album->al_lower,
|
quoted ? album->al_name : album->al_lower,
|
||||||
quoted ? "\"" : "",
|
quoted ? "\"" : "",
|
||||||
extra ? extra : "");
|
extra ? extra : "");
|
||||||
bool ret = __album_query_releaseid(album, mb5, param);
|
bool ret = __album_query_releaseid(album, param);
|
||||||
g_free(param);
|
g_free(param);
|
||||||
return ret;
|
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;
|
struct artist *artist = album->al_artist;
|
||||||
gchar *fmt = " AND artist:%s%s%s";
|
gchar *fmt = " AND artist:%s%s%s";
|
||||||
gchar *param = g_strdup_printf(fmt, quoted ? "\"" : "",
|
gchar *param = g_strdup_printf(fmt, quoted ? "\"" : "",
|
||||||
quoted ? artist->ar_name : artist->ar_lower,
|
quoted ? artist->ar_name : artist->ar_lower,
|
||||||
quoted ? "\"" : "");
|
quoted ? "\"" : "");
|
||||||
bool ret = __album_query_name(album, mb5, param, !quoted);
|
bool ret = __album_query_name(album, param, !quoted);
|
||||||
g_free(param);
|
g_free(param);
|
||||||
return ret;
|
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);
|
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);
|
g_free(param);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -147,13 +151,13 @@ static bool __album_fetch_artwork(struct album *album)
|
||||||
if (!mb5)
|
if (!mb5)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (album->al_artist && __album_query_artist(album, mb5, false))
|
if (album->al_artist && __album_query_artist(album, true))
|
||||||
goto out;
|
goto out;
|
||||||
if (album->al_artist && __album_query_artist(album, mb5, true))
|
if (album->al_artist && __album_query_artist(album, false))
|
||||||
goto out;
|
goto out;
|
||||||
if (album->al_year && __album_query_year(album, mb5))
|
if (album->al_year && __album_query_year(album))
|
||||||
goto out;
|
goto out;
|
||||||
__album_query_name(album, mb5, NULL, true);
|
__album_query_name(album, NULL, true);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
mb5_query_delete(mb5);
|
mb5_query_delete(mb5);
|
||||||
|
|
Loading…
Reference in New Issue