mirror of
https://github.com/beetbox/beets.git
synced 2026-01-09 17:33:51 +01:00
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.
This commit is contained in:
parent
8a0b18c960
commit
44c799320f
1 changed files with 16 additions and 7 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue