Cleanup, add Placeholder agent
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/navidrome/navidrome/log"
|
||||
)
|
||||
|
||||
const cacheSizeLimit = 1000
|
||||
const cacheSizeLimit = 100
|
||||
|
||||
type CachedHTTPClient struct {
|
||||
cache *ttlcache.Cache
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"github.com/navidrome/navidrome/log"
|
||||
)
|
||||
|
||||
const lastFMAgentName = "lastfm"
|
||||
|
||||
type lastfmAgent struct {
|
||||
ctx context.Context
|
||||
apiKey string
|
||||
@@ -18,10 +20,6 @@ type lastfmAgent struct {
|
||||
}
|
||||
|
||||
func lastFMConstructor(ctx context.Context) Interface {
|
||||
if conf.Server.LastFM.ApiKey == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
l := &lastfmAgent{
|
||||
ctx: ctx,
|
||||
apiKey: conf.Server.LastFM.ApiKey,
|
||||
@@ -33,7 +31,7 @@ func lastFMConstructor(ctx context.Context) Interface {
|
||||
}
|
||||
|
||||
func (l *lastfmAgent) AgentName() string {
|
||||
return "lastfm"
|
||||
return lastFMAgentName
|
||||
}
|
||||
|
||||
func (l *lastfmAgent) GetMBID(name string) (string, error) {
|
||||
@@ -136,7 +134,7 @@ func init() {
|
||||
conf.AddHook(func() {
|
||||
if conf.Server.LastFM.ApiKey != "" {
|
||||
log.Info("Last.FM integration is ENABLED")
|
||||
Register("lastfm", lastFMConstructor)
|
||||
Register(lastFMAgentName, lastFMConstructor)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package agents
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const PlaceholderAgentName = "placeholder"
|
||||
|
||||
const (
|
||||
placeholderArtistImageSmallUrl = "https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png"
|
||||
placeholderArtistImageMediumUrl = "https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png"
|
||||
placeholderArtistImageLargeUrl = "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png"
|
||||
placeholderBiography = "Biography not available"
|
||||
)
|
||||
|
||||
type placeholderAgent struct{}
|
||||
|
||||
func placeholdersConstructor(ctx context.Context) Interface {
|
||||
return &placeholderAgent{}
|
||||
}
|
||||
|
||||
func (p *placeholderAgent) AgentName() string {
|
||||
return PlaceholderAgentName
|
||||
}
|
||||
|
||||
func (p *placeholderAgent) GetBiography(name, mbid string) (string, error) {
|
||||
return placeholderBiography, nil
|
||||
}
|
||||
|
||||
func (p *placeholderAgent) GetImages(name, mbid string) ([]ArtistImage, error) {
|
||||
return []ArtistImage{
|
||||
{placeholderArtistImageLargeUrl, 300},
|
||||
{placeholderArtistImageMediumUrl, 174},
|
||||
{placeholderArtistImageSmallUrl, 64},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(PlaceholderAgentName, placeholdersConstructor)
|
||||
}
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
"github.com/xrash/smetrics"
|
||||
)
|
||||
|
||||
const spotifyAgentName = "spotify"
|
||||
|
||||
type spotifyAgent struct {
|
||||
ctx context.Context
|
||||
id string
|
||||
@@ -23,10 +25,6 @@ type spotifyAgent struct {
|
||||
}
|
||||
|
||||
func spotifyConstructor(ctx context.Context) Interface {
|
||||
if conf.Server.Spotify.ID == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
l := &spotifyAgent{
|
||||
ctx: ctx,
|
||||
id: conf.Server.Spotify.ID,
|
||||
@@ -38,7 +36,7 @@ func spotifyConstructor(ctx context.Context) Interface {
|
||||
}
|
||||
|
||||
func (s *spotifyAgent) AgentName() string {
|
||||
return "spotify"
|
||||
return spotifyAgentName
|
||||
}
|
||||
|
||||
func (s *spotifyAgent) GetImages(name, mbid string) ([]ArtistImage, error) {
|
||||
@@ -87,7 +85,7 @@ func init() {
|
||||
conf.AddHook(func() {
|
||||
if conf.Server.Spotify.ID != "" && conf.Server.Spotify.Secret != "" {
|
||||
log.Info("Spotify integration is ENABLED")
|
||||
Register("spotify", spotifyConstructor)
|
||||
Register(spotifyAgentName, spotifyConstructor)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user