Include a shared Last.FM api key, providing zero conf ArtistInfo (bio/top songs/similar artists)
This commit is contained in:
+13
-6
@@ -10,7 +10,11 @@ import (
|
||||
"github.com/navidrome/navidrome/utils/lastfm"
|
||||
)
|
||||
|
||||
const lastFMAgentName = "lastfm"
|
||||
const (
|
||||
lastFMAgentName = "lastfm"
|
||||
lastFMAPIKey = "c2918986bf01b6ba353c0bc1bdd27bea"
|
||||
//lastFMAPISecret = "3ff2aa214a6d8f2242515083bbb70e79" // Will be needed when implementing Scrobbling
|
||||
)
|
||||
|
||||
type lastfmAgent struct {
|
||||
ctx context.Context
|
||||
@@ -21,9 +25,13 @@ type lastfmAgent struct {
|
||||
|
||||
func lastFMConstructor(ctx context.Context) Interface {
|
||||
l := &lastfmAgent{
|
||||
ctx: ctx,
|
||||
apiKey: conf.Server.LastFM.ApiKey,
|
||||
lang: conf.Server.LastFM.Language,
|
||||
ctx: ctx,
|
||||
lang: conf.Server.LastFM.Language,
|
||||
}
|
||||
if conf.Server.LastFM.ApiKey != "" {
|
||||
l.apiKey = conf.Server.LastFM.ApiKey
|
||||
} else {
|
||||
l.apiKey = lastFMAPIKey
|
||||
}
|
||||
hc := NewCachedHTTPClient(http.DefaultClient, consts.DefaultCachedHttpClientTTL)
|
||||
l.client = lastfm.NewClient(l.apiKey, l.lang, hc)
|
||||
@@ -132,8 +140,7 @@ func (l *lastfmAgent) callArtistGetTopTracks(artistName, mbid string, count int)
|
||||
|
||||
func init() {
|
||||
conf.AddHook(func() {
|
||||
if conf.Server.LastFM.ApiKey != "" {
|
||||
log.Info("Last.FM integration is ENABLED")
|
||||
if conf.Server.LastFM.Enabled {
|
||||
Register(lastFMAgentName, lastFMConstructor)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package agents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("lastfmAgent", func() {
|
||||
Describe("lastFMConstructor", func() {
|
||||
It("uses default api key and language if not configured", func() {
|
||||
conf.Server.LastFM.ApiKey = ""
|
||||
agent := lastFMConstructor(context.TODO())
|
||||
Expect(agent.(*lastfmAgent).apiKey).To(Equal(lastFMAPIKey))
|
||||
Expect(agent.(*lastfmAgent).lang).To(Equal("en"))
|
||||
})
|
||||
|
||||
It("uses configured api key and language", func() {
|
||||
conf.Server.LastFM.ApiKey = "123"
|
||||
conf.Server.LastFM.Language = "pt"
|
||||
agent := lastFMConstructor(context.TODO())
|
||||
Expect(agent.(*lastfmAgent).apiKey).To(Equal("123"))
|
||||
Expect(agent.(*lastfmAgent).lang).To(Equal("pt"))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -84,7 +84,6 @@ func (s *spotifyAgent) searchArtist(name string) (*spotify.Artist, error) {
|
||||
func init() {
|
||||
conf.AddHook(func() {
|
||||
if conf.Server.Spotify.ID != "" && conf.Server.Spotify.Secret != "" {
|
||||
log.Info("Spotify integration is ENABLED")
|
||||
Register(spotifyAgentName, spotifyConstructor)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user