mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-10 12:22:19 +03:00
Use MBID in calls to Last.FM, if it is available
This commit is contained in:
parent
6c1fc5f836
commit
84a50d5dce
@ -106,7 +106,7 @@ func (l *lastfmAgent) GetTopSongs(artistName, mbid string, count int) ([]Track,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *lastfmAgent) callArtistGetInfo(name string, mbid string) (*lastfm.Artist, error) {
|
func (l *lastfmAgent) callArtistGetInfo(name string, mbid string) (*lastfm.Artist, error) {
|
||||||
a, err := l.client.ArtistGetInfo(l.ctx, name)
|
a, err := l.client.ArtistGetInfo(l.ctx, name, mbid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(l.ctx, "Error calling LastFM/artist.getInfo", "artist", name, "mbid", mbid, err)
|
log.Error(l.ctx, "Error calling LastFM/artist.getInfo", "artist", name, "mbid", mbid, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -115,7 +115,7 @@ func (l *lastfmAgent) callArtistGetInfo(name string, mbid string) (*lastfm.Artis
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *lastfmAgent) callArtistGetSimilar(name string, mbid string, limit int) ([]lastfm.Artist, error) {
|
func (l *lastfmAgent) callArtistGetSimilar(name string, mbid string, limit int) ([]lastfm.Artist, error) {
|
||||||
s, err := l.client.ArtistGetSimilar(l.ctx, name, limit)
|
s, err := l.client.ArtistGetSimilar(l.ctx, name, mbid, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(l.ctx, "Error calling LastFM/artist.getSimilar", "artist", name, "mbid", mbid, err)
|
log.Error(l.ctx, "Error calling LastFM/artist.getSimilar", "artist", name, "mbid", mbid, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -124,7 +124,7 @@ func (l *lastfmAgent) callArtistGetSimilar(name string, mbid string, limit int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *lastfmAgent) callArtistGetTopTracks(artistName, mbid string, count int) ([]lastfm.Track, error) {
|
func (l *lastfmAgent) callArtistGetTopTracks(artistName, mbid string, count int) ([]lastfm.Track, error) {
|
||||||
t, err := l.client.ArtistGetTopTracks(l.ctx, artistName, count)
|
t, err := l.client.ArtistGetTopTracks(l.ctx, artistName, mbid, count)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(l.ctx, "Error calling LastFM/artist.getTopTracks", "artist", artistName, "mbid", mbid, err)
|
log.Error(l.ctx, "Error calling LastFM/artist.getTopTracks", "artist", artistName, "mbid", mbid, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -141,7 +141,7 @@ func (e *externalInfo) similarArtists(ctx context.Context, artistName string, co
|
|||||||
var notPresent []string
|
var notPresent []string
|
||||||
|
|
||||||
log.Debug(ctx, "Calling Last.FM ArtistGetSimilar", "artist", artistName)
|
log.Debug(ctx, "Calling Last.FM ArtistGetSimilar", "artist", artistName)
|
||||||
similar, err := e.lfm.ArtistGetSimilar(ctx, artistName, count)
|
similar, err := e.lfm.ArtistGetSimilar(ctx, artistName, "", count)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -194,7 +194,7 @@ func (e *externalInfo) TopSongs(ctx context.Context, artistName string, count in
|
|||||||
artistName = clearName(artistName)
|
artistName = clearName(artistName)
|
||||||
|
|
||||||
log.Debug(ctx, "Calling Last.FM ArtistGetTopTracks", "artist", artistName, "id", artist.ID)
|
log.Debug(ctx, "Calling Last.FM ArtistGetTopTracks", "artist", artistName, "id", artist.ID)
|
||||||
tracks, err := e.lfm.ArtistGetTopTracks(ctx, artistName, count)
|
tracks, err := e.lfm.ArtistGetTopTracks(ctx, artistName, artist.MbzArtistID, count)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -242,7 +242,7 @@ func (e *externalInfo) callArtistInfo(ctx context.Context, artist *model.Artist,
|
|||||||
go func() {
|
go func() {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
lfmArtist, err := e.lfm.ArtistGetInfo(ctx, name)
|
lfmArtist, err := e.lfm.ArtistGetInfo(ctx, name, artist.MbzArtistID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(ctx, "Error calling Last.FM", "artist", name, err)
|
log.Error(ctx, "Error calling Last.FM", "artist", name, err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,10 +56,11 @@ func (c *Client) makeRequest(params url.Values) (*Response, error) {
|
|||||||
return &response, err
|
return &response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ArtistGetInfo(ctx context.Context, name string) (*Artist, error) {
|
func (c *Client) ArtistGetInfo(ctx context.Context, name string, mbid string) (*Artist, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("method", "artist.getInfo")
|
params.Add("method", "artist.getInfo")
|
||||||
params.Add("artist", name)
|
params.Add("artist", name)
|
||||||
|
params.Add("mbid", mbid)
|
||||||
params.Add("lang", c.lang)
|
params.Add("lang", c.lang)
|
||||||
response, err := c.makeRequest(params)
|
response, err := c.makeRequest(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -68,10 +69,11 @@ func (c *Client) ArtistGetInfo(ctx context.Context, name string) (*Artist, error
|
|||||||
return &response.Artist, nil
|
return &response.Artist, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ArtistGetSimilar(ctx context.Context, name string, limit int) ([]Artist, error) {
|
func (c *Client) ArtistGetSimilar(ctx context.Context, name string, mbid string, limit int) ([]Artist, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("method", "artist.getSimilar")
|
params.Add("method", "artist.getSimilar")
|
||||||
params.Add("artist", name)
|
params.Add("artist", name)
|
||||||
|
params.Add("mbid", mbid)
|
||||||
params.Add("limit", strconv.Itoa(limit))
|
params.Add("limit", strconv.Itoa(limit))
|
||||||
response, err := c.makeRequest(params)
|
response, err := c.makeRequest(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -80,10 +82,11 @@ func (c *Client) ArtistGetSimilar(ctx context.Context, name string, limit int) (
|
|||||||
return response.SimilarArtists.Artists, nil
|
return response.SimilarArtists.Artists, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ArtistGetTopTracks(ctx context.Context, name string, limit int) ([]Track, error) {
|
func (c *Client) ArtistGetTopTracks(ctx context.Context, name string, mbid string, limit int) ([]Track, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("method", "artist.getTopTracks")
|
params.Add("method", "artist.getTopTracks")
|
||||||
params.Add("artist", name)
|
params.Add("artist", name)
|
||||||
|
params.Add("mbid", mbid)
|
||||||
params.Add("limit", strconv.Itoa(limit))
|
params.Add("limit", strconv.Itoa(limit))
|
||||||
response, err := c.makeRequest(params)
|
response, err := c.makeRequest(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -26,10 +26,10 @@ var _ = Describe("Client", func() {
|
|||||||
f, _ := os.Open("tests/fixtures/lastfm.artist.getinfo.json")
|
f, _ := os.Open("tests/fixtures/lastfm.artist.getinfo.json")
|
||||||
httpClient.res = http.Response{Body: f, StatusCode: 200}
|
httpClient.res = http.Response{Body: f, StatusCode: 200}
|
||||||
|
|
||||||
artist, err := client.ArtistGetInfo(context.TODO(), "U2")
|
artist, err := client.ArtistGetInfo(context.TODO(), "U2", "123")
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
Expect(artist.Name).To(Equal("U2"))
|
Expect(artist.Name).To(Equal("U2"))
|
||||||
Expect(httpClient.savedRequest.URL.String()).To(Equal(apiBaseUrl + "?api_key=API_KEY&artist=U2&format=json&lang=pt&method=artist.getInfo"))
|
Expect(httpClient.savedRequest.URL.String()).To(Equal(apiBaseUrl + "?api_key=API_KEY&artist=U2&format=json&lang=pt&mbid=123&method=artist.getInfo"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("fails if Last.FM returns an error", func() {
|
It("fails if Last.FM returns an error", func() {
|
||||||
@ -38,14 +38,14 @@ var _ = Describe("Client", func() {
|
|||||||
StatusCode: 400,
|
StatusCode: 400,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.ArtistGetInfo(context.TODO(), "U2")
|
_, err := client.ArtistGetInfo(context.TODO(), "U2", "123")
|
||||||
Expect(err).To(MatchError("last.fm error(3): Invalid Method - No method with that name in this package"))
|
Expect(err).To(MatchError("last.fm error(3): Invalid Method - No method with that name in this package"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("fails if HttpClient.Do() returns error", func() {
|
It("fails if HttpClient.Do() returns error", func() {
|
||||||
httpClient.err = errors.New("generic error")
|
httpClient.err = errors.New("generic error")
|
||||||
|
|
||||||
_, err := client.ArtistGetInfo(context.TODO(), "U2")
|
_, err := client.ArtistGetInfo(context.TODO(), "U2", "123")
|
||||||
Expect(err).To(MatchError("generic error"))
|
Expect(err).To(MatchError("generic error"))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ var _ = Describe("Client", func() {
|
|||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.ArtistGetInfo(context.TODO(), "U2")
|
_, err := client.ArtistGetInfo(context.TODO(), "U2", "123")
|
||||||
Expect(err).To(MatchError("invalid character '<' looking for beginning of value"))
|
Expect(err).To(MatchError("invalid character '<' looking for beginning of value"))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -66,10 +66,10 @@ var _ = Describe("Client", func() {
|
|||||||
f, _ := os.Open("tests/fixtures/lastfm.artist.getsimilar.json")
|
f, _ := os.Open("tests/fixtures/lastfm.artist.getsimilar.json")
|
||||||
httpClient.res = http.Response{Body: f, StatusCode: 200}
|
httpClient.res = http.Response{Body: f, StatusCode: 200}
|
||||||
|
|
||||||
artists, err := client.ArtistGetSimilar(context.TODO(), "U2", 2)
|
artists, err := client.ArtistGetSimilar(context.TODO(), "U2", "123", 2)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
Expect(len(artists)).To(Equal(2))
|
Expect(len(artists)).To(Equal(2))
|
||||||
Expect(httpClient.savedRequest.URL.String()).To(Equal(apiBaseUrl + "?api_key=API_KEY&artist=U2&format=json&limit=2&method=artist.getSimilar"))
|
Expect(httpClient.savedRequest.URL.String()).To(Equal(apiBaseUrl + "?api_key=API_KEY&artist=U2&format=json&limit=2&mbid=123&method=artist.getSimilar"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("fails if Last.FM returns an error", func() {
|
It("fails if Last.FM returns an error", func() {
|
||||||
@ -78,14 +78,14 @@ var _ = Describe("Client", func() {
|
|||||||
StatusCode: 400,
|
StatusCode: 400,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.ArtistGetSimilar(context.TODO(), "U2", 2)
|
_, err := client.ArtistGetSimilar(context.TODO(), "U2", "123", 2)
|
||||||
Expect(err).To(MatchError("last.fm error(3): Invalid Method - No method with that name in this package"))
|
Expect(err).To(MatchError("last.fm error(3): Invalid Method - No method with that name in this package"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("fails if HttpClient.Do() returns error", func() {
|
It("fails if HttpClient.Do() returns error", func() {
|
||||||
httpClient.err = errors.New("generic error")
|
httpClient.err = errors.New("generic error")
|
||||||
|
|
||||||
_, err := client.ArtistGetSimilar(context.TODO(), "U2", 2)
|
_, err := client.ArtistGetSimilar(context.TODO(), "U2", "123", 2)
|
||||||
Expect(err).To(MatchError("generic error"))
|
Expect(err).To(MatchError("generic error"))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ var _ = Describe("Client", func() {
|
|||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.ArtistGetSimilar(context.TODO(), "U2", 2)
|
_, err := client.ArtistGetSimilar(context.TODO(), "U2", "123", 2)
|
||||||
Expect(err).To(MatchError("invalid character '<' looking for beginning of value"))
|
Expect(err).To(MatchError("invalid character '<' looking for beginning of value"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -105,10 +105,10 @@ var _ = Describe("Client", func() {
|
|||||||
f, _ := os.Open("tests/fixtures/lastfm.artist.gettoptracks.json")
|
f, _ := os.Open("tests/fixtures/lastfm.artist.gettoptracks.json")
|
||||||
httpClient.res = http.Response{Body: f, StatusCode: 200}
|
httpClient.res = http.Response{Body: f, StatusCode: 200}
|
||||||
|
|
||||||
tracks, err := client.ArtistGetTopTracks(context.TODO(), "U2", 2)
|
tracks, err := client.ArtistGetTopTracks(context.TODO(), "U2", "123", 2)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
Expect(len(tracks)).To(Equal(2))
|
Expect(len(tracks)).To(Equal(2))
|
||||||
Expect(httpClient.savedRequest.URL.String()).To(Equal(apiBaseUrl + "?api_key=API_KEY&artist=U2&format=json&limit=2&method=artist.getTopTracks"))
|
Expect(httpClient.savedRequest.URL.String()).To(Equal(apiBaseUrl + "?api_key=API_KEY&artist=U2&format=json&limit=2&mbid=123&method=artist.getTopTracks"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("fails if Last.FM returns an error", func() {
|
It("fails if Last.FM returns an error", func() {
|
||||||
@ -117,14 +117,14 @@ var _ = Describe("Client", func() {
|
|||||||
StatusCode: 400,
|
StatusCode: 400,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.ArtistGetTopTracks(context.TODO(), "U2", 2)
|
_, err := client.ArtistGetTopTracks(context.TODO(), "U2", "123", 2)
|
||||||
Expect(err).To(MatchError("last.fm error(3): Invalid Method - No method with that name in this package"))
|
Expect(err).To(MatchError("last.fm error(3): Invalid Method - No method with that name in this package"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("fails if HttpClient.Do() returns error", func() {
|
It("fails if HttpClient.Do() returns error", func() {
|
||||||
httpClient.err = errors.New("generic error")
|
httpClient.err = errors.New("generic error")
|
||||||
|
|
||||||
_, err := client.ArtistGetTopTracks(context.TODO(), "U2", 2)
|
_, err := client.ArtistGetTopTracks(context.TODO(), "U2", "123", 2)
|
||||||
Expect(err).To(MatchError("generic error"))
|
Expect(err).To(MatchError("generic error"))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ var _ = Describe("Client", func() {
|
|||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.ArtistGetTopTracks(context.TODO(), "U2", 2)
|
_, err := client.ArtistGetTopTracks(context.TODO(), "U2", "123", 2)
|
||||||
Expect(err).To(MatchError("invalid character '<' looking for beginning of value"))
|
Expect(err).To(MatchError("invalid character '<' looking for beginning of value"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user