Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ftintitle: Fix false positives in "feat. X" detection in title #5442

Merged
merged 8 commits into from
Oct 1, 2024
6 changes: 3 additions & 3 deletions beetsplug/ftintitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def split_on_feat(artist):
return tuple(parts)


def contains_feat(title, for_artist=True):
def contains_feat(title):
"""Determine whether the title contains a "featured" marker."""
return bool(
re.search(
plugins.feat_tokens(for_artist=for_artist),
plugins.feat_tokens(for_artist=False),
title,
flags=re.IGNORECASE,
)
Expand Down Expand Up @@ -149,7 +149,7 @@ def update_metadata(self, item, feat_part, drop_feat, keep_in_artist_field):

# Only update the title if it does not already contain a featured
# artist and if we do not drop featuring information.
if not drop_feat and not contains_feat(item.title, for_artist=False):
if not drop_feat and not contains_feat(item.title):
feat_format = self.config["format"].as_str()
new_format = feat_format.format(feat_part)
new_title = f"{item.title} {new_format}"
Expand Down
4 changes: 2 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ New features:

Bug fixes:

* The detection of a "feat. X" part in a song title does not produce any false
* :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`
* 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 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
23 changes: 6 additions & 17 deletions test/plugins/test_ftintitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,31 +175,20 @@ def test_split_on_feat(self):
parts = ftintitle.split_on_feat("Alice defeat Bob")
assert parts == ("Alice defeat Bob", None)

def test_contains_feat_artist(self):
def test_contains_feat(self):
assert ftintitle.contains_feat("Alice ft. Bob")
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)")

def test_contains_feat_title(self):
assert ftintitle.contains_feat(
"Live and Let Go (feat. Alice)", for_artist=False
)
assert ftintitle.contains_feat(
"Live and Let Go [feat. Alice]", for_artist=False
)
assert ftintitle.contains_feat(
"Live and Let Go feat. Alice", for_artist=False
)
assert not ftintitle.contains_feat("Live and Let Go", for_artist=False)
assert not ftintitle.contains_feat("Come With Me", for_artist=False)
assert ftintitle.contains_feat("Live and Let Go (feat. Alice)")
klb2 marked this conversation as resolved.
Show resolved Hide resolved
assert ftintitle.contains_feat("Live and Let Go [feat. Alice]")
assert ftintitle.contains_feat("Live and Let Go feat. Alice")
assert not ftintitle.contains_feat("Live and Let Go")
assert not ftintitle.contains_feat("Come With Me")
Loading