Improve handling of Spotify Top Tracks and compilations
Two improvements to handling of Spotify albums: - Remove single-track results if they also show up in the album results. This eliminates duplicates showing up in albums. - For each album, choose the majority artist attribution to specify as the Album Artist. For users who group by Album Artist, this prevents splitting albums into multiple entries when there are contributing artists. Squashes following commits: commit d8bf17e13f50c7642ba491228f31608f4861d3b6 Author: Joel Bradshaw <cincodenada@gmail.com> Date: Tue Oct 28 19:56:36 2014 -0700 Improve handling of Spotify Top Tracks and compilations Two improvements to handling of Spotify albums: - Combine individual tracks into a "Top Tracks" album by just setting the album name to "Top Tracks" - For each album, choose the majority artist attribution to specify as the Album Artist. For users who group by Album Artist, this prevents splitting albums into multiple entries when there is a contributing artist. commit 228650a1d7122e5d1947133ba793afaffaa69cb4 Author: Joel Bradshaw <cincodenada@gmail.com> Date: Wed Oct 29 10:00:21 2014 -0700 Style cleanup, including run of make format Also wrapped Top Tracks with tr() commit a4f6c1ecd9bcc8338a956b1a45c2f184ee9d660d Author: Joel Bradshaw <cincodenada@gmail.com> Date: Sun Feb 15 13:38:52 2015 -0800 Simply remove duplicate entries from the "Top Tracks" section Don't create the fake "Top Tracks" album, but remove entries from it if they show up in the album results. This will eliminate the main problem - duplicates showing up in albums - and avoid issues with actual single-track results showing up erroneously as "Top Tracks" commit 859abc93b3491cc526d89df19a85dc4cf9bce1c8 Author: Joel Bradshaw <cincodenada@gmail.com> Date: Sat Apr 18 09:17:50 2015 -0700 Clean up stray f and make format commit 333de1c4aa947c7cbe785429565bf4f08f98d476 Author: Joel Bradshjaw <cincodenada@gmail.com> Date: Sat Apr 18 09:19:10 2015 -0700 Update majority_count so it works Fixes issue with it just picking the last artist on the album as the album artist
This commit is contained in:
parent
d2bb07ead6
commit
ddd641b1ae
@ -45,8 +45,7 @@ SpotifyServer* SpotifySearchProvider::server() {
|
||||
if (service_->login_state() != SpotifyService::LoginState_LoggedIn)
|
||||
return nullptr;
|
||||
|
||||
if (!service_->IsBlobInstalled())
|
||||
return nullptr;
|
||||
if (!service_->IsBlobInstalled()) return nullptr;
|
||||
|
||||
server_ = service_->server();
|
||||
connect(server_, SIGNAL(SearchResults(pb::spotify::SearchResponse)),
|
||||
@ -90,30 +89,60 @@ void SpotifySearchProvider::SearchFinishedSlot(
|
||||
PendingState state = it.value();
|
||||
queries_.erase(it);
|
||||
|
||||
QMap<std::string, std::string> album_dedup;
|
||||
ResultList ret;
|
||||
for (int i = 0; i < response.result_size(); ++i) {
|
||||
const pb::spotify::Track& track = response.result(i);
|
||||
|
||||
Result result(this);
|
||||
SpotifyService::SongFromProtobuf(track, &result.metadata_);
|
||||
|
||||
ret << result;
|
||||
}
|
||||
|
||||
for (int i = 0; i < response.album_size(); ++i) {
|
||||
const pb::spotify::Album& album = response.album(i);
|
||||
|
||||
QHash<QString, int> artist_count;
|
||||
QString artist, majority_artist;
|
||||
int majority_count = 0;
|
||||
|
||||
// Choose an album artist
|
||||
for (int j = 0; j < album.track_size(); ++j) {
|
||||
for (int k = 0; k < album.track(j).artist_size(); ++k) {
|
||||
artist = QStringFromStdString(album.track(j).artist(k));
|
||||
if (artist_count.contains(artist)) {
|
||||
artist_count[artist]++;
|
||||
} else {
|
||||
artist_count[artist] = 1;
|
||||
}
|
||||
if (artist_count[artist] > majority_count) {
|
||||
majority_count = artist_count[artist];
|
||||
majority_artist = artist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < album.track_size(); ++j) {
|
||||
album_dedup.insertMulti(album.track(j).album(), album.track(j).title());
|
||||
|
||||
Result result(this);
|
||||
SpotifyService::SongFromProtobuf(album.track(j), &result.metadata_);
|
||||
|
||||
// Just use the album index as an id.
|
||||
result.metadata_.set_album_id(i);
|
||||
result.metadata_.set_albumartist(majority_artist);
|
||||
|
||||
ret << result;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < response.result_size(); ++i) {
|
||||
const pb::spotify::Track& track = response.result(i);
|
||||
|
||||
if (album_dedup.contains(track.album()) &&
|
||||
album_dedup.values(track.album()).contains(track.title())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Result result(this);
|
||||
SpotifyService::SongFromProtobuf(track, &result.metadata_);
|
||||
|
||||
ret << result;
|
||||
}
|
||||
|
||||
emit ResultsAvailable(state.orig_id_, ret);
|
||||
emit SearchFinished(state.orig_id_);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user