Merge pull request #1911 from jackwilsdon/fix-musixmatch-url

Fix MusixMatch issues
This commit is contained in:
Adrian Sampson 2016-03-18 11:51:27 -04:00
commit c9be5bc7d1
2 changed files with 19 additions and 7 deletions

View file

@ -200,18 +200,28 @@ class Backend(object):
class SymbolsReplaced(Backend):
REPLACEMENTS = {
r'\s+': '_',
'<': 'Less_Than',
'>': 'Greater_Than',
'#': 'Number_',
r'[\[\{]': '(',
r'[\[\{]': ')'
}
@classmethod
def _encode(cls, s):
s = re.sub(r'\s+', '_', s)
s = s.replace("<", "Less_Than")
s = s.replace(">", "Greater_Than")
s = s.replace("#", "Number_")
s = re.sub(r'[\[\{]', '(', s)
s = re.sub(r'[\]\}]', ')', s)
for old, new in cls.REPLACEMENTS.iteritems():
s = re.sub(old, new, s)
return super(SymbolsReplaced, cls)._encode(s)
class MusiXmatch(SymbolsReplaced):
REPLACEMENTS = dict(SymbolsReplaced.REPLACEMENTS, **{
r'\s+': '-'
})
URL_PATTERN = 'https://www.musixmatch.com/lyrics/%s/%s'
def fetch(self, artist, title):
@ -220,7 +230,7 @@ class MusiXmatch(SymbolsReplaced):
if not html:
return
lyrics = extract_text_between(html,
'"lyrics_body":', '"lyrics_language":')
'"body":', '"language":')
return lyrics.strip(',"').replace('\\n', '\n')

View file

@ -20,6 +20,8 @@ Fixes:
could undo the ``id3v23`` setting. :bug:`1903`
* :doc:`/plugins/lyrics`: Add compatibility with some changes to the
LyricsWiki page markup. :bug:`1912` :bug:`1909`
* :doc:`/plugins/lyrics`: Also fix retrieval from Musixmatch and the way we
guess the URL for lyrics. :bug:`1880`
1.3.17 (February 7, 2016)