diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 234b564af..dd63983b5 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -683,12 +683,12 @@ def max_filename_length(path, limit=MAX_FILENAME_LENGTH): def feat_tokens(for_artist=True): """Returns the tokens to use to detect featuring artists in strings.""" - FEAT_SPECIAL_CHARS = ['&', 'feat.', 'ft.'] - FEAT_WORDS = ['ft', 'featuring', 'feat'] + feat_special_chars = ['&', 'feat.', 'ft.'] + feat_words = ['ft', 'featuring', 'feat'] if for_artist: # appending to artist name enables more tokens - FEAT_WORDS += ['with', 'vs', 'and', 'con'] - regex = r'(%s)' % '|'.join(['\\b%s\\b' % re.escape(x) for x in FEAT_WORDS]) + feat_words += ['with', 'vs', 'and', 'con'] + regex = r'%s' % '|'.join(['\\b%s\\b' % re.escape(x) for x in feat_words]) if for_artist: - regex = r'(%s|%s)' % \ - ('|'.join([re.escape(x) for x in FEAT_SPECIAL_CHARS]), regex) + regex = r'%s|%s' % \ + ('|'.join([re.escape(x) for x in feat_special_chars]), regex) return regex diff --git a/beetsplug/ftintitle.py b/beetsplug/ftintitle.py index 96d1f54c9..e83836e0e 100644 --- a/beetsplug/ftintitle.py +++ b/beetsplug/ftintitle.py @@ -31,7 +31,7 @@ def split_on_feat(artist): may be a string or None if none is present. """ # split on the first "feat". - regex = re.compile(feat_tokens().translate(None, '()'), re.IGNORECASE) + regex = re.compile(feat_tokens(), re.IGNORECASE) parts = [s.strip() for s in regex.split(artist, 1)] if len(parts) == 1: return parts[0], None diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index a90e3d645..976aaf5c5 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -138,7 +138,7 @@ def search_pairs(item): artists = [artist] # Remove any featuring artists from the artists name - pattern = r"(.*?) %s" % feat_tokens() + pattern = r"(.*?) (%s)" % feat_tokens() match = re.search(pattern, artist, re.IGNORECASE) if match: artists.append(match.group(1)) @@ -151,7 +151,7 @@ def search_pairs(item): titles.append(match.group(1)) # Remove any featuring artists from the title - pattern = r"(.*?) %s" % feat_tokens(for_artist=False) + pattern = r"(.*?) (%s)" % feat_tokens(for_artist=False) for title in titles[:]: match = re.search(pattern, title, re.IGNORECASE) if match: