fix(subsonic): return artist as track artist in TrackChild

fixes #654
This commit is contained in:
sentriz
2026-02-07 17:18:52 +00:00
parent fcf69743f0
commit 9407450660
4 changed files with 56 additions and 42 deletions

No files matched your search

+16 -11
View File
@@ -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 {
+17 -8
View File
@@ -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})
}
@@ -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,
+20 -20
View File
@@ -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,