Fix false positives in "feat. X" detection in ftintitle

The old version of the `ftintitle.contains_feat` function could lead to
false positives by matching words like "and" and "with" in the title,
even if there was no "feat. X" part.
With this commit, the `for_artist` keyword is explicitly passed to the
`plugins.feat_tokens` function to disable these matches when matching a
title (and not an artist).
This commit is contained in:
Karl Besser 2024-09-26 17:20:12 -04:00
parent 1a59368dbf
commit c66eb10445

View file

@ -35,9 +35,15 @@ def split_on_feat(artist):
return tuple(parts)
def contains_feat(title):
def contains_feat(title, for_artist=True):
"""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=for_artist),
title,
flags=re.IGNORECASE,
)
)
def find_feat_part(artist, albumartist):
@ -143,7 +149,7 @@ class FtInTitlePlugin(plugins.BeetsPlugin):
# 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):
if not drop_feat and not contains_feat(item.title, for_artist=False):
feat_format = self.config["format"].as_str()
new_format = feat_format.format(feat_part)
new_title = f"{item.title} {new_format}"