Skip to content

Commit

Permalink
Use a non-capturing group by default (#1060)
Browse files Browse the repository at this point in the history
Now clients don't have to decide whether they need parentheses or not.
  • Loading branch information
sampsyo committed Dec 16, 2014
1 parent 829b623 commit a984c1a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions beets/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,11 @@ 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."""

"""Return a regular expression that matches phrases like "featuring"
that separate a main artist or a song title from secondary artists.
The `for_artist` option determines whether the regex should be
suitable for matching artist fields (the default) or title fields.
"""
feat_special_chars = ['&', 'feat.', 'ft.']
feat_words = ['ft', 'featuring', 'feat']
if for_artist: # appending to artist name enables more tokens
Expand All @@ -691,4 +694,4 @@ def feat_tokens(for_artist=True):
if for_artist:
regex = r'%s|%s' % \
('|'.join([re.escape(x) for x in feat_special_chars]), regex)
return regex
return '(?:{0})'.format(regex)

This comment has been minimized.

Copy link
@Kraymer

Kraymer Dec 16, 2014

Contributor

nifty!

4 changes: 2 additions & 2 deletions beetsplug/lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"(.*?) {0}".format(feat_tokens())
match = re.search(pattern, artist, re.IGNORECASE)
if match:
artists.append(match.group(1))
Expand All @@ -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"(.*?) {0}".format(feat_tokens(for_artist=False))
for title in titles[:]:
match = re.search(pattern, title, re.IGNORECASE)
if match:
Expand Down

0 comments on commit a984c1a

Please sign in to comment.