From cdccdc56c9072e539b808b998cf9bdfabe864149 Mon Sep 17 00:00:00 2001 From: Deluan Date: Tue, 28 Nov 2023 21:26:00 -0500 Subject: [PATCH] Add more OpenSubsonic fields - isCompilation - sortName --- server/subsonic/browsing.go | 2 ++ server/subsonic/helpers.go | 3 +++ .../Responses AlbumList with data should match .JSON | 5 +++-- .../Responses AlbumList with data should match .XML | 2 +- ...es AlbumWithSongsID3 with data should match .JSON | 7 +++++-- ...ses AlbumWithSongsID3 with data should match .XML | 4 ++-- ...AlbumWithSongsID3 without data should match .JSON | 4 +++- ... AlbumWithSongsID3 without data should match .XML | 2 +- .../Responses Bookmarks with data should match .JSON | 5 +++-- .../Responses Bookmarks with data should match .XML | 2 +- .../Responses Child with data should match .JSON | 5 +++-- .../Responses Child with data should match .XML | 2 +- .../Responses Child without data should match .JSON | 5 +++-- .../Responses Child without data should match .XML | 2 +- .../Responses Directory with data should match .JSON | 5 +++-- .../Responses Directory with data should match .XML | 2 +- .../Responses PlayQueue with data should match .JSON | 5 +++-- .../Responses PlayQueue with data should match .XML | 2 +- .../Responses Shares with data should match .JSON | 10 ++++++---- .../Responses Shares with data should match .XML | 4 ++-- ...sponses SimilarSongs with data should match .JSON | 5 +++-- ...esponses SimilarSongs with data should match .XML | 2 +- ...ponses SimilarSongs2 with data should match .JSON | 5 +++-- ...sponses SimilarSongs2 with data should match .XML | 2 +- .../Responses TopSongs with data should match .JSON | 5 +++-- .../Responses TopSongs with data should match .XML | 2 +- server/subsonic/responses/responses.go | 12 +++++++++--- server/subsonic/responses/responses_test.go | 8 ++++++-- 28 files changed, 75 insertions(+), 44 deletions(-) diff --git a/server/subsonic/browsing.go b/server/subsonic/browsing.go index 7c75c7427..bc6bb2465 100644 --- a/server/subsonic/browsing.go +++ b/server/subsonic/browsing.go @@ -432,6 +432,8 @@ func (api *Router) buildAlbum(ctx context.Context, album *model.Album, mfs model dir.Starred = &album.StarredAt } dir.MusicBrainzId = album.MbzAlbumID + dir.IsCompilation = album.Compilation + dir.SortName = album.SortAlbumName dir.Song = childrenFromMediaFiles(ctx, mfs) return dir } diff --git a/server/subsonic/helpers.go b/server/subsonic/helpers.go index ce88988d2..1d10ea23d 100644 --- a/server/subsonic/helpers.go +++ b/server/subsonic/helpers.go @@ -111,6 +111,7 @@ func toArtistID3(r *http.Request, a model.Artist) responses.ArtistID3 { ArtistImageUrl: public.ImageURL(r, a.CoverArtID(), 600), UserRating: int32(a.Rating), MusicBrainzId: a.MbzArtistID, + SortName: a.SortArtistName, } if a.Starred { artist.Starred = &a.StarredAt @@ -187,6 +188,7 @@ func childFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Child } child.BookmarkPosition = mf.BookmarkPosition child.Comment = mf.Comment + child.SortName = mf.SortTitle child.Bpm = int32(mf.Bpm) child.MediaType = responses.MediaTypeSong child.MusicBrainzId = mf.MbzRecordingID @@ -238,6 +240,7 @@ func childFromAlbum(_ context.Context, al model.Album) responses.Child { child.Played = &al.PlayDate } child.UserRating = int32(al.Rating) + child.SortName = al.SortAlbumName child.MediaType = responses.MediaTypeAlbum child.MusicBrainzId = al.MbzAlbumID return child diff --git a/server/subsonic/responses/.snapshots/Responses AlbumList with data should match .JSON b/server/subsonic/responses/.snapshots/Responses AlbumList with data should match .JSON index db626b5c5..a2dd3a7ea 100644 --- a/server/subsonic/responses/.snapshots/Responses AlbumList with data should match .JSON +++ b/server/subsonic/responses/.snapshots/Responses AlbumList with data should match .JSON @@ -11,10 +11,11 @@ "isDir": false, "title": "title", "isVideo": false, - "mediaType": "", - "musicBrainzId": "", "bpm": 0, "comment": "", + "sortName": "", + "mediaType": "", + "musicBrainzId": "", "genres": [] } ] diff --git a/server/subsonic/responses/.snapshots/Responses AlbumList with data should match .XML b/server/subsonic/responses/.snapshots/Responses AlbumList with data should match .XML index a45332c19..549d7a17c 100644 --- a/server/subsonic/responses/.snapshots/Responses AlbumList with data should match .XML +++ b/server/subsonic/responses/.snapshots/Responses AlbumList with data should match .XML @@ -1,5 +1,5 @@ - + diff --git a/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 with data should match .JSON b/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 with data should match .JSON index 7934ea4a7..6a6d74e6b 100644 --- a/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 with data should match .JSON +++ b/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 with data should match .JSON @@ -19,6 +19,8 @@ } ], "musicBrainzId": "1234", + "isCompilation": true, + "sortName": "sorted album", "song": [ { "id": "1", @@ -39,10 +41,11 @@ "duration": 146, "bitRate": 320, "isVideo": false, - "mediaType": "song", - "musicBrainzId": "4321", "bpm": 127, "comment": "a comment", + "sortName": "sorted song", + "mediaType": "song", + "musicBrainzId": "4321", "genres": [ { "name": "rock" diff --git a/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 with data should match .XML b/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 with data should match .XML index 128dab3e5..b329443e9 100644 --- a/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 with data should match .XML +++ b/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 with data should match .XML @@ -1,8 +1,8 @@ - + - + diff --git a/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 without data should match .JSON b/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 without data should match .JSON index 6c2024a08..ead02f6f5 100644 --- a/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 without data should match .JSON +++ b/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 without data should match .JSON @@ -9,6 +9,8 @@ "name": "", "userRating": 0, "genres": [], - "musicBrainzId": "" + "musicBrainzId": "", + "isCompilation": false, + "sortName": "" } } diff --git a/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 without data should match .XML b/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 without data should match .XML index affb6490b..58e03c04b 100644 --- a/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 without data should match .XML +++ b/server/subsonic/responses/.snapshots/Responses AlbumWithSongsID3 without data should match .XML @@ -1,3 +1,3 @@ - + diff --git a/server/subsonic/responses/.snapshots/Responses Bookmarks with data should match .JSON b/server/subsonic/responses/.snapshots/Responses Bookmarks with data should match .JSON index c87488cbf..8f0ac4f95 100644 --- a/server/subsonic/responses/.snapshots/Responses Bookmarks with data should match .JSON +++ b/server/subsonic/responses/.snapshots/Responses Bookmarks with data should match .JSON @@ -12,10 +12,11 @@ "isDir": false, "title": "title", "isVideo": false, - "mediaType": "", - "musicBrainzId": "", "bpm": 0, "comment": "", + "sortName": "", + "mediaType": "", + "musicBrainzId": "", "genres": [] }, "position": 123, diff --git a/server/subsonic/responses/.snapshots/Responses Bookmarks with data should match .XML b/server/subsonic/responses/.snapshots/Responses Bookmarks with data should match .XML index cb2ac042f..f3bfe4112 100644 --- a/server/subsonic/responses/.snapshots/Responses Bookmarks with data should match .XML +++ b/server/subsonic/responses/.snapshots/Responses Bookmarks with data should match .XML @@ -1,7 +1,7 @@ - + diff --git a/server/subsonic/responses/.snapshots/Responses Child with data should match .JSON b/server/subsonic/responses/.snapshots/Responses Child with data should match .JSON index bab848ffd..9c169f3b7 100644 --- a/server/subsonic/responses/.snapshots/Responses Child with data should match .JSON +++ b/server/subsonic/responses/.snapshots/Responses Child with data should match .JSON @@ -25,10 +25,11 @@ "duration": 146, "bitRate": 320, "isVideo": false, - "mediaType": "song", - "musicBrainzId": "4321", "bpm": 127, "comment": "a comment", + "sortName": "", + "mediaType": "song", + "musicBrainzId": "4321", "genres": [ { "name": "rock" diff --git a/server/subsonic/responses/.snapshots/Responses Child with data should match .XML b/server/subsonic/responses/.snapshots/Responses Child with data should match .XML index 1ddcf490f..28f2559b2 100644 --- a/server/subsonic/responses/.snapshots/Responses Child with data should match .XML +++ b/server/subsonic/responses/.snapshots/Responses Child with data should match .XML @@ -1,6 +1,6 @@ - + diff --git a/server/subsonic/responses/.snapshots/Responses Child without data should match .JSON b/server/subsonic/responses/.snapshots/Responses Child without data should match .JSON index 657eca88e..ba8b9fdbc 100644 --- a/server/subsonic/responses/.snapshots/Responses Child without data should match .JSON +++ b/server/subsonic/responses/.snapshots/Responses Child without data should match .JSON @@ -10,10 +10,11 @@ "id": "1", "isDir": false, "isVideo": false, - "mediaType": "", - "musicBrainzId": "", "bpm": 0, "comment": "", + "sortName": "", + "mediaType": "", + "musicBrainzId": "", "genres": [] } ], diff --git a/server/subsonic/responses/.snapshots/Responses Child without data should match .XML b/server/subsonic/responses/.snapshots/Responses Child without data should match .XML index 209894db4..f00a262a8 100644 --- a/server/subsonic/responses/.snapshots/Responses Child without data should match .XML +++ b/server/subsonic/responses/.snapshots/Responses Child without data should match .XML @@ -1,5 +1,5 @@ - + diff --git a/server/subsonic/responses/.snapshots/Responses Directory with data should match .JSON b/server/subsonic/responses/.snapshots/Responses Directory with data should match .JSON index 1496372ef..50515bde9 100644 --- a/server/subsonic/responses/.snapshots/Responses Directory with data should match .JSON +++ b/server/subsonic/responses/.snapshots/Responses Directory with data should match .JSON @@ -11,10 +11,11 @@ "isDir": false, "title": "title", "isVideo": false, - "mediaType": "", - "musicBrainzId": "", "bpm": 0, "comment": "", + "sortName": "", + "mediaType": "", + "musicBrainzId": "", "genres": [] } ], diff --git a/server/subsonic/responses/.snapshots/Responses Directory with data should match .XML b/server/subsonic/responses/.snapshots/Responses Directory with data should match .XML index dd507bea1..ee2083724 100644 --- a/server/subsonic/responses/.snapshots/Responses Directory with data should match .XML +++ b/server/subsonic/responses/.snapshots/Responses Directory with data should match .XML @@ -1,5 +1,5 @@ - + diff --git a/server/subsonic/responses/.snapshots/Responses PlayQueue with data should match .JSON b/server/subsonic/responses/.snapshots/Responses PlayQueue with data should match .JSON index 2d5bb7a35..3d299be63 100644 --- a/server/subsonic/responses/.snapshots/Responses PlayQueue with data should match .JSON +++ b/server/subsonic/responses/.snapshots/Responses PlayQueue with data should match .JSON @@ -11,10 +11,11 @@ "isDir": false, "title": "title", "isVideo": false, - "mediaType": "", - "musicBrainzId": "", "bpm": 0, "comment": "", + "sortName": "", + "mediaType": "", + "musicBrainzId": "", "genres": [] } ], diff --git a/server/subsonic/responses/.snapshots/Responses PlayQueue with data should match .XML b/server/subsonic/responses/.snapshots/Responses PlayQueue with data should match .XML index 49cb2416c..0b9211576 100644 --- a/server/subsonic/responses/.snapshots/Responses PlayQueue with data should match .XML +++ b/server/subsonic/responses/.snapshots/Responses PlayQueue with data should match .XML @@ -1,5 +1,5 @@ - + diff --git a/server/subsonic/responses/.snapshots/Responses Shares with data should match .JSON b/server/subsonic/responses/.snapshots/Responses Shares with data should match .JSON index 71caff2ae..8fa03c3b3 100644 --- a/server/subsonic/responses/.snapshots/Responses Shares with data should match .JSON +++ b/server/subsonic/responses/.snapshots/Responses Shares with data should match .JSON @@ -16,10 +16,11 @@ "artist": "artist", "duration": 120, "isVideo": false, - "mediaType": "", - "musicBrainzId": "", "bpm": 0, "comment": "", + "sortName": "", + "mediaType": "", + "musicBrainzId": "", "genres": [] }, { @@ -30,10 +31,11 @@ "artist": "artist", "duration": 300, "isVideo": false, - "mediaType": "", - "musicBrainzId": "", "bpm": 0, "comment": "", + "sortName": "", + "mediaType": "", + "musicBrainzId": "", "genres": [] } ], diff --git a/server/subsonic/responses/.snapshots/Responses Shares with data should match .XML b/server/subsonic/responses/.snapshots/Responses Shares with data should match .XML index c85d8c0ce..18a2b6ff4 100644 --- a/server/subsonic/responses/.snapshots/Responses Shares with data should match .XML +++ b/server/subsonic/responses/.snapshots/Responses Shares with data should match .XML @@ -1,8 +1,8 @@ - - + + diff --git a/server/subsonic/responses/.snapshots/Responses SimilarSongs with data should match .JSON b/server/subsonic/responses/.snapshots/Responses SimilarSongs with data should match .JSON index 85b979687..51951b04e 100644 --- a/server/subsonic/responses/.snapshots/Responses SimilarSongs with data should match .JSON +++ b/server/subsonic/responses/.snapshots/Responses SimilarSongs with data should match .JSON @@ -11,10 +11,11 @@ "isDir": false, "title": "title", "isVideo": false, - "mediaType": "", - "musicBrainzId": "", "bpm": 0, "comment": "", + "sortName": "", + "mediaType": "", + "musicBrainzId": "", "genres": [] } ] diff --git a/server/subsonic/responses/.snapshots/Responses SimilarSongs with data should match .XML b/server/subsonic/responses/.snapshots/Responses SimilarSongs with data should match .XML index a48b660dc..9ef47632f 100644 --- a/server/subsonic/responses/.snapshots/Responses SimilarSongs with data should match .XML +++ b/server/subsonic/responses/.snapshots/Responses SimilarSongs with data should match .XML @@ -1,5 +1,5 @@ - + diff --git a/server/subsonic/responses/.snapshots/Responses SimilarSongs2 with data should match .JSON b/server/subsonic/responses/.snapshots/Responses SimilarSongs2 with data should match .JSON index deaada7db..b4cb7aced 100644 --- a/server/subsonic/responses/.snapshots/Responses SimilarSongs2 with data should match .JSON +++ b/server/subsonic/responses/.snapshots/Responses SimilarSongs2 with data should match .JSON @@ -11,10 +11,11 @@ "isDir": false, "title": "title", "isVideo": false, - "mediaType": "", - "musicBrainzId": "", "bpm": 0, "comment": "", + "sortName": "", + "mediaType": "", + "musicBrainzId": "", "genres": [] } ] diff --git a/server/subsonic/responses/.snapshots/Responses SimilarSongs2 with data should match .XML b/server/subsonic/responses/.snapshots/Responses SimilarSongs2 with data should match .XML index 003cf1d11..faac7083d 100644 --- a/server/subsonic/responses/.snapshots/Responses SimilarSongs2 with data should match .XML +++ b/server/subsonic/responses/.snapshots/Responses SimilarSongs2 with data should match .XML @@ -1,5 +1,5 @@ - + diff --git a/server/subsonic/responses/.snapshots/Responses TopSongs with data should match .JSON b/server/subsonic/responses/.snapshots/Responses TopSongs with data should match .JSON index b87123262..0c3a9c53f 100644 --- a/server/subsonic/responses/.snapshots/Responses TopSongs with data should match .JSON +++ b/server/subsonic/responses/.snapshots/Responses TopSongs with data should match .JSON @@ -11,10 +11,11 @@ "isDir": false, "title": "title", "isVideo": false, - "mediaType": "", - "musicBrainzId": "", "bpm": 0, "comment": "", + "sortName": "", + "mediaType": "", + "musicBrainzId": "", "genres": [] } ] diff --git a/server/subsonic/responses/.snapshots/Responses TopSongs with data should match .XML b/server/subsonic/responses/.snapshots/Responses TopSongs with data should match .XML index 88013f911..1daf29044 100644 --- a/server/subsonic/responses/.snapshots/Responses TopSongs with data should match .XML +++ b/server/subsonic/responses/.snapshots/Responses TopSongs with data should match .XML @@ -1,5 +1,5 @@ - + diff --git a/server/subsonic/responses/responses.go b/server/subsonic/responses/responses.go index 3e88d1ae2..6c74936d1 100644 --- a/server/subsonic/responses/responses.go +++ b/server/subsonic/responses/responses.go @@ -150,10 +150,11 @@ type Child struct { */ // OpenSubsonic extensions Played *time.Time `xml:"played,attr,omitempty" json:"played,omitempty"` - MediaType MediaType `xml:"mediaType,attr" json:"mediaType"` - MusicBrainzId string `xml:"musicBrainzId,attr" json:"musicBrainzId"` Bpm int32 `xml:"bpm,attr" json:"bpm"` Comment string `xml:"comment,attr" json:"comment"` + SortName string `xml:"sortName,attr" json:"sortName"` + MediaType MediaType `xml:"mediaType,attr" json:"mediaType"` + MusicBrainzId string `xml:"musicBrainzId,attr" json:"musicBrainzId"` Genres ItemGenres `xml:"genres" json:"genres"` } @@ -195,7 +196,10 @@ type ArtistID3 struct { Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"` UserRating int32 `xml:"userRating,attr,omitempty" json:"userRating,omitempty"` ArtistImageUrl string `xml:"artistImageUrl,attr,omitempty" json:"artistImageUrl,omitempty"` - MusicBrainzId string `xml:"musicBrainzId,attr,omitempty" json:"musicBrainzId,omitempty"` + + // OpenSubsonic extensions + MusicBrainzId string `xml:"musicBrainzId,attr,omitempty" json:"musicBrainzId,omitempty"` + SortName string `xml:"sortName,attr,omitempty" json:"sortName,omitempty"` } type AlbumID3 struct { @@ -217,6 +221,8 @@ type AlbumID3 struct { UserRating int32 `xml:"userRating,attr" json:"userRating"` Genres ItemGenres `xml:"genres" json:"genres"` MusicBrainzId string `xml:"musicBrainzId,attr" json:"musicBrainzId"` + IsCompilation bool `xml:"isCompilation,attr" json:"isCompilation"` + SortName string `xml:"sortName,attr" json:"sortName"` } type ArtistWithAlbumsID3 struct { diff --git a/server/subsonic/responses/responses_test.go b/server/subsonic/responses/responses_test.go index 08ff758f8..832214790 100644 --- a/server/subsonic/responses/responses_test.go +++ b/server/subsonic/responses/responses_test.go @@ -171,8 +171,11 @@ var _ = Describe("Responses", func() { Context("with data", func() { BeforeEach(func() { - album := AlbumID3{Id: "1", Name: "album", Artist: "artist", Genre: "rock", - Genres: []ItemGenre{{Name: "rock"}, {Name: "progressive"}}, MusicBrainzId: "1234"} + album := AlbumID3{ + Id: "1", Name: "album", Artist: "artist", Genre: "rock", + Genres: []ItemGenre{{Name: "rock"}, {Name: "progressive"}}, + MusicBrainzId: "1234", IsCompilation: true, SortName: "sorted album", + } t := time.Date(2016, 03, 2, 20, 30, 0, 0, time.UTC) songs := []Child{{ Id: "1", IsDir: true, Title: "title", Album: "album", Artist: "artist", Track: 1, @@ -180,6 +183,7 @@ var _ = Describe("Responses", func() { Suffix: "flac", TranscodedContentType: "audio/mpeg", TranscodedSuffix: "mp3", Duration: 146, BitRate: 320, Starred: &t, Genres: []ItemGenre{{Name: "rock"}, {Name: "progressive"}}, Comment: "a comment", Bpm: 127, MediaType: MediaTypeSong, MusicBrainzId: "4321", + SortName: "sorted song", }} response.AlbumWithSongsID3.AlbumID3 = album response.AlbumWithSongsID3.Song = songs