Merge pull request #5435 from paperbagcorner/emptyimageresponse
Cope with empty spotify image responses
This commit is contained in:
commit
8eae8d4538
@ -21,9 +21,7 @@ QString ExtractSpotifyId(const QString& spotify_uri) {
|
|||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
SpotifyImages::SpotifyImages()
|
SpotifyImages::SpotifyImages() : network_(new NetworkAccessManager) {}
|
||||||
: network_(new NetworkAccessManager) {
|
|
||||||
}
|
|
||||||
|
|
||||||
SpotifyImages::~SpotifyImages() {}
|
SpotifyImages::~SpotifyImages() {}
|
||||||
|
|
||||||
@ -82,13 +80,16 @@ void SpotifyImages::FetchImagesForArtist(int id, const QString& spotify_id) {
|
|||||||
QUrl url = image["url"].toUrl();
|
QUrl url = image["url"].toUrl();
|
||||||
image_candidates.append(qMakePair(url, QSize(width, height)));
|
image_candidates.append(qMakePair(url, QSize(width, height)));
|
||||||
}
|
}
|
||||||
QPair<QUrl, QSize> winner = *std::max_element(
|
if (!image_candidates.isEmpty()) {
|
||||||
image_candidates.begin(),
|
QPair<QUrl, QSize> winner =
|
||||||
image_candidates.end(),
|
*std::max_element(
|
||||||
[](const QPair<QUrl, QSize>& a, const QPair<QUrl, QSize>& b) {
|
image_candidates.begin(), image_candidates.end(),
|
||||||
return (a.second.height() * a.second.width()) < (b.second.height() * b.second.width());
|
[](const QPair<QUrl, QSize>& a, const QPair<QUrl, QSize>& b) {
|
||||||
});
|
return (a.second.height() * a.second.width()) <
|
||||||
emit ImageReady(id, winner.first);
|
(b.second.height() * b.second.width());
|
||||||
|
});
|
||||||
|
emit ImageReady(id, winner.first);
|
||||||
|
}
|
||||||
emit Finished(id);
|
emit Finished(id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user