From 9407450660db6083639e3b5cd3cff1c35aeaa07b Mon Sep 17 00:00:00 2001 From: sentriz Date: Sat, 7 Feb 2026 17:14:56 +0000 Subject: [PATCH] fix(subsonic): return artist as track artist in TrackChild fixes #654 --- .../ctrlsubsonic/spec/construct_by_folder.go | 27 ++++++++----- server/ctrlsubsonic/spec/construct_by_tags.go | 25 ++++++++---- .../test_get_music_directory_with_tracks | 6 +-- .../testdata/test_search_two_q_tra | 40 +++++++++---------- 4 files changed, 56 insertions(+), 42 deletions(-) diff --git a/server/ctrlsubsonic/spec/construct_by_folder.go b/server/ctrlsubsonic/spec/construct_by_folder.go index efb741c..aaba0ab 100644 --- a/server/ctrlsubsonic/spec/construct_by_folder.go +++ b/server/ctrlsubsonic/spec/construct_by_folder.go @@ -3,6 +3,7 @@ package spec import ( "cmp" "path/filepath" + "sort" "go.senan.xyz/gonic/db" ) @@ -63,14 +64,14 @@ func NewTCAlbumByFolder(f *db.Album) *TrackChild { func NewTCTrackByFolder(t *db.Track, parent *db.Album) *TrackChild { trCh := &TrackChild{ - ID: t.SID(), - ContentType: t.MIME(), - Suffix: formatExt(t.Ext()), - Size: t.Size, - Artist: t.TagTrackArtist, - Title: cmp.Or(t.TagTitle, t.Filename), - TrackNumber: t.TagTrackNumber, - DiscNumber: t.TagDiscNumber, + ID: t.SID(), + ContentType: t.MIME(), + Suffix: formatExt(t.Ext()), + Size: t.Size, + DisplayArtist: t.TagTrackArtist, + Title: cmp.Or(t.TagTitle, t.Filename), + TrackNumber: t.TagTrackNumber, + DiscNumber: t.TagDiscNumber, Path: filepath.Join( parent.LeftPath, parent.RightPath, @@ -115,10 +116,14 @@ func NewTCTrackByFolder(t *db.Track, parent *db.Album) *TrackChild { for _, g := range t.Genres { trCh.Genres = append(trCh.Genres, &GenreRef{Name: g.Name}) } + sort.Slice(t.Artists, func(i, j int) bool { + return t.Artists[i].ID < t.Artists[j].ID + }) + if len(t.Artists) > 0 { + trCh.Artist = t.Artists[0].Name + trCh.ArtistID = t.Artists[0].SID() + } for _, a := range t.Artists { - if a.Name == t.TagTrackArtist { - trCh.ArtistID = a.SID() - } trCh.Artists = append(trCh.Artists, &ArtistRef{ID: a.SID(), Name: a.Name}) } if t.ReplayGainTrackGain != 0 || t.ReplayGainAlbumGain != 0 { diff --git a/server/ctrlsubsonic/spec/construct_by_tags.go b/server/ctrlsubsonic/spec/construct_by_tags.go index 91dbbc9..b62c013 100644 --- a/server/ctrlsubsonic/spec/construct_by_tags.go +++ b/server/ctrlsubsonic/spec/construct_by_tags.go @@ -79,7 +79,6 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild { ID: t.SID(), Album: album.TagTitle, AlbumID: album.SID(), - Artist: t.TagTrackArtist, Artists: []*ArtistRef{}, DisplayArtist: t.TagTrackArtist, AlbumArtists: []*ArtistRef{}, @@ -118,21 +117,31 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild { if t.TrackRating != nil { ret.UserRating = t.TrackRating.Rating } - if len(album.Artists) > 0 { - sort.Slice(album.Artists, func(i, j int) bool { - return album.Artists[i].ID < album.Artists[j].ID - }) + + sort.Slice(t.Artists, func(i, j int) bool { + return t.Artists[i].ID < t.Artists[j].ID + }) + sort.Slice(album.Artists, func(i, j int) bool { + return album.Artists[i].ID < album.Artists[j].ID + }) + + switch { + case len(t.Artists) > 0: + ret.Artist = t.Artists[0].Name + ret.ArtistID = t.Artists[0].SID() + case len(album.Artists) > 0: + ret.Artist = album.Artists[0].Name ret.ArtistID = album.Artists[0].SID() } + for _, a := range t.Artists { + ret.Artists = append(ret.Artists, &ArtistRef{ID: a.SID(), Name: a.Name}) + } if len(t.Genres) > 0 { ret.Genre = t.Genres[0].Name } for _, g := range t.Genres { ret.Genres = append(ret.Genres, &GenreRef{Name: g.Name}) } - for _, a := range t.Artists { - ret.Artists = append(ret.Artists, &ArtistRef{ID: a.SID(), Name: a.Name}) - } for _, a := range album.Artists { ret.AlbumArtists = append(ret.AlbumArtists, &ArtistRef{ID: a.SID(), Name: a.Name}) } diff --git a/server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks b/server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks index 41c5547..dbaa316 100644 --- a/server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks +++ b/server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks @@ -17,7 +17,7 @@ "artist": "artist-0", "artistId": "ar-1", "artists": [{ "id": "ar-1", "name": "artist-0" }], - "displayArtist": "", + "displayArtist": "artist-0", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -45,7 +45,7 @@ "artist": "artist-0", "artistId": "ar-1", "artists": [{ "id": "ar-1", "name": "artist-0" }], - "displayArtist": "", + "displayArtist": "artist-0", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -73,7 +73,7 @@ "artist": "artist-0", "artistId": "ar-1", "artists": [{ "id": "ar-1", "name": "artist-0" }], - "displayArtist": "", + "displayArtist": "artist-0", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, diff --git a/server/ctrlsubsonic/testdata/test_search_two_q_tra b/server/ctrlsubsonic/testdata/test_search_two_q_tra index 8d787f8..710b923 100644 --- a/server/ctrlsubsonic/testdata/test_search_two_q_tra +++ b/server/ctrlsubsonic/testdata/test_search_two_q_tra @@ -14,7 +14,7 @@ "artist": "artist-0", "artistId": "ar-1", "artists": [{ "id": "ar-1", "name": "artist-0" }], - "displayArtist": "", + "displayArtist": "artist-0", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -42,7 +42,7 @@ "artist": "artist-0", "artistId": "ar-1", "artists": [{ "id": "ar-1", "name": "artist-0" }], - "displayArtist": "", + "displayArtist": "artist-0", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -70,7 +70,7 @@ "artist": "artist-0", "artistId": "ar-1", "artists": [{ "id": "ar-1", "name": "artist-0" }], - "displayArtist": "", + "displayArtist": "artist-0", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -98,7 +98,7 @@ "artist": "artist-0", "artistId": "ar-1", "artists": [{ "id": "ar-1", "name": "artist-0" }], - "displayArtist": "", + "displayArtist": "artist-0", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -126,7 +126,7 @@ "artist": "artist-0", "artistId": "ar-1", "artists": [{ "id": "ar-1", "name": "artist-0" }], - "displayArtist": "", + "displayArtist": "artist-0", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -154,7 +154,7 @@ "artist": "artist-0", "artistId": "ar-1", "artists": [{ "id": "ar-1", "name": "artist-0" }], - "displayArtist": "", + "displayArtist": "artist-0", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -182,7 +182,7 @@ "artist": "artist-0", "artistId": "ar-1", "artists": [{ "id": "ar-1", "name": "artist-0" }], - "displayArtist": "", + "displayArtist": "artist-0", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -210,7 +210,7 @@ "artist": "artist-0", "artistId": "ar-1", "artists": [{ "id": "ar-1", "name": "artist-0" }], - "displayArtist": "", + "displayArtist": "artist-0", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -238,7 +238,7 @@ "artist": "artist-0", "artistId": "ar-1", "artists": [{ "id": "ar-1", "name": "artist-0" }], - "displayArtist": "", + "displayArtist": "artist-0", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -266,7 +266,7 @@ "artist": "artist-1", "artistId": "ar-2", "artists": [{ "id": "ar-2", "name": "artist-1" }], - "displayArtist": "", + "displayArtist": "artist-1", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -294,7 +294,7 @@ "artist": "artist-1", "artistId": "ar-2", "artists": [{ "id": "ar-2", "name": "artist-1" }], - "displayArtist": "", + "displayArtist": "artist-1", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -322,7 +322,7 @@ "artist": "artist-1", "artistId": "ar-2", "artists": [{ "id": "ar-2", "name": "artist-1" }], - "displayArtist": "", + "displayArtist": "artist-1", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -350,7 +350,7 @@ "artist": "artist-1", "artistId": "ar-2", "artists": [{ "id": "ar-2", "name": "artist-1" }], - "displayArtist": "", + "displayArtist": "artist-1", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -378,7 +378,7 @@ "artist": "artist-1", "artistId": "ar-2", "artists": [{ "id": "ar-2", "name": "artist-1" }], - "displayArtist": "", + "displayArtist": "artist-1", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -406,7 +406,7 @@ "artist": "artist-1", "artistId": "ar-2", "artists": [{ "id": "ar-2", "name": "artist-1" }], - "displayArtist": "", + "displayArtist": "artist-1", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -434,7 +434,7 @@ "artist": "artist-1", "artistId": "ar-2", "artists": [{ "id": "ar-2", "name": "artist-1" }], - "displayArtist": "", + "displayArtist": "artist-1", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -462,7 +462,7 @@ "artist": "artist-1", "artistId": "ar-2", "artists": [{ "id": "ar-2", "name": "artist-1" }], - "displayArtist": "", + "displayArtist": "artist-1", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -490,7 +490,7 @@ "artist": "artist-1", "artistId": "ar-2", "artists": [{ "id": "ar-2", "name": "artist-1" }], - "displayArtist": "", + "displayArtist": "artist-1", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -518,7 +518,7 @@ "artist": "artist-2", "artistId": "ar-3", "artists": [{ "id": "ar-3", "name": "artist-2" }], - "displayArtist": "", + "displayArtist": "artist-2", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100, @@ -546,7 +546,7 @@ "artist": "artist-2", "artistId": "ar-3", "artists": [{ "id": "ar-3", "name": "artist-2" }], - "displayArtist": "", + "displayArtist": "artist-2", "albumArtists": null, "displayAlbumArtist": "", "bitRate": 100,