diff --git a/db/model.go b/db/model.go index 7268598..e3510b8 100644 --- a/db/model.go +++ b/db/model.go @@ -52,7 +52,8 @@ type Artist struct { AlbumCount int `sql:"-"` ArtistStar *ArtistStar ArtistRating *ArtistRating - AverageRating float64 `sql:"default: null"` + AverageRating float64 `sql:"default: null"` + Info *ArtistInfo `gorm:"foreignkey:id"` } func (a *Artist) SID() *specid.ID { diff --git a/server/ctrlsubsonic/handlers_by_tags.go b/server/ctrlsubsonic/handlers_by_tags.go index df56141..8b4e51a 100644 --- a/server/ctrlsubsonic/handlers_by_tags.go +++ b/server/ctrlsubsonic/handlers_by_tags.go @@ -75,6 +75,7 @@ func (c *Controller) ServeGetArtist(r *http.Request) *spec.Response { }). Preload("Albums.Artists"). Preload("Albums.Genres"). + Preload("Info"). Preload("ArtistStar", "user_id=?", user.ID). Preload("ArtistRating", "user_id=?", user.ID). First(artist, id.Value) @@ -228,6 +229,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response { Joins("JOIN albums ON albums.id=album_artists.album_id"). Preload("ArtistStar", "user_id=?", user.ID). Preload("ArtistRating", "user_id=?", user.ID). + Preload("Info"). Offset(params.GetOrInt("artistOffset", 0)). Limit(params.GetOrInt("artistCount", 20)) if m := getMusicFolder(c.MusicPaths, params); m != "" { @@ -357,22 +359,23 @@ func (c *Controller) ServeGetArtistInfoTwo(r *http.Request) *spec.Response { Joins("LEFT JOIN album_artists ON album_artists.artist_id=artists.id"). Joins("LEFT JOIN albums ON albums.id=album_artists.album_id"). Group("artists.id"). + Preload("Info"). Find(&artist). Error if errors.Is(err, gorm.ErrRecordNotFound) && !inclNotPresent { continue } - artistID := &specid.ID{} - if artist.ID != 0 { - // we don't always have a match if `inclNotPresent` - artistID = artist.SID() + + if artist.ID == 0 { + // add a very limited artist, since we don't have everything with `inclNotPresent` + sub.ArtistInfoTwo.Similar = append(sub.ArtistInfoTwo.Similar, &spec.Artist{ + ID: &specid.ID{}, + Name: similarName, + }) + continue } - sub.ArtistInfoTwo.SimilarArtist = append(sub.ArtistInfoTwo.SimilarArtist, &spec.SimilarArtist{ - ID: artistID, - Name: similarName, - CoverArt: artistID, - AlbumCount: artist.AlbumCount, - }) + + sub.ArtistInfoTwo.Similar = append(sub.ArtistInfoTwo.Similar, spec.NewArtistByTags(&artist)) } return sub @@ -452,6 +455,7 @@ func (c *Controller) ServeGetStarredTwo(r *http.Request) *spec.Response { Joins("JOIN albums ON albums.id=album_artists.album_id"). Preload("ArtistStar", "user_id=?", user.ID). Preload("ArtistRating", "user_id=?", user.ID). + Preload("Info"). Group("artists.id") if m := getMusicFolder(c.MusicPaths, params); m != "" { q = q.Where("albums.root_dir=?", m) diff --git a/server/ctrlsubsonic/spec/construct_by_tags.go b/server/ctrlsubsonic/spec/construct_by_tags.go index c2f48de..fa9efac 100644 --- a/server/ctrlsubsonic/spec/construct_by_tags.go +++ b/server/ctrlsubsonic/spec/construct_by_tags.go @@ -99,7 +99,9 @@ func NewArtistByTags(a *db.Artist) *Artist { Name: a.Name, AlbumCount: a.AlbumCount, AverageRating: formatRating(a.AverageRating), - CoverID: a.SID(), + } + if a.Info != nil && a.Info.ImageURL != "" { + r.CoverID = a.SID() } if a.ArtistStar != nil { r.Starred = &a.ArtistStar.StarDate diff --git a/server/ctrlsubsonic/spec/spec.go b/server/ctrlsubsonic/spec/spec.go index 3a130cb..6a500c8 100644 --- a/server/ctrlsubsonic/spec/spec.go +++ b/server/ctrlsubsonic/spec/spec.go @@ -284,22 +284,15 @@ type Playlist struct { List []*TrackChild `xml:"entry,omitempty" json:"entry,omitempty"` } -type SimilarArtist struct { - ID *specid.ID `xml:"id,attr" json:"id"` - Name string `xml:"name,attr" json:"name"` - CoverArt *specid.ID `xml:"coverArt,attr" json:"coverArt"` - AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"` -} - type ArtistInfo struct { - Biography string `xml:"biography" json:"biography"` - MusicBrainzID string `xml:"musicBrainzId" json:"musicBrainzId"` - LastFMURL string `xml:"lastFmUrl" json:"lastFmUrl"` - SmallImageURL string `xml:"smallImageUrl" json:"smallImageUrl"` - MediumImageURL string `xml:"mediumImageUrl" json:"mediumImageUrl"` - LargeImageURL string `xml:"largeImageUrl" json:"largeImageUrl"` - ArtistImageURL string `xml:"artistImageUrl" json:"artistImageUrl"` // not sure where this comes from but other clients seem to expect it - SimilarArtist []*SimilarArtist `xml:"similarArtist,omitempty" json:"similarArtist,omitempty"` + Biography string `xml:"biography" json:"biography"` + MusicBrainzID string `xml:"musicBrainzId" json:"musicBrainzId"` + LastFMURL string `xml:"lastFmUrl" json:"lastFmUrl"` + SmallImageURL string `xml:"smallImageUrl" json:"smallImageUrl"` + MediumImageURL string `xml:"mediumImageUrl" json:"mediumImageUrl"` + LargeImageURL string `xml:"largeImageUrl" json:"largeImageUrl"` + ArtistImageURL string `xml:"artistImageUrl" json:"artistImageUrl"` // not sure where this comes from but other clients seem to expect it + Similar []*Artist `xml:"similarArtist,omitempty" json:"similarArtist,omitempty"` } type Genres struct { diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_random b/server/ctrlsubsonic/testdata/test_get_album_list_random index aff162c..150e389 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_random +++ b/server/ctrlsubsonic/testdata/test_get_album_list_random @@ -6,58 +6,6 @@ "serverVersion": "", "albumList": { "album": [ - { - "id": "al-8", - "coverArt": "al-8", - "artist": "artist-1", - "created": "2019-11-30T00:00:00Z", - "title": "album-1", - "album": "", - "parent": "al-6", - "isDir": true, - "name": "", - "songCount": 3, - "duration": 300 - }, - { - "id": "al-7", - "coverArt": "al-7", - "artist": "artist-1", - "created": "2019-11-30T00:00:00Z", - "title": "album-0", - "album": "", - "parent": "al-6", - "isDir": true, - "name": "", - "songCount": 3, - "duration": 300 - }, - { - "id": "al-9", - "coverArt": "al-9", - "artist": "artist-1", - "created": "2019-11-30T00:00:00Z", - "title": "album-2", - "album": "", - "parent": "al-6", - "isDir": true, - "name": "", - "songCount": 3, - "duration": 300 - }, - { - "id": "al-4", - "coverArt": "al-4", - "artist": "artist-0", - "created": "2019-11-30T00:00:00Z", - "title": "album-1", - "album": "", - "parent": "al-2", - "isDir": true, - "name": "", - "songCount": 3, - "duration": 300 - }, { "id": "al-3", "coverArt": "al-3", @@ -71,32 +19,6 @@ "songCount": 3, "duration": 300 }, - { - "id": "al-11", - "coverArt": "al-11", - "artist": "artist-2", - "created": "2019-11-30T00:00:00Z", - "title": "album-0", - "album": "", - "parent": "al-10", - "isDir": true, - "name": "", - "songCount": 3, - "duration": 300 - }, - { - "id": "al-5", - "coverArt": "al-5", - "artist": "artist-0", - "created": "2019-11-30T00:00:00Z", - "title": "album-2", - "album": "", - "parent": "al-2", - "isDir": true, - "name": "", - "songCount": 3, - "duration": 300 - }, { "id": "al-13", "coverArt": "al-13", @@ -110,6 +32,32 @@ "songCount": 3, "duration": 300 }, + { + "id": "al-7", + "coverArt": "al-7", + "artist": "artist-1", + "created": "2019-11-30T00:00:00Z", + "title": "album-0", + "album": "", + "parent": "al-6", + "isDir": true, + "name": "", + "songCount": 3, + "duration": 300 + }, + { + "id": "al-5", + "coverArt": "al-5", + "artist": "artist-0", + "created": "2019-11-30T00:00:00Z", + "title": "album-2", + "album": "", + "parent": "al-2", + "isDir": true, + "name": "", + "songCount": 3, + "duration": 300 + }, { "id": "al-12", "coverArt": "al-12", @@ -122,6 +70,58 @@ "name": "", "songCount": 3, "duration": 300 + }, + { + "id": "al-8", + "coverArt": "al-8", + "artist": "artist-1", + "created": "2019-11-30T00:00:00Z", + "title": "album-1", + "album": "", + "parent": "al-6", + "isDir": true, + "name": "", + "songCount": 3, + "duration": 300 + }, + { + "id": "al-9", + "coverArt": "al-9", + "artist": "artist-1", + "created": "2019-11-30T00:00:00Z", + "title": "album-2", + "album": "", + "parent": "al-6", + "isDir": true, + "name": "", + "songCount": 3, + "duration": 300 + }, + { + "id": "al-11", + "coverArt": "al-11", + "artist": "artist-2", + "created": "2019-11-30T00:00:00Z", + "title": "album-0", + "album": "", + "parent": "al-10", + "isDir": true, + "name": "", + "songCount": 3, + "duration": 300 + }, + { + "id": "al-4", + "coverArt": "al-4", + "artist": "artist-0", + "created": "2019-11-30T00:00:00Z", + "title": "album-1", + "album": "", + "parent": "al-2", + "isDir": true, + "name": "", + "songCount": 3, + "duration": 300 } ] } diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_random b/server/ctrlsubsonic/testdata/test_get_album_list_two_random index e6e1378..49eea7e 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_random +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_random @@ -6,34 +6,6 @@ "serverVersion": "", "albumList2": { "album": [ - { - "id": "al-3", - "coverArt": "al-3", - "artistId": "ar-1", - "artist": "artist-0", - "artists": [{ "id": "ar-1", "name": "artist-0" }], - "created": "2019-11-30T00:00:00Z", - "title": "", - "album": "", - "name": "album-0", - "songCount": 3, - "duration": 300, - "year": 2021 - }, - { - "id": "al-7", - "coverArt": "al-7", - "artistId": "ar-2", - "artist": "artist-1", - "artists": [{ "id": "ar-2", "name": "artist-1" }], - "created": "2019-11-30T00:00:00Z", - "title": "", - "album": "", - "name": "album-0", - "songCount": 3, - "duration": 300, - "year": 2021 - }, { "id": "al-8", "coverArt": "al-8", @@ -63,29 +35,29 @@ "year": 2021 }, { - "id": "al-12", - "coverArt": "al-12", - "artistId": "ar-3", - "artist": "artist-2", - "artists": [{ "id": "ar-3", "name": "artist-2" }], + "id": "al-5", + "coverArt": "al-5", + "artistId": "ar-1", + "artist": "artist-0", + "artists": [{ "id": "ar-1", "name": "artist-0" }], "created": "2019-11-30T00:00:00Z", "title": "", "album": "", - "name": "album-1", + "name": "album-2", "songCount": 3, "duration": 300, "year": 2021 }, { - "id": "al-13", - "coverArt": "al-13", - "artistId": "ar-3", - "artist": "artist-2", - "artists": [{ "id": "ar-3", "name": "artist-2" }], + "id": "al-3", + "coverArt": "al-3", + "artistId": "ar-1", + "artist": "artist-0", + "artists": [{ "id": "ar-1", "name": "artist-0" }], "created": "2019-11-30T00:00:00Z", "title": "", "album": "", - "name": "album-2", + "name": "album-0", "songCount": 3, "duration": 300, "year": 2021 @@ -105,11 +77,25 @@ "year": 2021 }, { - "id": "al-5", - "coverArt": "al-5", - "artistId": "ar-1", - "artist": "artist-0", - "artists": [{ "id": "ar-1", "name": "artist-0" }], + "id": "al-7", + "coverArt": "al-7", + "artistId": "ar-2", + "artist": "artist-1", + "artists": [{ "id": "ar-2", "name": "artist-1" }], + "created": "2019-11-30T00:00:00Z", + "title": "", + "album": "", + "name": "album-0", + "songCount": 3, + "duration": 300, + "year": 2021 + }, + { + "id": "al-13", + "coverArt": "al-13", + "artistId": "ar-3", + "artist": "artist-2", + "artists": [{ "id": "ar-3", "name": "artist-2" }], "created": "2019-11-30T00:00:00Z", "title": "", "album": "", @@ -131,6 +117,20 @@ "songCount": 3, "duration": 300, "year": 2021 + }, + { + "id": "al-12", + "coverArt": "al-12", + "artistId": "ar-3", + "artist": "artist-2", + "artists": [{ "id": "ar-3", "name": "artist-2" }], + "created": "2019-11-30T00:00:00Z", + "title": "", + "album": "", + "name": "album-1", + "songCount": 3, + "duration": 300, + "year": 2021 } ] } diff --git a/server/ctrlsubsonic/testdata/test_get_artist_id_one b/server/ctrlsubsonic/testdata/test_get_artist_id_one index 55f309a..0bc3012 100644 --- a/server/ctrlsubsonic/testdata/test_get_artist_id_one +++ b/server/ctrlsubsonic/testdata/test_get_artist_id_one @@ -7,7 +7,6 @@ "artist": { "id": "ar-1", "name": "artist-0", - "coverArt": "ar-1", "albumCount": 3, "album": [ { diff --git a/server/ctrlsubsonic/testdata/test_get_artist_id_three b/server/ctrlsubsonic/testdata/test_get_artist_id_three index b96328d..7667dde 100644 --- a/server/ctrlsubsonic/testdata/test_get_artist_id_three +++ b/server/ctrlsubsonic/testdata/test_get_artist_id_three @@ -7,7 +7,6 @@ "artist": { "id": "ar-3", "name": "artist-2", - "coverArt": "ar-3", "albumCount": 3, "album": [ { diff --git a/server/ctrlsubsonic/testdata/test_get_artist_id_two b/server/ctrlsubsonic/testdata/test_get_artist_id_two index 33fb4d2..1722eb4 100644 --- a/server/ctrlsubsonic/testdata/test_get_artist_id_two +++ b/server/ctrlsubsonic/testdata/test_get_artist_id_two @@ -7,7 +7,6 @@ "artist": { "id": "ar-2", "name": "artist-1", - "coverArt": "ar-2", "albumCount": 3, "album": [ { diff --git a/server/ctrlsubsonic/testdata/test_get_artists_no_args b/server/ctrlsubsonic/testdata/test_get_artists_no_args index 565e5fd..88cfdfa 100644 --- a/server/ctrlsubsonic/testdata/test_get_artists_no_args +++ b/server/ctrlsubsonic/testdata/test_get_artists_no_args @@ -10,24 +10,9 @@ { "name": "a", "artist": [ - { - "id": "ar-1", - "name": "artist-0", - "coverArt": "ar-1", - "albumCount": 6 - }, - { - "id": "ar-2", - "name": "artist-1", - "coverArt": "ar-2", - "albumCount": 6 - }, - { - "id": "ar-3", - "name": "artist-2", - "coverArt": "ar-3", - "albumCount": 6 - } + { "id": "ar-1", "name": "artist-0", "albumCount": 6 }, + { "id": "ar-2", "name": "artist-1", "albumCount": 6 }, + { "id": "ar-3", "name": "artist-2", "albumCount": 6 } ] } ] diff --git a/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_1 b/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_1 index 1cbbe07..0ee73fa 100644 --- a/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_1 +++ b/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_1 @@ -10,24 +10,9 @@ { "name": "a", "artist": [ - { - "id": "ar-1", - "name": "artist-0", - "coverArt": "ar-1", - "albumCount": 3 - }, - { - "id": "ar-2", - "name": "artist-1", - "coverArt": "ar-2", - "albumCount": 3 - }, - { - "id": "ar-3", - "name": "artist-2", - "coverArt": "ar-3", - "albumCount": 3 - } + { "id": "ar-1", "name": "artist-0", "albumCount": 3 }, + { "id": "ar-2", "name": "artist-1", "albumCount": 3 }, + { "id": "ar-3", "name": "artist-2", "albumCount": 3 } ] } ] diff --git a/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_2 b/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_2 index 1cbbe07..0ee73fa 100644 --- a/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_2 +++ b/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_2 @@ -10,24 +10,9 @@ { "name": "a", "artist": [ - { - "id": "ar-1", - "name": "artist-0", - "coverArt": "ar-1", - "albumCount": 3 - }, - { - "id": "ar-2", - "name": "artist-1", - "coverArt": "ar-2", - "albumCount": 3 - }, - { - "id": "ar-3", - "name": "artist-2", - "coverArt": "ar-3", - "albumCount": 3 - } + { "id": "ar-1", "name": "artist-0", "albumCount": 3 }, + { "id": "ar-2", "name": "artist-1", "albumCount": 3 }, + { "id": "ar-3", "name": "artist-2", "albumCount": 3 } ] } ] diff --git a/server/ctrlsubsonic/testdata/test_search_three_q_art b/server/ctrlsubsonic/testdata/test_search_three_q_art index c4940ce..33a55f6 100644 --- a/server/ctrlsubsonic/testdata/test_search_three_q_art +++ b/server/ctrlsubsonic/testdata/test_search_three_q_art @@ -6,24 +6,9 @@ "serverVersion": "", "searchResult3": { "artist": [ - { - "id": "ar-1", - "name": "artist-0", - "coverArt": "ar-1", - "albumCount": 3 - }, - { - "id": "ar-2", - "name": "artist-1", - "coverArt": "ar-2", - "albumCount": 3 - }, - { - "id": "ar-3", - "name": "artist-2", - "coverArt": "ar-3", - "albumCount": 3 - } + { "id": "ar-1", "name": "artist-0", "albumCount": 3 }, + { "id": "ar-2", "name": "artist-1", "albumCount": 3 }, + { "id": "ar-3", "name": "artist-2", "albumCount": 3 } ] } }