Add artistImageUrl available in getArtists endpoint
Also cache artist info in the DB for 1 hour
This commit is contained in:
+15
-32
@@ -69,12 +69,7 @@ func (c *BrowsingController) getArtistIndex(ctx context.Context, mediaFolderId i
|
||||
res.Index = make([]responses.Index, len(indexes))
|
||||
for i, idx := range indexes {
|
||||
res.Index[i].Name = idx.ID
|
||||
res.Index[i].Artists = make([]responses.Artist, len(idx.Artists))
|
||||
for j, a := range idx.Artists {
|
||||
res.Index[i].Artists[j].Id = a.ID
|
||||
res.Index[i].Artists[j].Name = a.Name
|
||||
res.Index[i].Artists[j].AlbumCount = a.AlbumCount
|
||||
}
|
||||
res.Index[i].Artists = toArtists(ctx, idx.Artists)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
@@ -241,28 +236,21 @@ func (c *BrowsingController) GetArtistInfo(w http.ResponseWriter, r *http.Reques
|
||||
count := utils.ParamInt(r, "count", 20)
|
||||
includeNotPresent := utils.ParamBool(r, "includeNotPresent", false)
|
||||
|
||||
info, err := c.ei.ArtistInfo(ctx, id, count, includeNotPresent)
|
||||
artist, err := c.ei.UpdateArtistInfo(ctx, id, count, includeNotPresent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := newResponse()
|
||||
response.ArtistInfo = &responses.ArtistInfo{}
|
||||
response.ArtistInfo.Biography = info.Biography
|
||||
response.ArtistInfo.SmallImageUrl = info.SmallImageUrl
|
||||
response.ArtistInfo.MediumImageUrl = info.MediumImageUrl
|
||||
response.ArtistInfo.LargeImageUrl = info.LargeImageUrl
|
||||
response.ArtistInfo.LastFmUrl = info.LastFMUrl
|
||||
response.ArtistInfo.MusicBrainzID = info.MBID
|
||||
for _, s := range info.SimilarArtists {
|
||||
similar := responses.Artist{}
|
||||
similar.Id = s.ID
|
||||
similar.Name = s.Name
|
||||
similar.AlbumCount = s.AlbumCount
|
||||
if s.Starred {
|
||||
similar.Starred = &s.StarredAt
|
||||
}
|
||||
similar.UserRating = s.Rating
|
||||
response.ArtistInfo.Biography = artist.Biography
|
||||
response.ArtistInfo.SmallImageUrl = artist.SmallImageUrl
|
||||
response.ArtistInfo.MediumImageUrl = artist.MediumImageUrl
|
||||
response.ArtistInfo.LargeImageUrl = artist.LargeImageUrl
|
||||
response.ArtistInfo.LastFmUrl = artist.ExternalUrl
|
||||
response.ArtistInfo.MusicBrainzID = artist.MbzArtistID
|
||||
for _, s := range artist.SimilarArtists {
|
||||
similar := toArtist(ctx, s)
|
||||
response.ArtistInfo.SimilarArtist = append(response.ArtistInfo.SimilarArtist, similar)
|
||||
}
|
||||
return response, nil
|
||||
@@ -283,6 +271,7 @@ func (c *BrowsingController) GetArtistInfo2(w http.ResponseWriter, r *http.Reque
|
||||
similar.Name = s.Name
|
||||
similar.AlbumCount = s.AlbumCount
|
||||
similar.Starred = s.Starred
|
||||
similar.ArtistImageUrl = s.ArtistImageUrl
|
||||
response.ArtistInfo2.SimilarArtist = append(response.ArtistInfo2.SimilarArtist, similar)
|
||||
}
|
||||
return response, nil
|
||||
@@ -362,16 +351,10 @@ func (c *BrowsingController) buildArtistDirectory(ctx context.Context, artist *m
|
||||
}
|
||||
|
||||
func (c *BrowsingController) buildArtist(ctx context.Context, artist *model.Artist, albums model.Albums) *responses.ArtistWithAlbumsID3 {
|
||||
dir := &responses.ArtistWithAlbumsID3{}
|
||||
dir.Id = artist.ID
|
||||
dir.Name = artist.Name
|
||||
dir.AlbumCount = artist.AlbumCount
|
||||
if artist.Starred {
|
||||
dir.Starred = &artist.StarredAt
|
||||
}
|
||||
|
||||
dir.Album = childrenFromAlbums(ctx, albums)
|
||||
return dir
|
||||
a := &responses.ArtistWithAlbumsID3{}
|
||||
a.ArtistID3 = toArtistID3(ctx, *artist)
|
||||
a.Album = childrenFromAlbums(ctx, albums)
|
||||
return a
|
||||
}
|
||||
|
||||
func (c *BrowsingController) buildAlbumDirectory(ctx context.Context, album *model.Album) (*responses.Directory, error) {
|
||||
|
||||
@@ -74,19 +74,38 @@ func getUser(ctx context.Context) string {
|
||||
func toArtists(ctx context.Context, artists model.Artists) []responses.Artist {
|
||||
as := make([]responses.Artist, len(artists))
|
||||
for i, artist := range artists {
|
||||
as[i] = responses.Artist{
|
||||
Id: artist.ID,
|
||||
Name: artist.Name,
|
||||
AlbumCount: artist.AlbumCount,
|
||||
UserRating: artist.Rating,
|
||||
}
|
||||
if artist.Starred {
|
||||
as[i].Starred = &artist.StarredAt
|
||||
}
|
||||
as[i] = toArtist(ctx, artist)
|
||||
}
|
||||
return as
|
||||
}
|
||||
|
||||
func toArtist(ctx context.Context, a model.Artist) responses.Artist {
|
||||
artist := responses.Artist{
|
||||
Id: a.ID,
|
||||
Name: a.Name,
|
||||
AlbumCount: a.AlbumCount,
|
||||
UserRating: a.Rating,
|
||||
ArtistImageUrl: a.ArtistImageUrl(),
|
||||
}
|
||||
if a.Starred {
|
||||
artist.Starred = &a.StarredAt
|
||||
}
|
||||
return artist
|
||||
}
|
||||
|
||||
func toArtistID3(ctx context.Context, a model.Artist) responses.ArtistID3 {
|
||||
artist := responses.ArtistID3{
|
||||
Id: a.ID,
|
||||
Name: a.Name,
|
||||
AlbumCount: a.AlbumCount,
|
||||
ArtistImageUrl: a.ArtistImageUrl(),
|
||||
}
|
||||
if a.Starred {
|
||||
artist.Starred = &a.StarredAt
|
||||
}
|
||||
return artist
|
||||
}
|
||||
|
||||
func toGenres(genres model.Genres) *responses.Genres {
|
||||
response := make([]responses.Genre, len(genres))
|
||||
for i, g := range genres {
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","indexes":{"index":[{"name":"A","artist":[{"id":"111","name":"aaa","albumCount":2,"starred":"2016-03-02T20:30:00Z","userRating":3}]}],"lastModified":1,"ignoredArticles":"A"}}
|
||||
{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","indexes":{"index":[{"name":"A","artist":[{"id":"111","name":"aaa","albumCount":2,"starred":"2016-03-02T20:30:00Z","userRating":3,"artistImageUrl":"https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png"}]}],"lastModified":1,"ignoredArticles":"A"}}
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0"><indexes lastModified="1" ignoredArticles="A"><index name="A"><artist id="111" name="aaa" albumCount="2" starred="2016-03-02T20:30:00Z" userRating="3"></artist></index></indexes></subsonic-response>
|
||||
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0"><indexes lastModified="1" ignoredArticles="A"><index name="A"><artist id="111" name="aaa" albumCount="2" starred="2016-03-02T20:30:00Z" userRating="3" artistImageUrl="https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png"></artist></index></indexes></subsonic-response>
|
||||
|
||||
@@ -71,11 +71,12 @@ type MusicFolders struct {
|
||||
}
|
||||
|
||||
type Artist struct {
|
||||
Id string `xml:"id,attr" json:"id"`
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
|
||||
Id string `xml:"id,attr" json:"id"`
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
|
||||
ArtistImageUrl string `xml:"artistImageUrl,attr,omitempty" json:"artistImageUrl,omitempty"`
|
||||
/*
|
||||
<xs:attribute name="averageRating" type="sub:AverageRating" use="optional"/> <!-- Added in 1.13.0 -->
|
||||
*/
|
||||
@@ -158,11 +159,12 @@ type Directory struct {
|
||||
}
|
||||
|
||||
type ArtistID3 struct {
|
||||
Id string `xml:"id,attr" json:"id"`
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
||||
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||
Id string `xml:"id,attr" json:"id"`
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
||||
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||
ArtistImageUrl string `xml:"artistImageUrl,attr,omitempty" json:"artistImageUrl,omitempty"`
|
||||
}
|
||||
|
||||
type AlbumID3 struct {
|
||||
|
||||
@@ -92,7 +92,14 @@ var _ = Describe("Responses", func() {
|
||||
BeforeEach(func() {
|
||||
artists := make([]Artist, 1)
|
||||
t := time.Date(2016, 03, 2, 20, 30, 0, 0, time.UTC)
|
||||
artists[0] = Artist{Id: "111", Name: "aaa", Starred: &t, UserRating: 3, AlbumCount: 2}
|
||||
artists[0] = Artist{
|
||||
Id: "111",
|
||||
Name: "aaa",
|
||||
Starred: &t,
|
||||
UserRating: 3,
|
||||
AlbumCount: 2,
|
||||
ArtistImageUrl: "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png",
|
||||
}
|
||||
index := make([]Index, 1)
|
||||
index[0] = Index{Name: "A", Artists: artists}
|
||||
response.Indexes.Index = index
|
||||
|
||||
@@ -96,6 +96,7 @@ func (c *SearchingController) Search2(w http.ResponseWriter, r *http.Request) (*
|
||||
}
|
||||
|
||||
func (c *SearchingController) Search3(w http.ResponseWriter, r *http.Request) (*responses.Subsonic, error) {
|
||||
ctx := r.Context()
|
||||
sp, err := c.getParams(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -106,17 +107,10 @@ func (c *SearchingController) Search3(w http.ResponseWriter, r *http.Request) (*
|
||||
searchResult3 := &responses.SearchResult3{}
|
||||
searchResult3.Artist = make([]responses.ArtistID3, len(as))
|
||||
for i, artist := range as {
|
||||
searchResult3.Artist[i] = responses.ArtistID3{
|
||||
Id: artist.ID,
|
||||
Name: artist.Name,
|
||||
AlbumCount: artist.AlbumCount,
|
||||
}
|
||||
if artist.Starred {
|
||||
searchResult3.Artist[i].Starred = &artist.StarredAt
|
||||
}
|
||||
searchResult3.Artist[i] = toArtistID3(ctx, artist)
|
||||
}
|
||||
searchResult3.Album = childrenFromAlbums(r.Context(), als)
|
||||
searchResult3.Song = childrenFromMediaFiles(r.Context(), mfs)
|
||||
searchResult3.Album = childrenFromAlbums(ctx, als)
|
||||
searchResult3.Song = childrenFromMediaFiles(ctx, mfs)
|
||||
response.SearchResult3 = searchResult3
|
||||
return response, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user