Skip to content

Commit 9407450

Browse files
committed
fix(subsonic): return artist as track artist in TrackChild
fixes #654
1 parent fcf6974 commit 9407450

File tree

4 files changed

+56
-42
lines changed

4 files changed

+56
-42
lines changed

server/ctrlsubsonic/spec/construct_by_folder.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package spec
33
import (
44
"cmp"
55
"path/filepath"
6+
"sort"
67

78
"go.senan.xyz/gonic/db"
89
)
@@ -63,14 +64,14 @@ func NewTCAlbumByFolder(f *db.Album) *TrackChild {
6364

6465
func NewTCTrackByFolder(t *db.Track, parent *db.Album) *TrackChild {
6566
trCh := &TrackChild{
66-
ID: t.SID(),
67-
ContentType: t.MIME(),
68-
Suffix: formatExt(t.Ext()),
69-
Size: t.Size,
70-
Artist: t.TagTrackArtist,
71-
Title: cmp.Or(t.TagTitle, t.Filename),
72-
TrackNumber: t.TagTrackNumber,
73-
DiscNumber: t.TagDiscNumber,
67+
ID: t.SID(),
68+
ContentType: t.MIME(),
69+
Suffix: formatExt(t.Ext()),
70+
Size: t.Size,
71+
DisplayArtist: t.TagTrackArtist,
72+
Title: cmp.Or(t.TagTitle, t.Filename),
73+
TrackNumber: t.TagTrackNumber,
74+
DiscNumber: t.TagDiscNumber,
7475
Path: filepath.Join(
7576
parent.LeftPath,
7677
parent.RightPath,
@@ -115,10 +116,14 @@ func NewTCTrackByFolder(t *db.Track, parent *db.Album) *TrackChild {
115116
for _, g := range t.Genres {
116117
trCh.Genres = append(trCh.Genres, &GenreRef{Name: g.Name})
117118
}
119+
sort.Slice(t.Artists, func(i, j int) bool {
120+
return t.Artists[i].ID < t.Artists[j].ID
121+
})
122+
if len(t.Artists) > 0 {
123+
trCh.Artist = t.Artists[0].Name
124+
trCh.ArtistID = t.Artists[0].SID()
125+
}
118126
for _, a := range t.Artists {
119-
if a.Name == t.TagTrackArtist {
120-
trCh.ArtistID = a.SID()
121-
}
122127
trCh.Artists = append(trCh.Artists, &ArtistRef{ID: a.SID(), Name: a.Name})
123128
}
124129
if t.ReplayGainTrackGain != 0 || t.ReplayGainAlbumGain != 0 {

server/ctrlsubsonic/spec/construct_by_tags.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
7979
ID: t.SID(),
8080
Album: album.TagTitle,
8181
AlbumID: album.SID(),
82-
Artist: t.TagTrackArtist,
8382
Artists: []*ArtistRef{},
8483
DisplayArtist: t.TagTrackArtist,
8584
AlbumArtists: []*ArtistRef{},
@@ -118,21 +117,31 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
118117
if t.TrackRating != nil {
119118
ret.UserRating = t.TrackRating.Rating
120119
}
121-
if len(album.Artists) > 0 {
122-
sort.Slice(album.Artists, func(i, j int) bool {
123-
return album.Artists[i].ID < album.Artists[j].ID
124-
})
120+
121+
sort.Slice(t.Artists, func(i, j int) bool {
122+
return t.Artists[i].ID < t.Artists[j].ID
123+
})
124+
sort.Slice(album.Artists, func(i, j int) bool {
125+
return album.Artists[i].ID < album.Artists[j].ID
126+
})
127+
128+
switch {
129+
case len(t.Artists) > 0:
130+
ret.Artist = t.Artists[0].Name
131+
ret.ArtistID = t.Artists[0].SID()
132+
case len(album.Artists) > 0:
133+
ret.Artist = album.Artists[0].Name
125134
ret.ArtistID = album.Artists[0].SID()
126135
}
136+
for _, a := range t.Artists {
137+
ret.Artists = append(ret.Artists, &ArtistRef{ID: a.SID(), Name: a.Name})
138+
}
127139
if len(t.Genres) > 0 {
128140
ret.Genre = t.Genres[0].Name
129141
}
130142
for _, g := range t.Genres {
131143
ret.Genres = append(ret.Genres, &GenreRef{Name: g.Name})
132144
}
133-
for _, a := range t.Artists {
134-
ret.Artists = append(ret.Artists, &ArtistRef{ID: a.SID(), Name: a.Name})
135-
}
136145
for _, a := range album.Artists {
137146
ret.AlbumArtists = append(ret.AlbumArtists, &ArtistRef{ID: a.SID(), Name: a.Name})
138147
}

server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"artist": "artist-0",
1818
"artistId": "ar-1",
1919
"artists": [{ "id": "ar-1", "name": "artist-0" }],
20-
"displayArtist": "",
20+
"displayArtist": "artist-0",
2121
"albumArtists": null,
2222
"displayAlbumArtist": "",
2323
"bitRate": 100,
@@ -45,7 +45,7 @@
4545
"artist": "artist-0",
4646
"artistId": "ar-1",
4747
"artists": [{ "id": "ar-1", "name": "artist-0" }],
48-
"displayArtist": "",
48+
"displayArtist": "artist-0",
4949
"albumArtists": null,
5050
"displayAlbumArtist": "",
5151
"bitRate": 100,
@@ -73,7 +73,7 @@
7373
"artist": "artist-0",
7474
"artistId": "ar-1",
7575
"artists": [{ "id": "ar-1", "name": "artist-0" }],
76-
"displayArtist": "",
76+
"displayArtist": "artist-0",
7777
"albumArtists": null,
7878
"displayAlbumArtist": "",
7979
"bitRate": 100,

server/ctrlsubsonic/testdata/test_search_two_q_tra

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"artist": "artist-0",
1515
"artistId": "ar-1",
1616
"artists": [{ "id": "ar-1", "name": "artist-0" }],
17-
"displayArtist": "",
17+
"displayArtist": "artist-0",
1818
"albumArtists": null,
1919
"displayAlbumArtist": "",
2020
"bitRate": 100,
@@ -42,7 +42,7 @@
4242
"artist": "artist-0",
4343
"artistId": "ar-1",
4444
"artists": [{ "id": "ar-1", "name": "artist-0" }],
45-
"displayArtist": "",
45+
"displayArtist": "artist-0",
4646
"albumArtists": null,
4747
"displayAlbumArtist": "",
4848
"bitRate": 100,
@@ -70,7 +70,7 @@
7070
"artist": "artist-0",
7171
"artistId": "ar-1",
7272
"artists": [{ "id": "ar-1", "name": "artist-0" }],
73-
"displayArtist": "",
73+
"displayArtist": "artist-0",
7474
"albumArtists": null,
7575
"displayAlbumArtist": "",
7676
"bitRate": 100,
@@ -98,7 +98,7 @@
9898
"artist": "artist-0",
9999
"artistId": "ar-1",
100100
"artists": [{ "id": "ar-1", "name": "artist-0" }],
101-
"displayArtist": "",
101+
"displayArtist": "artist-0",
102102
"albumArtists": null,
103103
"displayAlbumArtist": "",
104104
"bitRate": 100,
@@ -126,7 +126,7 @@
126126
"artist": "artist-0",
127127
"artistId": "ar-1",
128128
"artists": [{ "id": "ar-1", "name": "artist-0" }],
129-
"displayArtist": "",
129+
"displayArtist": "artist-0",
130130
"albumArtists": null,
131131
"displayAlbumArtist": "",
132132
"bitRate": 100,
@@ -154,7 +154,7 @@
154154
"artist": "artist-0",
155155
"artistId": "ar-1",
156156
"artists": [{ "id": "ar-1", "name": "artist-0" }],
157-
"displayArtist": "",
157+
"displayArtist": "artist-0",
158158
"albumArtists": null,
159159
"displayAlbumArtist": "",
160160
"bitRate": 100,
@@ -182,7 +182,7 @@
182182
"artist": "artist-0",
183183
"artistId": "ar-1",
184184
"artists": [{ "id": "ar-1", "name": "artist-0" }],
185-
"displayArtist": "",
185+
"displayArtist": "artist-0",
186186
"albumArtists": null,
187187
"displayAlbumArtist": "",
188188
"bitRate": 100,
@@ -210,7 +210,7 @@
210210
"artist": "artist-0",
211211
"artistId": "ar-1",
212212
"artists": [{ "id": "ar-1", "name": "artist-0" }],
213-
"displayArtist": "",
213+
"displayArtist": "artist-0",
214214
"albumArtists": null,
215215
"displayAlbumArtist": "",
216216
"bitRate": 100,
@@ -238,7 +238,7 @@
238238
"artist": "artist-0",
239239
"artistId": "ar-1",
240240
"artists": [{ "id": "ar-1", "name": "artist-0" }],
241-
"displayArtist": "",
241+
"displayArtist": "artist-0",
242242
"albumArtists": null,
243243
"displayAlbumArtist": "",
244244
"bitRate": 100,
@@ -266,7 +266,7 @@
266266
"artist": "artist-1",
267267
"artistId": "ar-2",
268268
"artists": [{ "id": "ar-2", "name": "artist-1" }],
269-
"displayArtist": "",
269+
"displayArtist": "artist-1",
270270
"albumArtists": null,
271271
"displayAlbumArtist": "",
272272
"bitRate": 100,
@@ -294,7 +294,7 @@
294294
"artist": "artist-1",
295295
"artistId": "ar-2",
296296
"artists": [{ "id": "ar-2", "name": "artist-1" }],
297-
"displayArtist": "",
297+
"displayArtist": "artist-1",
298298
"albumArtists": null,
299299
"displayAlbumArtist": "",
300300
"bitRate": 100,
@@ -322,7 +322,7 @@
322322
"artist": "artist-1",
323323
"artistId": "ar-2",
324324
"artists": [{ "id": "ar-2", "name": "artist-1" }],
325-
"displayArtist": "",
325+
"displayArtist": "artist-1",
326326
"albumArtists": null,
327327
"displayAlbumArtist": "",
328328
"bitRate": 100,
@@ -350,7 +350,7 @@
350350
"artist": "artist-1",
351351
"artistId": "ar-2",
352352
"artists": [{ "id": "ar-2", "name": "artist-1" }],
353-
"displayArtist": "",
353+
"displayArtist": "artist-1",
354354
"albumArtists": null,
355355
"displayAlbumArtist": "",
356356
"bitRate": 100,
@@ -378,7 +378,7 @@
378378
"artist": "artist-1",
379379
"artistId": "ar-2",
380380
"artists": [{ "id": "ar-2", "name": "artist-1" }],
381-
"displayArtist": "",
381+
"displayArtist": "artist-1",
382382
"albumArtists": null,
383383
"displayAlbumArtist": "",
384384
"bitRate": 100,
@@ -406,7 +406,7 @@
406406
"artist": "artist-1",
407407
"artistId": "ar-2",
408408
"artists": [{ "id": "ar-2", "name": "artist-1" }],
409-
"displayArtist": "",
409+
"displayArtist": "artist-1",
410410
"albumArtists": null,
411411
"displayAlbumArtist": "",
412412
"bitRate": 100,
@@ -434,7 +434,7 @@
434434
"artist": "artist-1",
435435
"artistId": "ar-2",
436436
"artists": [{ "id": "ar-2", "name": "artist-1" }],
437-
"displayArtist": "",
437+
"displayArtist": "artist-1",
438438
"albumArtists": null,
439439
"displayAlbumArtist": "",
440440
"bitRate": 100,
@@ -462,7 +462,7 @@
462462
"artist": "artist-1",
463463
"artistId": "ar-2",
464464
"artists": [{ "id": "ar-2", "name": "artist-1" }],
465-
"displayArtist": "",
465+
"displayArtist": "artist-1",
466466
"albumArtists": null,
467467
"displayAlbumArtist": "",
468468
"bitRate": 100,
@@ -490,7 +490,7 @@
490490
"artist": "artist-1",
491491
"artistId": "ar-2",
492492
"artists": [{ "id": "ar-2", "name": "artist-1" }],
493-
"displayArtist": "",
493+
"displayArtist": "artist-1",
494494
"albumArtists": null,
495495
"displayAlbumArtist": "",
496496
"bitRate": 100,
@@ -518,7 +518,7 @@
518518
"artist": "artist-2",
519519
"artistId": "ar-3",
520520
"artists": [{ "id": "ar-3", "name": "artist-2" }],
521-
"displayArtist": "",
521+
"displayArtist": "artist-2",
522522
"albumArtists": null,
523523
"displayAlbumArtist": "",
524524
"bitRate": 100,
@@ -546,7 +546,7 @@
546546
"artist": "artist-2",
547547
"artistId": "ar-3",
548548
"artists": [{ "id": "ar-3", "name": "artist-2" }],
549-
"displayArtist": "",
549+
"displayArtist": "artist-2",
550550
"albumArtists": null,
551551
"displayAlbumArtist": "",
552552
"bitRate": 100,

0 commit comments

Comments
 (0)