feat(lastfm): autocorrect artist and album name misspellings when fetching info
closes #472
This commit is contained in:
@@ -52,6 +52,7 @@ func (c *Client) ArtistGetInfo(artistName string) (Artist, error) {
|
|||||||
params.Add("method", "artist.getInfo")
|
params.Add("method", "artist.getInfo")
|
||||||
params.Add("api_key", apiKey)
|
params.Add("api_key", apiKey)
|
||||||
params.Add("artist", artistName)
|
params.Add("artist", artistName)
|
||||||
|
params.Add("autocorrect", "1")
|
||||||
|
|
||||||
resp, err := c.makeRequest(http.MethodGet, params)
|
resp, err := c.makeRequest(http.MethodGet, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -72,6 +73,7 @@ func (c *Client) AlbumGetInfo(artistName, albumName string) (Album, error) {
|
|||||||
params.Add("api_key", apiKey)
|
params.Add("api_key", apiKey)
|
||||||
params.Add("artist", artistName)
|
params.Add("artist", artistName)
|
||||||
params.Add("album", albumName)
|
params.Add("album", albumName)
|
||||||
|
params.Add("autocorrect", "1")
|
||||||
|
|
||||||
resp, err := c.makeRequest(http.MethodGet, params)
|
resp, err := c.makeRequest(http.MethodGet, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func TestArtistGetInfo(t *testing.T) {
|
|||||||
client := lastfm.NewClientCustom(
|
client := lastfm.NewClientCustom(
|
||||||
mockclient.New(t, func(w http.ResponseWriter, r *http.Request) {
|
mockclient.New(t, func(w http.ResponseWriter, r *http.Request) {
|
||||||
require.Equal(t, http.MethodGet, r.Method)
|
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, "/2.0/", r.URL.Path)
|
||||||
require.Equal(t, lastfm.BaseURL, "https://"+r.Host+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) {
|
mockclient.New(t, func(w http.ResponseWriter, r *http.Request) {
|
||||||
require.Equal(t, http.MethodGet, r.Method)
|
require.Equal(t, http.MethodGet, r.Method)
|
||||||
require.Equal(t, url.Values{
|
require.Equal(t, url.Values{
|
||||||
"method": []string{"artist.getInfo"},
|
"method": []string{"artist.getInfo"},
|
||||||
"api_key": []string{"apiKey1"},
|
"api_key": []string{"apiKey1"},
|
||||||
"artist": []string{"Artist 1"},
|
"artist": []string{"Artist 1"},
|
||||||
|
"autocorrect": []string{"1"},
|
||||||
}, r.URL.Query())
|
}, r.URL.Query())
|
||||||
|
|
||||||
require.Equal(t, "/2.0/", r.URL.Path)
|
require.Equal(t, "/2.0/", r.URL.Path)
|
||||||
|
|||||||
Reference in New Issue
Block a user