From c1fb32cedb74f51001dade7883ae1ae350a2dade Mon Sep 17 00:00:00 2001 From: Deluan Date: Mon, 26 Oct 2020 23:33:06 -0400 Subject: [PATCH] Replace unicode quotes and dash with simple ascii chars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit External services do not use these unicode chars. Ex: - “Weird Al” Yankovic - Bachman–Turner Overdrive - The Go‐Go’s are not found in Last.FM and Spotify --- core/external_info.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/external_info.go b/core/external_info.go index 2bf3b1c9d..87c93c141 100644 --- a/core/external_info.go +++ b/core/external_info.go @@ -59,10 +59,23 @@ func (e *externalInfo) getArtist(ctx context.Context, id string) (artist *model. } default: err = model.ErrNotFound + return } + artist.Name = clearName(artist.Name) return } +// Replace some Unicode chars with their equivalent ASCII +func clearName(name string) string { + name = strings.ReplaceAll(name, "–", "-") + name = strings.ReplaceAll(name, "‐", "-") + name = strings.ReplaceAll(name, "“", `"`) + name = strings.ReplaceAll(name, "”", `"`) + name = strings.ReplaceAll(name, "‘", `'`) + name = strings.ReplaceAll(name, "’", `'`) + return name +} + func (e *externalInfo) SimilarSongs(ctx context.Context, id string, count int) (model.MediaFiles, error) { if e.lfm == nil { log.Warn(ctx, "Last.FM client not configured") @@ -132,6 +145,7 @@ func (e *externalInfo) TopSongs(ctx context.Context, artistName string, count in log.Error(ctx, "Artist not found", "name", artistName, err) return nil, nil } + artistName = clearName(artistName) log.Debug(ctx, "Calling Last.FM ArtistGetTopTracks", "artist", artistName, "id", artist.ID) tracks, err := e.lfm.ArtistGetTopTracks(ctx, artistName, count)