From 7c170a68c2c66d021680bb9caad9da8da62bcf69 Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 21 Feb 2020 17:55:30 +0000 Subject: [PATCH] add more omitempty changes --- server/ctrlsubsonic/spec/construct_by_tags.go | 10 ++ server/ctrlsubsonic/spec/spec.go | 12 +-- .../testdata/test_get_album_list_random | 90 ++++++++-------- .../testdata/test_get_album_list_two_random | 102 +++++++++--------- 4 files changed, 112 insertions(+), 102 deletions(-) diff --git a/server/ctrlsubsonic/spec/construct_by_tags.go b/server/ctrlsubsonic/spec/construct_by_tags.go index 71b5a3c..b42c27b 100644 --- a/server/ctrlsubsonic/spec/construct_by_tags.go +++ b/server/ctrlsubsonic/spec/construct_by_tags.go @@ -52,6 +52,16 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild { if album.TagArtist != nil { ret.ArtistID = album.TagArtist.ID } + // replace tags that we're present + if ret.Title == "" { + ret.Title = "" + } + if ret.Artist == "" { + ret.Artist = "<artist>" + } + if ret.Album == "" { + ret.Album = "<album>" + } return ret } diff --git a/server/ctrlsubsonic/spec/spec.go b/server/ctrlsubsonic/spec/spec.go index fe87d0e..cdd8bfe 100644 --- a/server/ctrlsubsonic/spec/spec.go +++ b/server/ctrlsubsonic/spec/spec.go @@ -134,12 +134,12 @@ type TrackChild struct { } type Artists struct { - List []*Index `xml:"index,omitempty" json:"index"` + List []*Index `xml:"index" json:"index"` } type Artist struct { ID int `xml:"id,attr,omitempty" json:"id,string"` - Name string `xml:"name,attr,omitempty" json:"name"` + Name string `xml:"name,attr" json:"name"` CoverID int `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty,string"` AlbumCount int `xml:"albumCount,attr" json:"albumCount"` Albums []*Album `xml:"album,omitempty" json:"album,omitempty"` @@ -147,12 +147,12 @@ type Artist struct { type Indexes struct { LastModified int `xml:"lastModified,attr,omitempty" json:"lastModified"` - Index []*Index `xml:"index,omitempty" json:"index"` + Index []*Index `xml:"index" json:"index"` } type Index struct { Name string `xml:"name,attr,omitempty" json:"name"` - Artists []*Artist `xml:"artist,omitempty" json:"artist"` + Artists []*Artist `xml:"artist" json:"artist"` } type Directory struct { @@ -164,7 +164,7 @@ type Directory struct { } type MusicFolders struct { - List []*MusicFolder `xml:"musicFolder,omitempty" json:"musicFolder,omitempty"` + List []*MusicFolder `xml:"musicFolder" json:"musicFolder"` } type MusicFolder struct { @@ -224,7 +224,7 @@ type Playlist struct { Created time.Time `xml:"created,attr" json:"created"` Duration string `xml:"duration,attr" json:"duration,omitempty"` Public bool `xml:"public,attr" json:"public,omitempty"` - List []*TrackChild `xml:"entry" json:"entry,omitempty"` + List []*TrackChild `xml:"entry" json:"entry"` } type SimilarArtist struct { diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_random b/server/ctrlsubsonic/testdata/test_get_album_list_random index 69488be..4167582 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_random +++ b/server/ctrlsubsonic/testdata/test_get_album_list_random @@ -6,28 +6,6 @@ "gonicVersion": "v0.7.0", "albumList": { "album": [ - { - "id": "19", - "coverArt": "19", - "artist": "Ten Years After", - "title": "(1967) Ten Years After", - "parent": "18", - "isDir": true, - "songCount": 15, - "duration": 0, - "created": "0001-01-01T00:00:00Z" - }, - { - "id": "8", - "coverArt": "8", - "artist": "13th Floor Lowervators", - "title": "(1967) Easter Nowhere", - "parent": "7", - "isDir": true, - "songCount": 10, - "duration": 0, - "created": "0001-01-01T00:00:00Z" - }, { "id": "9", "coverArt": "9", @@ -39,6 +17,17 @@ "duration": 0, "created": "0001-01-01T00:00:00Z" }, + { + "id": "19", + "coverArt": "19", + "artist": "Ten Years After", + "title": "(1967) Ten Years After", + "parent": "18", + "isDir": true, + "songCount": 15, + "duration": 0, + "created": "0001-01-01T00:00:00Z" + }, { "id": "13", "coverArt": "13", @@ -51,23 +40,24 @@ "created": "0001-01-01T00:00:00Z" }, { - "id": "3", - "coverArt": "3", - "artist": "Jah Wobble, The Edge, Holger Czukay", - "title": "(1983) Snake Charmer", - "parent": "2", + "id": "21", + "coverArt": "21", + "artist": "Captain Beefheart", + "title": "(1970) Lick My Decals Off, Bitch", + "parent": "20", "isDir": true, - "songCount": 5, + "songCount": 15, "duration": 0, "created": "0001-01-01T00:00:00Z" }, { - "id": "6", - "artist": "A Certain Ratio", - "title": "(1981) To EachOTHER.", - "parent": "4", + "id": "17", + "coverArt": "17", + "artist": "Swell Maps", + "title": "(1979) A Trip to Marineville", + "parent": "15", "isDir": true, - "songCount": 9, + "songCount": 18, "duration": 0, "created": "0001-01-01T00:00:00Z" }, @@ -83,13 +73,12 @@ "created": "0001-01-01T00:00:00Z" }, { - "id": "21", - "coverArt": "21", - "artist": "Captain Beefheart", - "title": "(1970) Lick My Decals Off, Bitch", - "parent": "20", + "id": "6", + "artist": "A Certain Ratio", + "title": "(1981) To EachOTHER.", + "parent": "4", "isDir": true, - "songCount": 15, + "songCount": 9, "duration": 0, "created": "0001-01-01T00:00:00Z" }, @@ -105,13 +94,24 @@ "created": "0001-01-01T00:00:00Z" }, { - "id": "17", - "coverArt": "17", - "artist": "Swell Maps", - "title": "(1979) A Trip to Marineville", - "parent": "15", + "id": "8", + "coverArt": "8", + "artist": "13th Floor Lowervators", + "title": "(1967) Easter Nowhere", + "parent": "7", "isDir": true, - "songCount": 18, + "songCount": 10, + "duration": 0, + "created": "0001-01-01T00:00:00Z" + }, + { + "id": "3", + "coverArt": "3", + "artist": "Jah Wobble, The Edge, Holger Czukay", + "title": "(1983) Snake Charmer", + "parent": "2", + "isDir": true, + "songCount": 5, "duration": 0, "created": "0001-01-01T00:00:00Z" } diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_random b/server/ctrlsubsonic/testdata/test_get_album_list_two_random index c1a6d1d..1282b0c 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_random +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_random @@ -7,45 +7,14 @@ "albumList2": { "album": [ { - "id": "13", - "coverArt": "13", - "artistId": "4", - "artist": "Anikas", - "name": "Anika", + "id": "6", + "artistId": "2", + "artist": "A Certain Ratio", + "name": "To Each...", "songCount": 9, "duration": 0, "created": "2019-05-23T15:12:02.921473302+01:00" }, - { - "id": "19", - "coverArt": "19", - "artistId": "6", - "artist": "Ten Years After", - "name": "Ten Years After", - "songCount": 15, - "duration": 0, - "created": "2019-04-30T16:48:30+01:00" - }, - { - "id": "5", - "coverArt": "5", - "artistId": "2", - "artist": "A Certain Ratio", - "name": "The Graveyard and the Ballroom", - "songCount": 14, - "duration": 0, - "created": "2019-06-05T17:46:37.675917974+01:00" - }, - { - "id": "17", - "coverArt": "17", - "artistId": "5", - "artist": "Swell Maps", - "name": "A Trip to Marineville", - "songCount": 18, - "duration": 0, - "created": "2019-04-30T16:48:48+01:00" - }, { "id": "3", "coverArt": "3", @@ -56,6 +25,26 @@ "duration": 0, "created": "2019-05-16T22:10:52+01:00" }, + { + "id": "17", + "coverArt": "17", + "artistId": "5", + "artist": "Swell Maps", + "name": "A Trip to Marineville", + "songCount": 18, + "duration": 0, + "created": "2019-04-30T16:48:48+01:00" + }, + { + "id": "5", + "coverArt": "5", + "artistId": "2", + "artist": "A Certain Ratio", + "name": "The Graveyard and the Ballroom", + "songCount": 14, + "duration": 0, + "created": "2019-06-05T17:46:37.675917974+01:00" + }, { "id": "21", "coverArt": "21", @@ -66,6 +55,16 @@ "duration": 0, "created": "2019-06-10T19:26:30.944742894+01:00" }, + { + "id": "13", + "coverArt": "13", + "artistId": "4", + "artist": "Anikas", + "name": "Anika", + "songCount": 9, + "duration": 0, + "created": "2019-05-23T15:12:02.921473302+01:00" + }, { "id": "9", "coverArt": "9", @@ -77,23 +76,14 @@ "created": "2019-06-13T12:57:24.306717554+01:00" }, { - "id": "16", - "coverArt": "16", - "artistId": "5", - "artist": "Swell Maps", - "name": "Jane From Occupied Europe", - "songCount": 16, + "id": "19", + "coverArt": "19", + "artistId": "6", + "artist": "Ten Years After", + "name": "Ten Years After", + "songCount": 15, "duration": 0, - "created": "2019-04-30T16:48:48+01:00" - }, - { - "id": "6", - "artistId": "2", - "artist": "A Certain Ratio", - "name": "To Each...", - "songCount": 9, - "duration": 0, - "created": "2019-05-23T15:12:02.921473302+01:00" + "created": "2019-04-30T16:48:30+01:00" }, { "id": "8", @@ -104,6 +94,16 @@ "songCount": 10, "duration": 0, "created": "2019-06-13T12:57:28.850090338+01:00" + }, + { + "id": "16", + "coverArt": "16", + "artistId": "5", + "artist": "Swell Maps", + "name": "Jane From Occupied Europe", + "songCount": 16, + "duration": 0, + "created": "2019-04-30T16:48:48+01:00" } ] }