Skip to content

Commit

Permalink
feat(subsonic): improve getArtistInfo2.view similar artist results (#203
Browse files Browse the repository at this point in the history
)

Co-authored-by: xavier <xavier@futurae.com>
  • Loading branch information
2 people authored and sentriz committed Feb 25, 2022
1 parent 401c17b commit 55c0920
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions server/ctrlsubsonic/handlers_by_tags.go
Expand Up @@ -296,7 +296,12 @@ func (c *Controller) ServeGetArtistInfoTwo(r *http.Request) *spec.Response {

count := params.GetOrInt("count", 20)
inclNotPresent := params.GetOrBool("includeNotPresent", false)
for i, similarInfo := range info.Similar.Artists {
similarArtists, err := lastfm.ArtistGetSimilar(apiKey, artist.Name)
if err != nil {
return spec.NewError(0, "fetching artist similar: %v", err)
}

for i, similarInfo := range similarArtists.Artists {
if i == count {
break
}
Expand All @@ -311,16 +316,15 @@ func (c *Controller) ServeGetArtistInfoTwo(r *http.Request) *spec.Response {
if errors.Is(err, gorm.ErrRecordNotFound) && !inclNotPresent {
continue
}
similar := &spec.SimilarArtist{
ID: &specid.ID{},
}
artistID := &specid.ID{}
if artist.ID != 0 {
similar.ID = artist.SID()
artistID = artist.SID()
}
similar.Name = similarInfo.Name
similar.AlbumCount = artist.AlbumCount
sub.ArtistInfoTwo.SimilarArtist = append(
sub.ArtistInfoTwo.SimilarArtist, similar)
sub.ArtistInfoTwo.SimilarArtist = append(sub.ArtistInfoTwo.SimilarArtist, &spec.SimilarArtist{
ID: artistID,
Name: similarInfo.Name,
AlbumCount: artist.AlbumCount,
})
}

return sub
Expand Down

0 comments on commit 55c0920

Please sign in to comment.