SpotifyRequest: Limit returned albums to queried artists

This commit is contained in:
Jonas Kvinge 2024-08-05 18:24:47 +02:00
parent 1c4d3aebad
commit 826fad1ad4
1 changed files with 13 additions and 3 deletions

View File

@ -728,17 +728,27 @@ void SpotifyRequest::AlbumsReceived(QNetworkReply *reply, const Artist &artist_a
if (obj_item.contains(QLatin1String("artists")) && obj_item[QLatin1String("artists")].isArray()) { if (obj_item.contains(QLatin1String("artists")) && obj_item[QLatin1String("artists")].isArray()) {
QJsonArray array_artists = obj_item[QLatin1String("artists")].toArray(); QJsonArray array_artists = obj_item[QLatin1String("artists")].toArray();
bool artist_matches = false;
for (const QJsonValueRef value : array_artists) { for (const QJsonValueRef value : array_artists) {
if (!value.isObject()) { if (!value.isObject()) {
continue; continue;
} }
QJsonObject obj_artist = value.toObject(); QJsonObject obj_artist = value.toObject();
if (obj_artist.isEmpty() || !obj_artist.contains(QLatin1String("id")) || !obj_artist.contains(QLatin1String("name"))) continue; if (obj_artist.isEmpty() || !obj_artist.contains(QLatin1String("id")) || !obj_artist.contains(QLatin1String("name"))) continue;
if (artist.artist_id.isEmpty() || artist.artist_id == artist_artist.artist_id) {
artist.artist_id = obj_artist[QLatin1String("id")].toString(); artist.artist_id = obj_artist[QLatin1String("id")].toString();
artist.artist = obj_artist[QLatin1String("name")].toString(); artist.artist = obj_artist[QLatin1String("name")].toString();
if (artist.artist_id == artist_artist.artist_id) {
artist_matches = true;
break; break;
} }
} }
}
if (!artist_matches && (type_ == Type::FavouriteArtists || type_ == Type::SearchArtists)) {
AlbumsFinishCheck(artist_artist);
return;
}
}
if (artist.artist_id.isEmpty()) { if (artist.artist_id.isEmpty()) {
artist = artist_artist; artist = artist_artist;