Skip to content

Commit

Permalink
ftintitle: Fix false positives in "feat. X" detection in title (#5442)
Browse files Browse the repository at this point in the history
Fixes #5441 

This small change explicitly passes the `for_artist` keyword to the
`plugins.feat_tokens` function that constructs the regex for matching
existing "feat. X" parts in song titles.
Previously, it was not passed and set to the default (`True`), which
caused using the pattern intended for the artist field to also be used
for the title field.
This caused some false positives as shown in #5441
  • Loading branch information
snejus authored Oct 1, 2024
2 parents 04ee041 + 37879d0 commit 03f1205
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 7 additions & 1 deletion beetsplug/ftintitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ def split_on_feat(artist):

def contains_feat(title):
"""Determine whether the title contains a "featured" marker."""
return bool(re.search(plugins.feat_tokens(), title, flags=re.IGNORECASE))
return bool(
re.search(
plugins.feat_tokens(for_artist=False),
title,
flags=re.IGNORECASE,
)
)


def find_feat_part(artist, albumartist):
Expand Down
4 changes: 3 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ New features:

Bug fixes:

* The detection of a "feat. X" part now also matches such parts if they are in
* :doc:`plugins/ftintitle`: The detection of a "feat. X" part in a song title does not produce any false
positives caused by words like "and" or "with" anymore. :bug:`5441`
* :doc:`plugins/ftintitle`: The detection of a "feat. X" part now also matches such parts if they are in
parentheses or brackets. :bug:`5436`
* Improve naming of temporary files by separating the random part with the file extension.
* Fix the ``auto`` value for the :ref:`reflink` config option.
Expand Down
5 changes: 2 additions & 3 deletions test/plugins/test_ftintitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,12 @@ def test_contains_feat(self):
assert ftintitle.contains_feat("Alice feat. Bob")
assert ftintitle.contains_feat("Alice feat Bob")
assert ftintitle.contains_feat("Alice featuring Bob")
assert ftintitle.contains_feat("Alice & Bob")
assert ftintitle.contains_feat("Alice and Bob")
assert ftintitle.contains_feat("Alice With Bob")
assert ftintitle.contains_feat("Alice (ft. Bob)")
assert ftintitle.contains_feat("Alice (feat. Bob)")
assert ftintitle.contains_feat("Alice [ft. Bob]")
assert ftintitle.contains_feat("Alice [feat. Bob]")
assert not ftintitle.contains_feat("Alice defeat Bob")
assert not ftintitle.contains_feat("Aliceft.Bob")
assert not ftintitle.contains_feat("Alice (defeat Bob)")
assert not ftintitle.contains_feat("Live and Let Go")
assert not ftintitle.contains_feat("Come With Me")

0 comments on commit 03f1205

Please sign in to comment.