From c66eb1044549cc3ebd3d1ca98dde899ea910c93c Mon Sep 17 00:00:00 2001 From: Karl Besser Date: Thu, 26 Sep 2024 17:20:12 -0400 Subject: [PATCH] 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). --- beetsplug/ftintitle.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/beetsplug/ftintitle.py b/beetsplug/ftintitle.py index 5bc018fe1..2c4634002 100644 --- a/beetsplug/ftintitle.py +++ b/beetsplug/ftintitle.py @@ -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}"