🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
feat(subsonic): set sortName for OS AlbumList (#3776)
Kendall Garner5869f7caaf6c
diff --git a/server/subsonic/album_lists.go b/server/subsonic/album_lists.goindex cb64ac485..39a164500 100644--- a/server/subsonic/album_lists.go+++ b/server/subsonic/album_lists.go@@ -103,8 +103,8 @@ func (api *Router) GetAlbumList2(w http.ResponseWriter, r *http.Request) (*respow.Header().Set("x-total-count", strconv.FormatInt(pageCount, 10))response := newResponse()- response.AlbumList2 = &responses.AlbumList{- Album: slice.MapWithArg(albums, r.Context(), childFromAlbum),+ response.AlbumList2 = &responses.AlbumList2{+ Album: slice.MapWithArg(albums, r.Context(), buildAlbumID3),}return response, nil}@@ -137,13 +137,29 @@ func (api *Router) GetStarred(r *http.Request) (*responses.Subsonic, error) {}func (api *Router) GetStarred2(r *http.Request) (*responses.Subsonic, error) {- resp, err := api.GetStarred(r)+ ctx := r.Context()+ artists, err := api.ds.Artist(ctx).GetAll(filter.ArtistsByStarred())if err != nil {+ log.Error(r, "Error retrieving starred artists", err)+ return nil, err+ }+ options := filter.ByStarred()+ albums, err := api.ds.Album(ctx).GetAll(options)+ if err != nil {+ log.Error(r, "Error retrieving starred albums", err)+ return nil, err+ }+ mediaFiles, err := api.ds.MediaFile(ctx).GetAll(options)+ if err != nil {+ log.Error(r, "Error retrieving starred mediaFiles", err)return nil, err}response := newResponse()- response.Starred2 = resp.Starred+ response.Starred2 = &responses.Starred2{}+ response.Starred2.Artist = slice.MapWithArg(artists, r, toArtistID3)+ response.Starred2.Album = slice.MapWithArg(albums, ctx, buildAlbumID3)+ response.Starred2.Song = slice.MapWithArg(mediaFiles, ctx, childFromMediaFile)return response, nil}diff --git a/server/subsonic/helpers.go b/server/subsonic/helpers.goindex 01d876d19..056caed84 100644--- a/server/subsonic/helpers.go+++ b/server/subsonic/helpers.go@@ -317,6 +317,7 @@ func osChildFromAlbum(ctx context.Context, al model.Album) *responses.OpenSubsonchild.DisplayAlbumArtist = al.AlbumArtistchild.AlbumArtists = artistRefs(al.Participants[model.RoleAlbumArtist])child.ExplicitStatus = mapExplicitStatus(al.ExplicitStatus)+ child.SortName = sortName(al.SortAlbumName, al.OrderAlbumName)return &child}diff --git a/server/subsonic/responses/.snapshots/Responses AlbumList with OS data should match .JSON b/server/subsonic/responses/.snapshots/Responses AlbumList with OS data should match .JSONnew file mode 100644index 000000000..c7bddc312--- /dev/null+++ b/server/subsonic/responses/.snapshots/Responses AlbumList with OS data should match .JSON@@ -0,0 +1,62 @@+{+ "status": "ok",+ "version": "1.8.0",+ "type": "navidrome",+ "serverVersion": "v0.0.0",+ "openSubsonic": true,+ "albumList": {+ "album": [+ {+ "id": "1",+ "isDir": false,+ "isVideo": false,+ "bpm": 0,+ "comment": "",+ "sortName": "sort name",+ "mediaType": "album",+ "musicBrainzId": "00000000-0000-0000-0000-000000000000",+ "genres": [+ {+ "name": "Genre 1"+ },+ {+ "name": "Genre 2"+ }+ ],+ "replayGain": {},+ "channelCount": 0,+ "samplingRate": 0,+ "bitDepth": 0,+ "moods": [+ "mood1",+ "mood2"+ ],+ "artists": [+ {+ "id": "artist-1",+ "name": "Artist 1"+ },+ {+ "id": "artist-2",+ "name": "Artist 2"+ }+ ],+ "displayArtist": "Display artist",+ "albumArtists": [+ {+ "id": "album-artist-1",+ "name": "Artist 1"+ },+ {+ "id": "album-artist-2",+ "name": "Artist 2"+ }+ ],+ "displayAlbumArtist": "Display album artist",+ "contributors": [],+ "displayComposer": "",+ "explicitStatus": "explicit"+ }+ ]+ }+}diff --git a/server/subsonic/responses/.snapshots/Responses AlbumList with OS data should match .XML b/server/subsonic/responses/.snapshots/Responses AlbumList with OS data should match .XMLnew file mode 100644index 000000000..33aef53be--- /dev/null+++ b/server/subsonic/responses/.snapshots/Responses AlbumList with OS data should match .XML@@ -0,0 +1,14 @@+<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">+ <albumList>+ <album id="1" isDir="false" isVideo="false" sortName="sort name" mediaType="album" musicBrainzId="00000000-0000-0000-0000-000000000000" displayArtist="Display artist" displayAlbumArtist="Display album artist" explicitStatus="explicit">+ <genres name="Genre 1"></genres>+ <genres name="Genre 2"></genres>+ <moods>mood1</moods>+ <moods>mood2</moods>+ <artists id="artist-1" name="Artist 1"></artists>+ <artists id="artist-2" name="Artist 2"></artists>+ <albumArtists id="album-artist-1" name="Artist 1"></albumArtists>+ <albumArtists id="album-artist-2" name="Artist 2"></albumArtists>+ </album>+ </albumList>+</subsonic-response>diff --git a/server/subsonic/responses/responses.go b/server/subsonic/responses/responses.goindex b2133ee6e..f329fae4b 100644--- a/server/subsonic/responses/responses.go+++ b/server/subsonic/responses/responses.go@@ -21,13 +21,13 @@ type Subsonic struct {User *User `xml:"user,omitempty" json:"user,omitempty"`Users *Users `xml:"users,omitempty" json:"users,omitempty"`AlbumList *AlbumList `xml:"albumList,omitempty" json:"albumList,omitempty"`- AlbumList2 *AlbumList `xml:"albumList2,omitempty" json:"albumList2,omitempty"`+ AlbumList2 *AlbumList2 `xml:"albumList2,omitempty" json:"albumList2,omitempty"`Playlists *Playlists `xml:"playlists,omitempty" json:"playlists,omitempty"`Playlist *PlaylistWithSongs `xml:"playlist,omitempty" json:"playlist,omitempty"`SearchResult2 *SearchResult2 `xml:"searchResult2,omitempty" json:"searchResult2,omitempty"`SearchResult3 *SearchResult3 `xml:"searchResult3,omitempty" json:"searchResult3,omitempty"`Starred *Starred `xml:"starred,omitempty" json:"starred,omitempty"`- Starred2 *Starred `xml:"starred2,omitempty" json:"starred2,omitempty"`+ Starred2 *Starred2 `xml:"starred2,omitempty" json:"starred2,omitempty"`NowPlaying *NowPlaying `xml:"nowPlaying,omitempty" json:"nowPlaying,omitempty"`Song *Child `xml:"song,omitempty" json:"song,omitempty"`RandomSongs *Songs `xml:"randomSongs,omitempty" json:"randomSongs,omitempty"`@@ -297,6 +297,10 @@ type AlbumList struct {Album []Child `xml:"album" json:"album,omitempty"`}+type AlbumList2 struct {+ Album []AlbumID3 `xml:"album" json:"album,omitempty"`+}+type Playlist struct {Id string `xml:"id,attr" json:"id"`Name string `xml:"name,attr" json:"name"`@@ -342,6 +346,12 @@ type Starred struct {Song []Child `xml:"song" json:"song,omitempty"`}+type Starred2 struct {+ Artist []ArtistID3 `xml:"artist" json:"artist,omitempty"`+ Album []AlbumID3 `xml:"album" json:"album,omitempty"`+ Song []Child `xml:"song" json:"song,omitempty"`+}+type NowPlayingEntry struct {ChildUserName string `xml:"username,attr" json:"username"`diff --git a/server/subsonic/responses/responses_test.go b/server/subsonic/responses/responses_test.goindex 7d4f05373..fed454195 100644--- a/server/subsonic/responses/responses_test.go+++ b/server/subsonic/responses/responses_test.go@@ -403,6 +403,42 @@ var _ = Describe("Responses", func() {Expect(json.MarshalIndent(response, "", " ")).To(MatchSnapshot())})})++ Context("with OS data", func() {+ BeforeEach(func() {+ child := make([]Child, 1)+ child[0] = Child{Id: "1", OpenSubsonicChild: &OpenSubsonicChild{+ MediaType: MediaTypeAlbum,+ MusicBrainzId: "00000000-0000-0000-0000-000000000000",+ Genres: Array[ItemGenre]{+ ItemGenre{Name: "Genre 1"},+ ItemGenre{Name: "Genre 2"},+ },+ Moods: []string{"mood1", "mood2"},+ DisplayArtist: "Display artist",+ Artists: Array[ArtistID3Ref]{+ ArtistID3Ref{Id: "artist-1", Name: "Artist 1"},+ ArtistID3Ref{Id: "artist-2", Name: "Artist 2"},+ },+ DisplayAlbumArtist: "Display album artist",+ AlbumArtists: Array[ArtistID3Ref]{+ ArtistID3Ref{Id: "album-artist-1", Name: "Artist 1"},+ ArtistID3Ref{Id: "album-artist-2", Name: "Artist 2"},+ },+ ExplicitStatus: "explicit",+ SortName: "sort name",+ }}+ response.AlbumList.Album = child++ })++ It("should match .XML", func() {+ Expect(xml.MarshalIndent(response, "", " ")).To(MatchSnapshot())+ })+ It("should match .JSON", func() {+ Expect(json.MarshalIndent(response, "", " ")).To(MatchSnapshot())+ })+ })})Describe("User", func() {