Clementine-audio-player-Mac.../src/globalsearch/spotifysearchprovider.cpp

281 lines
8.5 KiB
C++
Raw Normal View History

2011-08-29 00:59:18 +02:00
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "spotifysearchprovider.h"
#include <ctime>
#include <random>
#include "core/logging.h"
#include "internet/core/internetmodel.h"
#include "internet/spotify/spotifyserver.h"
#include "playlist/songmimedata.h"
#include "ui/iconloader.h"
2011-08-29 00:59:18 +02:00
namespace {
const int kSearchSongLimit = 5;
const int kSearchAlbumLimit = 20;
2020-09-18 16:15:19 +02:00
} // namespace
SpotifySearchProvider::SpotifySearchProvider(Application* app, QObject* parent)
: SearchProvider(app, parent), server_(nullptr), service_(nullptr) {
Init("Spotify", "spotify", IconLoader::Load("spotify", IconLoader::Provider),
WantsDelayedQueries | WantsSerialisedArtQueries | ArtIsProbablyRemote |
CanShowConfig | CanGiveSuggestions);
2011-08-29 00:59:18 +02:00
}
SpotifyServer* SpotifySearchProvider::server() {
if (server_) return server_;
2011-08-29 00:59:18 +02:00
if (!service_) service_ = InternetModel::Service<SpotifyService>();
2011-08-29 00:59:18 +02:00
if (service_->login_state() != SpotifyService::LoginState_LoggedIn)
return nullptr;
2011-08-29 00:59:18 +02:00
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
2014-10-29 03:56:36 +01:00
if (!service_->IsBlobInstalled()) return nullptr;
2011-08-29 00:59:18 +02:00
server_ = service_->server();
connect(server_, SIGNAL(SearchResults(cpb::spotify::SearchResponse)),
SLOT(SearchFinishedSlot(cpb::spotify::SearchResponse)));
connect(server_, SIGNAL(ImageLoaded(QString, QImage)),
SLOT(ArtLoadedSlot(QString, QImage)));
2011-08-29 00:59:18 +02:00
connect(server_, SIGNAL(destroyed()), SLOT(ServerDestroyed()));
connect(server_, SIGNAL(StarredLoaded(cpb::spotify::LoadPlaylistResponse)),
SLOT(SuggestionsLoaded(cpb::spotify::LoadPlaylistResponse)));
connect(server_,
SIGNAL(ToplistBrowseResults(cpb::spotify::BrowseToplistResponse)),
SLOT(SuggestionsLoaded(cpb::spotify::BrowseToplistResponse)));
2011-08-29 00:59:18 +02:00
return server_;
2011-08-29 00:59:18 +02:00
}
void SpotifySearchProvider::ServerDestroyed() { server_ = nullptr; }
2011-08-29 00:59:18 +02:00
void SpotifySearchProvider::SearchAsync(int id, const QString& query) {
SpotifyServer* s = server();
if (!s) {
emit SearchFinished(id);
return;
}
PendingState state;
state.orig_id_ = id;
state.tokens_ = TokenizeQuery(query);
const QString query_string = state.tokens_.join(" ");
s->Search(query_string, kSearchSongLimit, kSearchAlbumLimit);
2011-08-29 00:59:18 +02:00
queries_[query_string] = state;
}
void SpotifySearchProvider::SearchFinishedSlot(
const cpb::spotify::SearchResponse& response) {
2011-08-29 00:59:18 +02:00
QString query_string = QString::fromUtf8(response.request().query().c_str());
QMap<QString, PendingState>::iterator it = queries_.find(query_string);
if (it == queries_.end()) return;
2011-08-29 00:59:18 +02:00
PendingState state = it.value();
queries_.erase(it);
/* Here we clean up Spotify's results for our purposes
*
* Since Spotify doesn't give us an album artist,
* we pick one, so there's a single album artist
* per album to use for sorting.
*
* We also drop any of the single tracks returned
* if they are already represented in an album
*
* This eliminates frequent duplicates from the
* "Top Tracks" results that Spotify sometimes
* returns
*/
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
2014-10-29 03:56:36 +01:00
QMap<std::string, std::string> album_dedup;
2011-08-29 00:59:18 +02:00
ResultList ret;
for (int i = 0; i < response.album_size(); ++i) {
const cpb::spotify::Album& album = response.album(i);
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
2014-10-29 03:56:36 +01:00
QHash<QString, int> artist_count;
QString majority_artist;
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
2014-10-29 03:56:36 +01:00
int majority_count = 0;
/* We go through and find the artist that is
* represented most frequently in the artist
*
* For most albums this will just be one artist,
2015-04-25 18:01:32 +02:00
* but this ensures we have a consistent album artist for
* soundtracks, compilations, contributing artists, etc
*/
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
2014-10-29 03:56:36 +01:00
for (int j = 0; j < album.track_size(); ++j) {
// Each track can have multiple artists attributed, check them all
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
2014-10-29 03:56:36 +01:00
for (int k = 0; k < album.track(j).artist_size(); ++k) {
QString artist = QStringFromStdString(album.track(j).artist(k));
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
2014-10-29 03:56:36 +01:00
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) {
// Insert the album/track title into the dedup map
// so we can check tracks against it below
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
2014-10-29 03:56:36 +01:00
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);
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
2014-10-29 03:56:36 +01:00
result.metadata_.set_albumartist(majority_artist);
ret << result;
}
}
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
2014-10-29 03:56:36 +01:00
for (int i = 0; i < response.result_size(); ++i) {
const cpb::spotify::Track& track = response.result(i);
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
2014-10-29 03:56:36 +01:00
// Check this track/album against tracks we've already seen
// in the album results, and skip if it's a duplicate
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
2014-10-29 03:56:36 +01:00
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;
}
2011-08-29 00:59:18 +02:00
emit ResultsAvailable(state.orig_id_, ret);
emit SearchFinished(state.orig_id_);
}
void SpotifySearchProvider::LoadArtAsync(int id, const Result& result) {
SpotifyServer* s = server();
if (!s) {
emit ArtLoaded(id, QImage());
return;
}
2011-08-29 02:24:32 +02:00
QString image_id = QUrl(result.metadata_.art_automatic()).path();
if (image_id.startsWith('/')) image_id.remove(0, 1);
2011-08-29 00:59:18 +02:00
pending_art_[image_id] = id;
s->LoadImage(image_id);
}
void SpotifySearchProvider::ArtLoadedSlot(const QString& id,
const QImage& image) {
2011-08-29 00:59:18 +02:00
QMap<QString, int>::iterator it = pending_art_.find(id);
if (it == pending_art_.end()) return;
2011-08-29 00:59:18 +02:00
const int orig_id = it.value();
pending_art_.erase(it);
emit ArtLoaded(orig_id, ScaleAndPad(image));
}
bool SpotifySearchProvider::IsLoggedIn() {
if (server()) {
return service_->IsLoggedIn();
}
return false;
}
2011-08-29 00:59:18 +02:00
void SpotifySearchProvider::ShowConfig() {
if (service_) {
return service_->ShowConfig();
}
}
void SpotifySearchProvider::AddSuggestionFromTrack(
const cpb::spotify::Track& track) {
if (!track.title().empty()) {
suggestions_.insert(QString::fromUtf8(track.title().c_str()));
}
for (int j = 0; j < track.artist_size(); ++j) {
if (!track.artist(j).empty()) {
suggestions_.insert(QString::fromUtf8(track.artist(j).c_str()));
}
}
if (!track.album().empty()) {
suggestions_.insert(QString::fromUtf8(track.album().c_str()));
}
}
void SpotifySearchProvider::AddSuggestionFromAlbum(
const cpb::spotify::Album& album) {
AddSuggestionFromTrack(album.metadata());
for (int i = 0; i < album.track_size(); ++i) {
AddSuggestionFromTrack(album.track(i));
}
}
void SpotifySearchProvider::SuggestionsLoaded(
const cpb::spotify::LoadPlaylistResponse& playlist) {
for (int i = 0; i < playlist.track_size(); ++i) {
AddSuggestionFromTrack(playlist.track(i));
}
}
void SpotifySearchProvider::SuggestionsLoaded(
const cpb::spotify::BrowseToplistResponse& response) {
for (int i = 0; i < response.track_size(); ++i) {
AddSuggestionFromTrack(response.track(i));
}
for (int i = 0; i < response.album_size(); ++i) {
AddSuggestionFromAlbum(response.album(i));
}
}
void SpotifySearchProvider::LoadSuggestions() {
if (!server()) {
return;
}
server()->LoadStarred();
server()->LoadToplist();
}
QStringList SpotifySearchProvider::GetSuggestions(int count) {
if (suggestions_.empty()) {
LoadSuggestions();
return QStringList();
}
QStringList all_suggestions = suggestions_.values();
std::mt19937 gen(std::time(0));
std::uniform_int_distribution<> random(0, all_suggestions.size() - 1);
QSet<QString> candidates;
const int max = qMin(count, all_suggestions.size());
while (candidates.size() < max) {
const int index = random(gen);
candidates.insert(all_suggestions[index]);
}
return candidates.toList();
}