From 44c799320fcf1e3d10fd4368db776fa786f0cb1d Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Wed, 16 Mar 2016 20:46:25 +0000 Subject: [PATCH 1/4] Improve URL generation in lyrics plugin Allow custom replacements to be defined in subclasses of SymbolsReplaced. Replace spaces with a hyphens when the source is MusiXmatch, instead of (incorrectly) using underscores. This fixes #1880. --- beetsplug/lyrics.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 66b859f59..c7ce64584 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -200,18 +200,27 @@ 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): From 1ec06e14c52ea883f2aa770c4d99a16de66d1aeb Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Wed, 16 Mar 2016 20:48:57 +0000 Subject: [PATCH 2/4] Fix lyrics extraction from MusiXmatch Remove "lyrics_" prefix from extract_text_between arguments to reflect changes made to the MusiXmatch website. --- beetsplug/lyrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index c7ce64584..c921081e7 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -229,7 +229,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') From c41700318464fc7621f5fc72edded7978fac016e Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Wed, 16 Mar 2016 21:07:28 +0000 Subject: [PATCH 3/4] Add missing newline --- beetsplug/lyrics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index c921081e7..37cbb9739 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -216,6 +216,7 @@ class SymbolsReplaced(Backend): return super(SymbolsReplaced, cls)._encode(s) + class MusiXmatch(SymbolsReplaced): REPLACEMENTS = dict(SymbolsReplaced.REPLACEMENTS, **{ r'\s+': '-' From 0689279e6733942fee4780a04f81976858d21782 Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Thu, 17 Mar 2016 14:49:01 +0000 Subject: [PATCH 4/4] Update changelog to reflect changes to lyrics plugin --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 22d2c7226..79425ad24 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -18,6 +18,8 @@ Fixes: password in the ``beet config`` output. :bug:`1907` * :doc:`/plugins/scrub`: Fix an occasional problem where scrubbing on import could undo the ``id3v23`` setting. :bug:`1903` +* :doc:`/plugins/lyrics`: Fix lyric retrieval for MusixMatch and improve URL + generation. :bug:`1880` 1.3.17 (February 7, 2016)