diff --git a/src/core/song.cpp b/src/core/song.cpp index a8ddf260f..9a851cc30 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -114,6 +114,13 @@ struct Song::Private : public QSharedData { bool forced_compilation_on_; // Set by the user bool forced_compilation_off_; // Set by the user + // A unique album ID + // Used to distinguish between albums from providers that have multiple + // versions of a given album with the same title (e.g. Spotify). + // This is never persisted, it is only stored temporarily for global search + // results. + int album_id_; + float rating_; int playcount_; int skipcount_; @@ -177,6 +184,7 @@ Song::Private::Private() sampler_(false), forced_compilation_on_(false), forced_compilation_off_(false), + album_id_(-1), rating_(-1.0), playcount_(0), skipcount_(0), @@ -243,6 +251,7 @@ int Song::lastplayed() const { return d->lastplayed_; } int Song::score() const { return d->score_; } const QString& Song::cue_path() const { return d->cue_path_; } bool Song::has_cue() const { return !d->cue_path_.isEmpty(); } +int Song::album_id() const { return d->album_id_; } qint64 Song::beginning_nanosec() const { return d->beginning_; } qint64 Song::end_nanosec() const { return d->end_; } qint64 Song::length_nanosec() const { return d->end_ - d->beginning_; } @@ -280,6 +289,7 @@ void Song::set_genre(const QString& v) { d->genre_ = v; } void Song::set_comment(const QString& v) { d->comment_ = v; } void Song::set_compilation(bool v) { d->compilation_ = v; } void Song::set_sampler(bool v) { d->sampler_ = v; } +void Song::set_album_id(int v) { d->album_id_ = v; } void Song::set_beginning_nanosec(qint64 v) { d->beginning_ = qMax(0ll, v); } void Song::set_end_nanosec(qint64 v) { d->end_ = v; } void Song::set_length_nanosec(qint64 v) { d->end_ = d->beginning_ + v; } diff --git a/src/core/song.h b/src/core/song.h index 20b5c1431..4e9f5dc9e 100644 --- a/src/core/song.h +++ b/src/core/song.h @@ -173,6 +173,7 @@ class Song { int skipcount() const; int lastplayed() const; int score() const; + int album_id() const; const QString& cue_path() const; bool has_cue() const; @@ -242,6 +243,7 @@ class Song { void set_comment(const QString& v); void set_compilation(bool v); void set_sampler(bool v); + void set_album_id(int v); void set_beginning_nanosec(qint64 v); void set_end_nanosec(qint64 v); void set_length_nanosec(qint64 v); diff --git a/src/globalsearch/globalsearchmodel.cpp b/src/globalsearch/globalsearchmodel.cpp index f1192b5d8..bd4fc9beb 100644 --- a/src/globalsearch/globalsearchmodel.cpp +++ b/src/globalsearch/globalsearchmodel.cpp @@ -95,6 +95,7 @@ QStandardItem* GlobalSearchModel::BuildContainers( bool has_album_icon = false; QString display_text; QString sort_text; + int unique_tag = -1; int year = 0; switch (group_by_[level]) { @@ -113,6 +114,7 @@ QStandardItem* GlobalSearchModel::BuildContainers( year = qMax(0, s.year()); display_text = LibraryModel::PrettyYearAlbum(year, s.album()); sort_text = LibraryModel::SortTextForYear(year) + s.album(); + unique_tag = s.album_id(); has_album_icon = true; break; @@ -124,7 +126,12 @@ QStandardItem* GlobalSearchModel::BuildContainers( case LibraryModel::GroupBy_Composer: display_text = s.composer(); case LibraryModel::GroupBy_Genre: if (display_text.isNull()) display_text = s.genre(); - case LibraryModel::GroupBy_Album: if (display_text.isNull()) display_text = s.album(); + case LibraryModel::GroupBy_Album: + unique_tag = s.album_id(); + if (display_text.isNull()) { + display_text = s.album(); + } + // fallthrough case LibraryModel::GroupBy_AlbumArtist: if (display_text.isNull()) display_text = s.effective_albumartist(); display_text = LibraryModel::TextOrUnknown(display_text); sort_text = LibraryModel::SortTextForArtist(display_text); @@ -141,7 +148,7 @@ QStandardItem* GlobalSearchModel::BuildContainers( } // Find a container for this level - key->group_[level] = display_text; + key->group_[level] = display_text + QString::number(unique_tag); QStandardItem* container = containers_[*key]; if (!container) { container = new QStandardItem(display_text); diff --git a/src/globalsearch/spotifysearchprovider.cpp b/src/globalsearch/spotifysearchprovider.cpp index e696533d2..4c4a3740a 100644 --- a/src/globalsearch/spotifysearchprovider.cpp +++ b/src/globalsearch/spotifysearchprovider.cpp @@ -107,6 +107,10 @@ void SpotifySearchProvider::SearchFinishedSlot(const pb::spotify::SearchResponse for (int j=0; j < album.track_size() ; ++j) { Result result(this); SpotifyService::SongFromProtobuf(album.track(j), &result.metadata_); + + // Just use the album index as an id. + result.metadata_.set_album_id(i); + ret << result; } }