From 4641dc0b2bbdb0a381b40c1f90519a4f3490b016 Mon Sep 17 00:00:00 2001 From: Deluan Date: Sat, 2 Dec 2023 15:28:44 -0500 Subject: [PATCH] Add ReplayGain to OpenSubsonic API Child response --- server/subsonic/helpers.go | 6 ++++++ .../Responses AlbumList with data should match .JSON | 3 ++- .../Responses AlbumList with data should match .XML | 4 +++- ...nses AlbumWithSongsID3 with data should match .JSON | 10 +++++++++- ...onses AlbumWithSongsID3 with data should match .XML | 1 + .../Responses Bookmarks with data should match .JSON | 3 ++- .../Responses Bookmarks with data should match .XML | 4 +++- .../Responses Child with data should match .JSON | 10 +++++++++- .../Responses Child with data should match .XML | 1 + .../Responses Child without data should match .JSON | 3 ++- .../Responses Child without data should match .XML | 4 +++- .../Responses Directory with data should match .JSON | 3 ++- .../Responses Directory with data should match .XML | 4 +++- .../Responses PlayQueue with data should match .JSON | 3 ++- .../Responses PlayQueue with data should match .XML | 4 +++- .../Responses Shares with data should match .JSON | 6 ++++-- .../Responses Shares with data should match .XML | 8 ++++++-- ...Responses SimilarSongs with data should match .JSON | 3 ++- .../Responses SimilarSongs with data should match .XML | 4 +++- ...esponses SimilarSongs2 with data should match .JSON | 3 ++- ...Responses SimilarSongs2 with data should match .XML | 4 +++- .../Responses TopSongs with data should match .JSON | 3 ++- .../Responses TopSongs with data should match .XML | 4 +++- server/subsonic/responses/responses.go | 10 ++++++++++ server/subsonic/responses/responses_test.go | 5 +++-- 25 files changed, 89 insertions(+), 24 deletions(-) diff --git a/server/subsonic/helpers.go b/server/subsonic/helpers.go index 1d10ea23..0f4ab4a6 100644 --- a/server/subsonic/helpers.go +++ b/server/subsonic/helpers.go @@ -192,6 +192,12 @@ func childFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Child child.Bpm = int32(mf.Bpm) child.MediaType = responses.MediaTypeSong child.MusicBrainzId = mf.MbzRecordingID + child.ReplayGain = responses.ReplayGain{ + TrackGain: mf.RGTrackGain, + AlbumGain: mf.RGAlbumGain, + TrackPeak: mf.RGTrackPeak, + AlbumPeak: mf.RGAlbumPeak, + } 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 a2dd3a7e..2d3bc3b7 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 @@ -16,7 +16,8 @@ "sortName": "", "mediaType": "", "musicBrainzId": "", - "genres": [] + "genres": [], + "replayGain": {} } ] } 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 549d7a17..8787b423 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,7 @@ - + + + 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 6a6d74e6..da546b70 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 @@ -53,7 +53,15 @@ { "name": "progressive" } - ] + ], + "replayGain": { + "trackGain": 1, + "albumGain": 2, + "trackPeak": 3, + "albumPeak": 4, + "baseGain": 5, + "fallbackGain": 6 + } } ] } 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 b329443e..53539358 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 @@ -5,6 +5,7 @@ + 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 8f0ac4f9..3edf0cfd 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 @@ -17,7 +17,8 @@ "sortName": "", "mediaType": "", "musicBrainzId": "", - "genres": [] + "genres": [], + "replayGain": {} }, "position": 123, "username": "user2", 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 f3bfe411..db7c6710 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,9 @@ - + + + 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 9c169f3b..8abef4a6 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 @@ -37,7 +37,15 @@ { "name": "progressive" } - ] + ], + "replayGain": { + "trackGain": 1, + "albumGain": 2, + "trackPeak": 3, + "albumPeak": 4, + "baseGain": 5, + "fallbackGain": 6 + } } ], "id": "1", 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 28f2559b..fe858081 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 @@ -3,6 +3,7 @@ + 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 ba8b9fdb..57cf62d3 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 @@ -15,7 +15,8 @@ "sortName": "", "mediaType": "", "musicBrainzId": "", - "genres": [] + "genres": [], + "replayGain": {} } ], "id": "", 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 f00a262a..aa163689 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,7 @@ - + + + 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 50515bde..6d16805c 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 @@ -16,7 +16,8 @@ "sortName": "", "mediaType": "", "musicBrainzId": "", - "genres": [] + "genres": [], + "replayGain": {} } ], "id": "1", 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 ee208372..11c9b381 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,7 @@ - + + + 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 3d299be6..42ea7de5 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 @@ -16,7 +16,8 @@ "sortName": "", "mediaType": "", "musicBrainzId": "", - "genres": [] + "genres": [], + "replayGain": {} } ], "current": "111", 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 0b921157..c37f6169 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,7 @@ - + + + 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 8fa03c3b..34af86c2 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 @@ -21,7 +21,8 @@ "sortName": "", "mediaType": "", "musicBrainzId": "", - "genres": [] + "genres": [], + "replayGain": {} }, { "id": "2", @@ -36,7 +37,8 @@ "sortName": "", "mediaType": "", "musicBrainzId": "", - "genres": [] + "genres": [], + "replayGain": {} } ], "id": "ABC123", 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 18a2b6ff..d8863b6d 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,12 @@ - - + + + + + + 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 51951b04..7a42f091 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 @@ -16,7 +16,8 @@ "sortName": "", "mediaType": "", "musicBrainzId": "", - "genres": [] + "genres": [], + "replayGain": {} } ] } 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 9ef47632..78c41a77 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,7 @@ - + + + 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 b4cb7ace..74b6c232 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 @@ -16,7 +16,8 @@ "sortName": "", "mediaType": "", "musicBrainzId": "", - "genres": [] + "genres": [], + "replayGain": {} } ] } 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 faac7083..bf98df70 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,7 @@ - + + + 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 0c3a9c53..226b4ab1 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 @@ -16,7 +16,8 @@ "sortName": "", "mediaType": "", "musicBrainzId": "", - "genres": [] + "genres": [], + "replayGain": {} } ] } 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 1daf2904..3a597798 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,7 @@ - + + + diff --git a/server/subsonic/responses/responses.go b/server/subsonic/responses/responses.go index 6c74936d..04bac482 100644 --- a/server/subsonic/responses/responses.go +++ b/server/subsonic/responses/responses.go @@ -156,6 +156,7 @@ type Child struct { MediaType MediaType `xml:"mediaType,attr" json:"mediaType"` MusicBrainzId string `xml:"musicBrainzId,attr" json:"musicBrainzId"` Genres ItemGenres `xml:"genres" json:"genres"` + ReplayGain ReplayGain `xml:"replayGain" json:"replayGain"` } type Songs struct { @@ -465,3 +466,12 @@ func (i ItemGenres) MarshalJSON() ([]byte, error) { a := (Alias)(i) return json.Marshal(a) } + +type ReplayGain struct { + TrackGain float64 `xml:"trackGain,omitempty,attr" json:"trackGain,omitempty"` + AlbumGain float64 `xml:"albumGain,omitempty,attr" json:"albumGain,omitempty"` + TrackPeak float64 `xml:"trackPeak,omitempty,attr" json:"trackPeak,omitempty"` + AlbumPeak float64 `xml:"albumPeak,omitempty,attr" json:"albumPeak,omitempty"` + BaseGain float64 `xml:"baseGain,omitempty,attr" json:"baseGain,omitempty"` + FallbackGain float64 `xml:"fallbackGain,omitempty,attr" json:"fallbackGain,omitempty"` +} diff --git a/server/subsonic/responses/responses_test.go b/server/subsonic/responses/responses_test.go index 83221479..23f1abaf 100644 --- a/server/subsonic/responses/responses_test.go +++ b/server/subsonic/responses/responses_test.go @@ -143,6 +143,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", + ReplayGain: ReplayGain{TrackGain: 1, AlbumGain: 2, TrackPeak: 3, AlbumPeak: 4, BaseGain: 5, FallbackGain: 6}, } response.Directory.Child = child }) @@ -182,8 +183,8 @@ var _ = Describe("Responses", func() { Year: 1985, Genre: "Rock", CoverArt: "1", Size: 8421341, ContentType: "audio/flac", 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", + Comment: "a comment", Bpm: 127, MediaType: MediaTypeSong, MusicBrainzId: "4321", SortName: "sorted song", + ReplayGain: ReplayGain{TrackGain: 1, AlbumGain: 2, TrackPeak: 3, AlbumPeak: 4, BaseGain: 5, FallbackGain: 6}, }} response.AlbumWithSongsID3.AlbumID3 = album response.AlbumWithSongsID3.Song = songs