diff --git a/conf/configuration.go b/conf/configuration.go index a9fee00e4..0ad81492a 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -176,7 +176,8 @@ type spotifyOptions struct { } type deezerOptions struct { - Enabled bool + Enabled bool + Language string } type listenBrainzOptions struct { @@ -566,6 +567,7 @@ func setViperDefaults() { viper.SetDefault("spotify.id", "") viper.SetDefault("spotify.secret", "") viper.SetDefault("deezer.enabled", true) + viper.SetDefault("deezer.language", "en") viper.SetDefault("listenbrainz.enabled", true) viper.SetDefault("listenbrainz.baseurl", "https://api.listenbrainz.org/1/") viper.SetDefault("httpsecurityheaders.customframeoptionsvalue", "DENY") diff --git a/core/agents/deezer/client.go b/core/agents/deezer/client.go index 2c07d53db..906e1f5e5 100644 --- a/core/agents/deezer/client.go +++ b/core/agents/deezer/client.go @@ -28,10 +28,11 @@ type httpDoer interface { type client struct { httpDoer httpDoer + language string } -func newClient(hc httpDoer) *client { - return &client{hc} +func newClient(hc httpDoer, language string) *client { + return &client{hc, language} } func (c *client) searchArtists(ctx context.Context, name string, limit int) ([]Artist, error) { @@ -122,7 +123,7 @@ var dzrAppStateRegex = regexp.MustCompile(`window\.__DZR_APP_STATE__\s*=\s*({.+? var strictPolicy = bluemonday.StrictPolicy() func (c *client) getArtistBio(ctx context.Context, artistID int) (string, error) { - u := fmt.Sprintf("https://www.deezer.com/en/artist/%d/biography", artistID) + u := fmt.Sprintf("https://www.deezer.com/%s/artist/%d/biography", c.language, artistID) req, err := http.NewRequestWithContext(ctx, "GET", u, nil) if err != nil { return "", err diff --git a/core/agents/deezer/client_test.go b/core/agents/deezer/client_test.go index d2162c1fe..15c111a68 100644 --- a/core/agents/deezer/client_test.go +++ b/core/agents/deezer/client_test.go @@ -2,7 +2,6 @@ package deezer import ( "bytes" - "context" "io" "net/http" "os" @@ -17,7 +16,7 @@ var _ = Describe("client", func() { BeforeEach(func() { httpClient = &fakeHttpClient{} - client = newClient(httpClient) + client = newClient(httpClient, "en") }) Describe("ArtistImages", func() { @@ -26,7 +25,7 @@ var _ = Describe("client", func() { Expect(err).To(BeNil()) httpClient.mock("https://api.deezer.com/search/artist", http.Response{Body: f, StatusCode: 200}) - artists, err := client.searchArtists(context.TODO(), "Michael Jackson", 20) + artists, err := client.searchArtists(GinkgoT().Context(), "Michael Jackson", 20) Expect(err).To(BeNil()) Expect(artists).To(HaveLen(17)) Expect(artists[0].Name).To(Equal("Michael Jackson")) @@ -39,7 +38,7 @@ var _ = Describe("client", func() { Body: io.NopCloser(bytes.NewBufferString(`{"data":[],"total":0}`)), }) - _, err := client.searchArtists(context.TODO(), "Michael Jackson", 20) + _, err := client.searchArtists(GinkgoT().Context(), "Michael Jackson", 20) Expect(err).To(MatchError(ErrNotFound)) }) }) @@ -50,12 +49,23 @@ var _ = Describe("client", func() { Expect(err).To(BeNil()) httpClient.mock("https://www.deezer.com/en/artist/27/biography", http.Response{Body: f, StatusCode: 200}) - bio, err := client.getArtistBio(context.TODO(), 27) + bio, err := client.getArtistBio(GinkgoT().Context(), 27) Expect(err).To(BeNil()) Expect(bio).To(ContainSubstring("Schoolmates Thomas and Guy-Manuel")) Expect(bio).ToNot(ContainSubstring("
")) Expect(bio).ToNot(ContainSubstring("
")) }) + + It("uses the configured language", func() { + client = newClient(httpClient, "fr") + f, err := os.Open("tests/fixtures/deezer.artist.bio.html") + Expect(err).To(BeNil()) + httpClient.mock("https://www.deezer.com/fr/artist/27/biography", http.Response{Body: f, StatusCode: 200}) + + _, err = client.getArtistBio(GinkgoT().Context(), 27) + Expect(err).To(BeNil()) + Expect(httpClient.lastRequest.URL.String()).To(Equal("https://www.deezer.com/fr/artist/27/biography")) + }) }) }) diff --git a/core/agents/deezer/deezer.go b/core/agents/deezer/deezer.go index df286e828..8f3e505ec 100644 --- a/core/agents/deezer/deezer.go +++ b/core/agents/deezer/deezer.go @@ -33,7 +33,7 @@ func deezerConstructor(dataStore model.DataStore) agents.Interface { Timeout: consts.DefaultHttpClientTimeOut, } cachedHttpClient := cache.NewHTTPClient(httpClient, consts.DefaultHttpClientTimeOut) - agent.client = newClient(cachedHttpClient) + agent.client = newClient(cachedHttpClient, conf.Server.Deezer.Language) return agent }