feat(server): expose main credit stat to reflect only album artist | artist credit (#4268)

* attempt using artist | albumartist

* add primary stats, expose to ND and Subsonic

* response to feedback (1)

* address feedback part 1

* fix docs and artist show

* fix migration order

---------

Co-authored-by: Deluan Quintão <deluan@navidrome.org>
This commit is contained in:
Kendall Garner
2025-06-28 23:00:13 +00:00
committed by GitHub
parent d4f8419d83
commit 2741b1a5c5
8 changed files with 115 additions and 34 deletions

View File

@@ -397,7 +397,7 @@ func (api *Router) buildArtistDirectory(ctx context.Context, artist *model.Artis
if artist.PlayCount > 0 {
dir.Played = artist.PlayDate
}
dir.AlbumCount = int32(artist.AlbumCount)
dir.AlbumCount = getArtistAlbumCount(artist)
dir.UserRating = int32(artist.Rating)
if artist.Starred {
dir.Starred = artist.StarredAt

View File

@@ -77,18 +77,16 @@ func sortName(sortName, orderName string) string {
return orderName
}
func getArtistAlbumCount(a model.Artist) int32 {
albumStats := a.Stats[model.RoleAlbumArtist]
func getArtistAlbumCount(a *model.Artist) int32 {
// If ArtistParticipations are set, then `getArtist` will return albums
// where the artist is an album artist OR artist. While it may be an underestimate,
// guess the count by taking a max of the album artist and artist count. This is
// guaranteed to be <= the actual count.
// where the artist is an album artist OR artist. Use the custom stat
// main credit for this calculation.
// Otherwise, return just the roles as album artist (precise)
if conf.Server.Subsonic.ArtistParticipations {
artistStats := a.Stats[model.RoleArtist]
return int32(max(artistStats.AlbumCount, albumStats.AlbumCount))
mainCreditStats := a.Stats[model.RoleMainCredit]
return int32(mainCreditStats.AlbumCount)
} else {
albumStats := a.Stats[model.RoleAlbumArtist]
return int32(albumStats.AlbumCount)
}
}
@@ -111,7 +109,7 @@ func toArtistID3(r *http.Request, a model.Artist) responses.ArtistID3 {
artist := responses.ArtistID3{
Id: a.ID,
Name: a.Name,
AlbumCount: getArtistAlbumCount(a),
AlbumCount: getArtistAlbumCount(&a),
CoverArt: a.CoverArtID().String(),
ArtistImageUrl: public.ImageURL(r, a.CoverArtID(), 600),
UserRating: int32(a.Rating),

View File

@@ -145,7 +145,7 @@ var _ = Describe("helpers", func() {
model.RoleAlbumArtist: {
AlbumCount: 3,
},
model.RoleArtist: {
model.RoleMainCredit: {
AlbumCount: 4,
},
},
@@ -153,13 +153,13 @@ var _ = Describe("helpers", func() {
It("Handles album count without artist participations", func() {
conf.Server.Subsonic.ArtistParticipations = false
result := getArtistAlbumCount(artist)
result := getArtistAlbumCount(&artist)
Expect(result).To(Equal(int32(3)))
})
It("Handles album count without with participations", func() {
conf.Server.Subsonic.ArtistParticipations = true
result := getArtistAlbumCount(artist)
result := getArtistAlbumCount(&artist)
Expect(result).To(Equal(int32(4)))
})
})