diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index f53191d8a..8e45d25b4 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -419,15 +419,13 @@ class Genius(Backend): return None for hit in json["response"]["hits"]: - # Genius uses zero-width characters to denote lowercase - # artist names. - hit_artist = hit["result"]["primary_artist"]["name"]. \ - strip(u'\u200b').lower() + hit_artist = hit["result"]["primary_artist"]["name"] - if hit_artist == artist.lower(): + if slug(hit_artist) == slug(artist): return self.lyrics_from_song_page(hit["result"]["url"]) - self._log.debug(u'genius: no matching artist') + self._log.debug(u'Genius failed to find a matching artist for \'{0}\'', + artist) class LyricsWiki(SymbolsReplaced): diff --git a/docs/changelog.rst b/docs/changelog.rst index 112fdf23d..cfdcb33af 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -129,6 +129,9 @@ New features: * :doc:`/plugins/plexupdate`: Add option to use secure connection to Plex server, and to ignore certificate validation errors if necessary. :bug:`2871` +* :doc:`/plugins/lyrics`: Improved searching Genius backend when artist + contained special characters. + :bug:`3634` Fixes: diff --git a/test/test_lyrics.py b/test/test_lyrics.py index d31116284..22d5f2f0c 100644 --- a/test/test_lyrics.py +++ b/test/test_lyrics.py @@ -17,6 +17,7 @@ from __future__ import absolute_import, division, print_function +import itertools import os import re import six @@ -485,18 +486,28 @@ class SlugTests(unittest.TestCase): # plain ascii passthrough text = u"test" self.assertEqual(lyrics.slug(text), 'test') + # german unicode and capitals text = u"Mørdag" self.assertEqual(lyrics.slug(text), 'mordag') + # more accents and quotes text = u"l'été c'est fait pour jouer" self.assertEqual(lyrics.slug(text), 'l-ete-c-est-fait-pour-jouer') + # accents, parens and spaces text = u"\xe7afe au lait (boisson)" self.assertEqual(lyrics.slug(text), 'cafe-au-lait-boisson') text = u"Multiple spaces -- and symbols! -- merged" self.assertEqual(lyrics.slug(text), 'multiple-spaces-and-symbols-merged') + text = u"\u200Bno-width-space" + self.assertEqual(lyrics.slug(text), 'no-width-space') + + # variations of dashes should get standardized + dashes = [u'\u200D', u'\u2010'] + for dash1, dash2 in itertools.combinations(dashes, 2): + self.assertEqual(lyrics.slug(dash1), lyrics.slug(dash2)) def suite():