mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-16 23:32:32 +03:00
Fix recursive bug in Last.FM calls without mbid
This commit is contained in:
parent
ead2095dd0
commit
c5abdc19bc
@ -114,7 +114,7 @@ func (l *lastfmAgent) GetTopSongs(id, artistName, mbid string, count int) ([]Son
|
|||||||
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, mbid)
|
a, err := l.client.ArtistGetInfo(l.ctx, name, mbid)
|
||||||
lfErr, isLastFMError := err.(*lastfm.Error)
|
lfErr, isLastFMError := err.(*lastfm.Error)
|
||||||
if mbid != "" && (err == nil && a.Name == "[unknown]") || (isLastFMError && lfErr.Code == 6) {
|
if mbid != "" && ((err == nil && a.Name == "[unknown]") || (isLastFMError && lfErr.Code == 6)) {
|
||||||
log.Warn(l.ctx, "LastFM/artist.getInfo could not find artist by mbid, trying again", "artist", name, "mbid", mbid)
|
log.Warn(l.ctx, "LastFM/artist.getInfo could not find artist by mbid, trying again", "artist", name, "mbid", mbid)
|
||||||
return l.callArtistGetInfo(name, "")
|
return l.callArtistGetInfo(name, "")
|
||||||
}
|
}
|
||||||
@ -129,7 +129,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, mbid, limit)
|
s, err := l.client.ArtistGetSimilar(l.ctx, name, mbid, limit)
|
||||||
lfErr, isLastFMError := err.(*lastfm.Error)
|
lfErr, isLastFMError := err.(*lastfm.Error)
|
||||||
if mbid != "" && (err == nil && s.Attr.Artist == "[unknown]") || (isLastFMError && lfErr.Code == 6) {
|
if mbid != "" && ((err == nil && s.Attr.Artist == "[unknown]") || (isLastFMError && lfErr.Code == 6)) {
|
||||||
log.Warn(l.ctx, "LastFM/artist.getSimilar could not find artist by mbid, trying again", "artist", name, "mbid", mbid)
|
log.Warn(l.ctx, "LastFM/artist.getSimilar could not find artist by mbid, trying again", "artist", name, "mbid", mbid)
|
||||||
return l.callArtistGetSimilar(name, "", limit)
|
return l.callArtistGetSimilar(name, "", limit)
|
||||||
}
|
}
|
||||||
@ -143,7 +143,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, mbid, count)
|
t, err := l.client.ArtistGetTopTracks(l.ctx, artistName, mbid, count)
|
||||||
lfErr, isLastFMError := err.(*lastfm.Error)
|
lfErr, isLastFMError := err.(*lastfm.Error)
|
||||||
if mbid != "" && (err == nil && t.Attr.Artist == "[unknown]") || (isLastFMError && lfErr.Code == 6) {
|
if mbid != "" && ((err == nil && t.Attr.Artist == "[unknown]") || (isLastFMError && lfErr.Code == 6)) {
|
||||||
log.Warn(l.ctx, "LastFM/artist.getTopTracks could not find artist by mbid, trying again", "artist", artistName, "mbid", mbid)
|
log.Warn(l.ctx, "LastFM/artist.getTopTracks could not find artist by mbid, trying again", "artist", artistName, "mbid", mbid)
|
||||||
return l.callArtistGetTopTracks(artistName, "", count)
|
return l.callArtistGetTopTracks(artistName, "", count)
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,14 @@ var _ = Describe("lastfmAgent", func() {
|
|||||||
Expect(httpClient.SavedRequest.URL.Query().Get("mbid")).To(Equal("mbid-1234"))
|
Expect(httpClient.SavedRequest.URL.Query().Get("mbid")).To(Equal("mbid-1234"))
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("MBID not existent in Last.FM", func() {
|
It("returns an error if Last.FM call returns an error 6 and mbid is empty", func() {
|
||||||
|
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
|
||||||
|
_, err := agent.GetBiography("123", "U2", "")
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
Expect(httpClient.RequestCount).To(Equal(1))
|
||||||
|
})
|
||||||
|
|
||||||
|
Context("MBID non existent in Last.FM", func() {
|
||||||
It("calls again when the response is artist == [unknown]", func() {
|
It("calls again when the response is artist == [unknown]", func() {
|
||||||
f, _ := os.Open("tests/fixtures/lastfm.artist.getinfo.unknown.json")
|
f, _ := os.Open("tests/fixtures/lastfm.artist.getinfo.unknown.json")
|
||||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||||
@ -127,7 +134,14 @@ var _ = Describe("lastfmAgent", func() {
|
|||||||
Expect(httpClient.SavedRequest.URL.Query().Get("mbid")).To(Equal("mbid-1234"))
|
Expect(httpClient.SavedRequest.URL.Query().Get("mbid")).To(Equal("mbid-1234"))
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("MBID not existent in Last.FM", func() {
|
It("returns an error if Last.FM call returns an error 6 and mbid is empty", func() {
|
||||||
|
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
|
||||||
|
_, err := agent.GetSimilar("123", "U2", "", 2)
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
Expect(httpClient.RequestCount).To(Equal(1))
|
||||||
|
})
|
||||||
|
|
||||||
|
Context("MBID non existent in Last.FM", func() {
|
||||||
It("calls again when the response is artist == [unknown]", func() {
|
It("calls again when the response is artist == [unknown]", func() {
|
||||||
f, _ := os.Open("tests/fixtures/lastfm.artist.getsimilar.unknown.json")
|
f, _ := os.Open("tests/fixtures/lastfm.artist.getsimilar.unknown.json")
|
||||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||||
@ -181,7 +195,14 @@ var _ = Describe("lastfmAgent", func() {
|
|||||||
Expect(httpClient.SavedRequest.URL.Query().Get("mbid")).To(Equal("mbid-1234"))
|
Expect(httpClient.SavedRequest.URL.Query().Get("mbid")).To(Equal("mbid-1234"))
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("MBID not existent in Last.FM", func() {
|
It("returns an error if Last.FM call returns an error 6 and mbid is empty", func() {
|
||||||
|
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
|
||||||
|
_, err := agent.GetTopSongs("123", "U2", "", 2)
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
Expect(httpClient.RequestCount).To(Equal(1))
|
||||||
|
})
|
||||||
|
|
||||||
|
Context("MBID non existent in Last.FM", func() {
|
||||||
It("calls again when the response is artist == [unknown]", func() {
|
It("calls again when the response is artist == [unknown]", func() {
|
||||||
f, _ := os.Open("tests/fixtures/lastfm.artist.gettoptracks.unknown.json")
|
f, _ := os.Open("tests/fixtures/lastfm.artist.gettoptracks.unknown.json")
|
||||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user