feat(lastfm): autocorrect artist and album name misspellings when fetching info

closes #472
This commit is contained in:
sentriz
2024-02-20 18:31:44 +00:00
parent 51fa0baac3
commit 2878b88aee
2 changed files with 7 additions and 4 deletions

View File

@@ -52,6 +52,7 @@ func (c *Client) ArtistGetInfo(artistName string) (Artist, error) {
params.Add("method", "artist.getInfo")
params.Add("api_key", apiKey)
params.Add("artist", artistName)
params.Add("autocorrect", "1")
resp, err := c.makeRequest(http.MethodGet, params)
if err != nil {
@@ -72,6 +73,7 @@ func (c *Client) AlbumGetInfo(artistName, albumName string) (Album, error) {
params.Add("api_key", apiKey)
params.Add("artist", artistName)
params.Add("album", albumName)
params.Add("autocorrect", "1")
resp, err := c.makeRequest(http.MethodGet, params)
if err != nil {

View File

@@ -23,7 +23,7 @@ func TestArtistGetInfo(t *testing.T) {
client := lastfm.NewClientCustom(
mockclient.New(t, func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodGet, r.Method)
require.Equal(t, url.Values{"method": []string{"artist.getInfo"}, "api_key": []string{"apiKey1"}, "artist": []string{"Artist 1"}}, r.URL.Query())
require.Equal(t, url.Values{"method": []string{"artist.getInfo"}, "api_key": []string{"apiKey1"}, "artist": []string{"Artist 1"}, "autocorrect": []string{"1"}}, r.URL.Query())
require.Equal(t, "/2.0/", r.URL.Path)
require.Equal(t, lastfm.BaseURL, "https://"+r.Host+r.URL.Path)
@@ -103,9 +103,10 @@ func TestArtistGetInfoClientRequestFails(t *testing.T) {
mockclient.New(t, func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodGet, r.Method)
require.Equal(t, url.Values{
"method": []string{"artist.getInfo"},
"api_key": []string{"apiKey1"},
"artist": []string{"Artist 1"},
"method": []string{"artist.getInfo"},
"api_key": []string{"apiKey1"},
"artist": []string{"Artist 1"},
"autocorrect": []string{"1"},
}, r.URL.Query())
require.Equal(t, "/2.0/", r.URL.Path)