only return artist cover art if we have cached it

This commit is contained in:
sentriz
2023-09-14 00:32:48 +01:00
parent 5c6a59ac38
commit df2c0707dd
13 changed files with 162 additions and 225 deletions

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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

View File

@@ -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 {

View File

@@ -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
}
]
}

View File

@@ -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
}
]
}

View File

@@ -7,7 +7,6 @@
"artist": {
"id": "ar-1",
"name": "artist-0",
"coverArt": "ar-1",
"albumCount": 3,
"album": [
{

View File

@@ -7,7 +7,6 @@
"artist": {
"id": "ar-3",
"name": "artist-2",
"coverArt": "ar-3",
"albumCount": 3,
"album": [
{

View File

@@ -7,7 +7,6 @@
"artist": {
"id": "ar-2",
"name": "artist-1",
"coverArt": "ar-2",
"albumCount": 3,
"album": [
{

View File

@@ -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 }
]
}
]

View File

@@ -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 }
]
}
]

View File

@@ -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 }
]
}
]

View File

@@ -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 }
]
}
}