return similar artists
This commit is contained in:
@@ -257,5 +257,31 @@ func (c *Controller) ServeGetArtistInfoTwo(r *http.Request) *spec.Response {
|
|||||||
sub.ArtistInfoTwo.LargeImageURL = image.Text
|
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
|
return sub
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,6 +230,7 @@ type Playlist struct {
|
|||||||
type SimilarArtist struct {
|
type SimilarArtist struct {
|
||||||
ID int `xml:"id,attr" json:"id,string"`
|
ID int `xml:"id,attr" json:"id,string"`
|
||||||
Name string `xml:"name,attr" json:"name"`
|
Name string `xml:"name,attr" json:"name"`
|
||||||
|
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtistInfo struct {
|
type ArtistInfo struct {
|
||||||
@@ -239,7 +240,7 @@ type ArtistInfo struct {
|
|||||||
SmallImageURL string `xml:"smallImageUrl" json:"smallImageUrl"`
|
SmallImageURL string `xml:"smallImageUrl" json:"smallImageUrl"`
|
||||||
MediumImageURL string `xml:"mediumImageUrl" json:"mediumImageUrl"`
|
MediumImageURL string `xml:"mediumImageUrl" json:"mediumImageUrl"`
|
||||||
LargeImageURL string `xml:"largeImageUrl" json:"largeImageUrl"`
|
LargeImageURL string `xml:"largeImageUrl" json:"largeImageUrl"`
|
||||||
SimilarArtist []*SimilarArtist `xml:"similarArtist" json:"similarArtist"`
|
SimilarArtist []*SimilarArtist `xml:"similarArtist,omitempty" json:"similarArtist,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Genre struct {
|
type Genre struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user