diff --git a/server/ctrlsubsonic/handlers_by_tags.go b/server/ctrlsubsonic/handlers_by_tags.go index fd85b86..c580fe1 100644 --- a/server/ctrlsubsonic/handlers_by_tags.go +++ b/server/ctrlsubsonic/handlers_by_tags.go @@ -257,5 +257,31 @@ func (c *Controller) ServeGetArtistInfoTwo(r *http.Request) *spec.Response { sub.ArtistInfoTwo.LargeImageURL = image.Text } } + count := params.GetIntOr("count", 20) + includeNotPresent := params.Get("includeNotPresent") == "true" + for i, similarInfo := range info.Similar.Artists { + if i == count { + break + } + artist = &model.Artist{} + err = c.DB. + Select("*, count(albums.id) as album_count"). + Where("name = ?", similarInfo.Name). + Joins(`LEFT JOIN albums ON artists.id = albums.tag_artist_id`). + Group("artists.id"). + Find(artist). + Error + if gorm.IsRecordNotFoundError(err) && !includeNotPresent { + continue + } + similar := &spec.SimilarArtist{ID: -1} + if artist.ID != 0 { + similar.ID = artist.ID + } + similar.Name = similarInfo.Name + similar.AlbumCount = artist.AlbumCount + sub.ArtistInfoTwo.SimilarArtist = append( + sub.ArtistInfoTwo.SimilarArtist, similar) + } return sub } diff --git a/server/ctrlsubsonic/spec/spec.go b/server/ctrlsubsonic/spec/spec.go index 143e0a4..aa69704 100644 --- a/server/ctrlsubsonic/spec/spec.go +++ b/server/ctrlsubsonic/spec/spec.go @@ -228,18 +228,19 @@ type Playlist struct { } type SimilarArtist struct { - ID int `xml:"id,attr" json:"id,string"` - Name string `xml:"name,attr" json:"name"` + ID int `xml:"id,attr" json:"id,string"` + Name string `xml:"name,attr" json:"name"` + 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"` - SimilarArtist []*SimilarArtist `xml:"similarArtist" json:"similarArtist"` + 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"` + SimilarArtist []*SimilarArtist `xml:"similarArtist,omitempty" json:"similarArtist,omitempty"` } type Genre struct {