Merge pull request #3635 from jtpavlock/master

Fix genius lyrics backend artist matching with hyphens
This commit is contained in:
Adrian Sampson 2020-06-27 19:38:26 -04:00 committed by GitHub
commit 3e32a4fb87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 6 deletions

View file

@ -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):

View file

@ -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:

View file

@ -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():