From 8c60d2b9600662d593b57024ee1f1e206153b0e5 Mon Sep 17 00:00:00 2001 From: Karl Besser Date: Fri, 20 Sep 2024 22:59:59 -0400 Subject: [PATCH 1/4] Add parentheses as delimiters for feat. detection When checking whether a title or artist contains a feature, it now also detects them when they are in parentheses or brackets, i.e., "Song Name (feat. XYZ)" will return true. --- beets/plugins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beets/plugins.py b/beets/plugins.py index 0864c4b9b0..fba321f43d 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -518,7 +518,7 @@ def feat_tokens(for_artist=True): feat_words = ["ft", "featuring", "feat", "feat.", "ft."] if for_artist: feat_words += ["with", "vs", "and", "con", "&"] - return r"(?<=\s)(?:{})(?=\s)".format( + return r"(?<=[\s,(,\[])(?:{})(?=\s)".format( "|".join(re.escape(x) for x in feat_words) ) From 6c8bd424e8cc308351a9c145107d116ffa146dd9 Mon Sep 17 00:00:00 2001 From: Karl Besser Date: Sun, 22 Sep 2024 18:30:28 -0400 Subject: [PATCH 2/4] Add unit tests to test new feat. X detection regex The previous version of the `plugins.feat_tokens` regular expression only matched "feat. X" parts if preceded by a space. This caused missed detections in the `ftintitle.contains_feat` function. This commit adds unit tests for the updated regex that also matches "feat. X" parts within parentheses and brackets --- test/plugins/test_ftintitle.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/plugins/test_ftintitle.py b/test/plugins/test_ftintitle.py index 45146b42b7..9e8f14fe1a 100644 --- a/test/plugins/test_ftintitle.py +++ b/test/plugins/test_ftintitle.py @@ -183,5 +183,10 @@ def test_contains_feat(self): 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)") From 3942753a631206a8ead3944ed93aba216bb11f63 Mon Sep 17 00:00:00 2001 From: Karl Besser Date: Mon, 23 Sep 2024 12:26:51 -0400 Subject: [PATCH 3/4] Delete unnecessary comma in feat detection regex --- beets/plugins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beets/plugins.py b/beets/plugins.py index fba321f43d..299c418157 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -518,7 +518,7 @@ def feat_tokens(for_artist=True): feat_words = ["ft", "featuring", "feat", "feat.", "ft."] if for_artist: feat_words += ["with", "vs", "and", "con", "&"] - return r"(?<=[\s,(,\[])(?:{})(?=\s)".format( + return r"(?<=[\s(\[])(?:{})(?=\s)".format( "|".join(re.escape(x) for x in feat_words) ) From 5aa96aad17cbfcf1e10743ed20f5e52aa529d775 Mon Sep 17 00:00:00 2001 From: Karl Besser Date: Mon, 23 Sep 2024 12:31:02 -0400 Subject: [PATCH 4/4] Add changelog entry about new "feat. X" matching --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 38e7642264..33a4b5f94d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -26,6 +26,8 @@ New features: Bug fixes: +* 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. * Fix lyrics plugin only getting part of the lyrics from ``Genius.com`` :bug:`4815`