Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions beetsplug/ftintitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,23 @@ def split_on_feat(
artist, which is always a string, and the featuring artist, which
may be a string or None if none is present.
"""
# split on the first "feat".
regex = re.compile(
plugins.feat_tokens(for_artist, custom_words), re.IGNORECASE
# Try explicit featuring tokens first (ft, feat, featuring, etc.)
# to avoid splitting on generic separators like "&" when both are present
regex_explicit = re.compile(
plugins.feat_tokens(for_artist=False, custom_words=custom_words),
re.IGNORECASE,
)
parts = tuple(s.strip() for s in regex.split(artist, 1))
parts = tuple(s.strip() for s in regex_explicit.split(artist, 1))
if len(parts) == 2:
Comment on lines +45 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): When for_artist is False we no longer fall back to generic tokens, which changes previous behavior.

Previously, both artist and non-artist paths used feat_tokens(for_artist, custom_words), so generic separators were still applied when no explicit featuring token was present. Now, when for_artist is False and there’s no explicit feat/ft token, the generic-token regex is never used and we always return (artist, None). If you only want to avoid over-splitting the artist field, consider preserving the generic fallback for the non-artist case by moving that logic outside if for_artist: or adding an else that calls feat_tokens(False, custom_words).

return parts

# Fall back to all tokens including generic separators if no explicit match
if for_artist:
regex = re.compile(
plugins.feat_tokens(for_artist, custom_words), re.IGNORECASE
)
parts = tuple(s.strip() for s in regex.split(artist, 1))

if len(parts) == 1:
return parts[0], None
else:
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ Bug fixes:
"albumartist" instead of a list of unique album artists.
- Sanitize log messages by removing control characters preventing terminal
rendering issues.
- :doc:`/plugins/ftintitle`: Fixed artist name splitting to prioritize explicit
featuring tokens (feat, ft, featuring) over generic separators (&, and),
preventing incorrect splits when both are present.

For plugin developers:

Expand Down
4 changes: 4 additions & 0 deletions test/plugins/test_ftintitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ def test_find_feat_part(
("Alice and Bob", ("Alice", "Bob")),
("Alice With Bob", ("Alice", "Bob")),
("Alice defeat Bob", ("Alice defeat Bob", None)),
("Alice & Bob feat Charlie", ("Alice & Bob", "Charlie")),
("Alice & Bob ft. Charlie", ("Alice & Bob", "Charlie")),
("Alice & Bob featuring Charlie", ("Alice & Bob", "Charlie")),
("Alice and Bob feat Charlie", ("Alice and Bob", "Charlie")),
],
)
def test_split_on_feat(
Expand Down