diff --git a/model/lyrics.go b/model/lyrics.go index 356e09624..c7f872c59 100644 --- a/model/lyrics.go +++ b/model/lyrics.go @@ -10,17 +10,17 @@ import ( ) type Line struct { - Start *int64 `structs:"start,omitempty" xml:"start,attr,omitempty" json:"start,omitempty"` - Value string `structs:"value" xml:"value" json:"value"` + Start *int64 `structs:"start,omitempty" json:"start,omitempty"` + Value string `structs:"value" json:"value"` } type Lyric struct { - DisplayArtist string `structs:"displayArtist,omitempty" xml:"displayArtist,attr,omitempty" json:"displayArtist,omitempty"` - DisplayTitle string `structs:"displayTitle,omitempty" xml:"displayTitle,attr,omitempty" json:"displayTitle,omitempty"` - Lang string `structs:"lang" xml:"lang,attr" json:"lang"` - Line []Line `structs:"line" xml:"line" json:"line"` - Offset *int64 `structs:"offset,omitempty" xml:"offset,attr,omitempty" json:"offset,omitempty"` - Synced bool `structs:"synced" xml:"synced,attr" json:"synced"` + DisplayArtist string `structs:"displayArtist,omitempty" json:"displayArtist,omitempty"` + DisplayTitle string `structs:"displayTitle,omitempty" json:"displayTitle,omitempty"` + Lang string `structs:"lang" json:"lang"` + Line []Line `structs:"line" json:"line"` + Offset *int64 `structs:"offset,omitempty" json:"offset,omitempty"` + Synced bool `structs:"synced" json:"synced"` } // support the standard [mm:ss.mm], as well as [hh:*] and [*.mmm] diff --git a/server/subsonic/helpers.go b/server/subsonic/helpers.go index 87ace90b9..c5beea9e5 100644 --- a/server/subsonic/helpers.go +++ b/server/subsonic/helpers.go @@ -320,3 +320,38 @@ func buildAlbumID3(ctx context.Context, album model.Album) responses.AlbumID3 { dir.SortName = album.SortAlbumName return dir } + +func buildStructuredLyric(lyric model.Lyric) responses.StructuredLyric { + lines := make([]responses.Line, len(lyric.Line)) + + for i, line := range lyric.Line { + lines[i] = responses.Line{ + Start: line.Start, + Value: line.Value, + } + } + + structured := responses.StructuredLyric{ + DisplayArtist: lyric.DisplayArtist, + DisplayTitle: lyric.DisplayTitle, + Lang: lyric.Lang, + Line: lines, + Offset: lyric.Offset, + Synced: lyric.Synced, + } + + return structured +} + +func buildStructuredLyrics(lyrics model.Lyrics) *responses.LyricsList { + lyricList := make(responses.StructuredLyrics, len(lyrics)) + + for i, lyric := range lyrics { + lyricList[i] = buildStructuredLyric(lyric) + } + + res := &responses.LyricsList{ + StructuredLyrics: lyricList, + } + return res +} diff --git a/server/subsonic/media_retrieval.go b/server/subsonic/media_retrieval.go index 51e6bdb7b..83b664f58 100644 --- a/server/subsonic/media_retrieval.go +++ b/server/subsonic/media_retrieval.go @@ -139,10 +139,7 @@ func (api *Router) GetLyricsBySongId(r *http.Request) (*responses.Subsonic, erro } response := newResponse() - allLyrics := responses.LyricsList{ - StructuredLyrics: lyrics, - } - response.LyricsList = &allLyrics + response.LyricsList = buildStructuredLyrics(lyrics) return response, nil } diff --git a/server/subsonic/media_retrieval_test.go b/server/subsonic/media_retrieval_test.go index 215bdd226..4704fd8d5 100644 --- a/server/subsonic/media_retrieval_test.go +++ b/server/subsonic/media_retrieval_test.go @@ -169,11 +169,11 @@ var _ = Describe("MediaRetrievalController", func() { response, err := router.GetLyricsBySongId(r) Expect(err).ToNot(HaveOccurred()) compareResponses(response.LyricsList, responses.LyricsList{ - StructuredLyrics: model.Lyrics{ + StructuredLyrics: responses.StructuredLyrics{ { Lang: "eng", Synced: true, - Line: []model.Line{ + Line: []responses.Line{ { Start: ×[0], Value: "We're no strangers to love", @@ -187,7 +187,7 @@ var _ = Describe("MediaRetrievalController", func() { { Lang: "xxx", Synced: false, - Line: []model.Line{ + Line: []responses.Line{ { Value: "We're no strangers to love", }, @@ -221,13 +221,13 @@ var _ = Describe("MediaRetrievalController", func() { offset := int64(-100) compareResponses(response.LyricsList, responses.LyricsList{ - StructuredLyrics: model.Lyrics{ + StructuredLyrics: responses.StructuredLyrics{ { DisplayArtist: "Rick Astley", DisplayTitle: "That one song", Lang: "eng", Synced: true, - Line: []model.Line{ + Line: []responses.Line{ { Start: ×[0], Value: "We're no strangers to love", diff --git a/server/subsonic/responses/responses.go b/server/subsonic/responses/responses.go index 2b696ae24..ec48b4026 100644 --- a/server/subsonic/responses/responses.go +++ b/server/subsonic/responses/responses.go @@ -4,8 +4,6 @@ import ( "encoding/json" "encoding/xml" "time" - - "github.com/navidrome/navidrome/model" ) type Subsonic struct { @@ -448,8 +446,24 @@ type JukeboxPlaylist struct { JukeboxStatus Entry []Child `xml:"entry,omitempty" json:"entry,omitempty"` } + +type Line struct { + Start *int64 `xml:"start,attr,omitempty" json:"start,omitempty"` + Value string `xml:"value" json:"value"` +} + +type StructuredLyric struct { + DisplayArtist string `xml:"displayArtist,attr,omitempty" json:"displayArtist,omitempty"` + DisplayTitle string `xml:"displayTitle,attr,omitempty" json:"displayTitle,omitempty"` + Lang string `xml:"lang,attr" json:"lang"` + Line []Line `xml:"line" json:"line"` + Offset *int64 `xml:"offset,attr,omitempty" json:"offset,omitempty"` + Synced bool `xml:"synced,attr" json:"synced"` +} + +type StructuredLyrics []StructuredLyric type LyricsList struct { - StructuredLyrics model.Lyrics `xml:"structuredLyrics,omitempty" json:"structuredLyrics,omitempty"` + StructuredLyrics []StructuredLyric `xml:"structuredLyrics,omitempty" json:"structuredLyrics,omitempty"` } type OpenSubsonicExtension struct { diff --git a/server/subsonic/responses/responses_test.go b/server/subsonic/responses/responses_test.go index 54e93e38e..fb218b8e8 100644 --- a/server/subsonic/responses/responses_test.go +++ b/server/subsonic/responses/responses_test.go @@ -11,7 +11,6 @@ import ( "time" "github.com/navidrome/navidrome/consts" - "github.com/navidrome/navidrome/model" . "github.com/navidrome/navidrome/server/subsonic/responses" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -815,11 +814,11 @@ var _ = Describe("Responses", func() { BeforeEach(func() { times := []int64{int64(18800), int64(22801)} - response.LyricsList.StructuredLyrics = model.Lyrics{ + response.LyricsList.StructuredLyrics = StructuredLyrics{ { Lang: "eng", Synced: true, - Line: []model.Line{ + Line: []Line{ { Start: ×[0], Value: "We're no strangers to love", @@ -833,7 +832,7 @@ var _ = Describe("Responses", func() { { Lang: "xxx", Synced: false, - Line: []model.Line{ + Line: []Line{ { Value: "We're no strangers to love", },