From c046dc3976b391845030ef08210e1f60c1e5026a Mon Sep 17 00:00:00 2001 From: Karl Besser Date: Tue, 9 Jul 2024 23:49:20 -0400 Subject: [PATCH 1/7] Add new keep_in_artist option for ftintitle plugin The new keep_in_artist option allows keeping the feat. part in the artist metadata field while still changing the title. --- beetsplug/ftintitle.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/beetsplug/ftintitle.py b/beetsplug/ftintitle.py index 2ba94c333..0a404c29c 100644 --- a/beetsplug/ftintitle.py +++ b/beetsplug/ftintitle.py @@ -78,6 +78,7 @@ class FtInTitlePlugin(plugins.BeetsPlugin): "auto": True, "drop": False, "format": "feat. {0}", + "keep_in_artist": False, } ) @@ -101,10 +102,11 @@ class FtInTitlePlugin(plugins.BeetsPlugin): def func(lib, opts, args): self.config.set_args(opts) drop_feat = self.config["drop"].get(bool) + keep_in_artist_field = self.config["keep_in_artist"].get(bool) write = ui.should_write() for item in lib.items(ui.decargs(args)): - self.ft_in_title(item, drop_feat) + self.ft_in_title(item, drop_feat, keep_in_artist_field) item.store() if write: item.try_write() @@ -120,15 +122,19 @@ class FtInTitlePlugin(plugins.BeetsPlugin): self.ft_in_title(item, drop_feat) item.store() - def update_metadata(self, item, feat_part, drop_feat): + def update_metadata(self, item, feat_part, drop_feat, keep_in_artist_field): """Choose how to add new artists to the title and set the new metadata. Also, print out messages about any changes that are made. If `drop_feat` is set, then do not add the artist to the title; just remove it from the artist field. """ - # In all cases, update the artist fields. - self._log.info("artist: {0} -> {1}", item.artist, item.albumartist) - item.artist = item.albumartist + # In case the artist is kept, do not update the artist fields. + if keep_in_artist_field: + self._log.info("artist: {0} -> {1}", item.artist, item.artist) + else: + self._log.info("artist: {0} -> {1}", item.artist, item.albumartist) + item.artist = item.albumartist + if item.artist_sort: # Just strip the featured artist from the sort name. item.artist_sort, _ = split_on_feat(item.artist_sort) @@ -142,7 +148,7 @@ class FtInTitlePlugin(plugins.BeetsPlugin): self._log.info("title: {0} -> {1}", item.title, new_title) item.title = new_title - def ft_in_title(self, item, drop_feat): + def ft_in_title(self, item, drop_feat, keep_in_artist_field): """Look for featured artists in the item's artist fields and move them to the title. """ @@ -163,6 +169,8 @@ class FtInTitlePlugin(plugins.BeetsPlugin): # If we have a featuring artist, move it to the title. if feat_part: - self.update_metadata(item, feat_part, drop_feat) + self.update_metadata( + item, feat_part, drop_feat, keep_in_artist_field + ) else: self._log.info("no featuring artists found") From 43304a9eaa601e337503d518ab4a44b8243cb79b Mon Sep 17 00:00:00 2001 From: Karl Besser Date: Tue, 9 Jul 2024 23:53:12 -0400 Subject: [PATCH 2/7] Add keep_artist_in_title to changelog --- docs/changelog.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index f02ba8980..d318d8748 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -12,6 +12,9 @@ New features: `beet list -a title:something` or `beet list artpath:cover`. Consequently album queries involving `path` field have been sped up, like `beet list -a path:/path/`. +* New `keep_in_artist` option for the :doc:`plugins/ftintitle` plugin, which + allows keeping the "feat." part in the artist metadata while still changing + the title. Bug fixes: From acb4680c72dcb7206f8c7924bcdcd686077c8440 Mon Sep 17 00:00:00 2001 From: Karl Besser Date: Tue, 9 Jul 2024 23:55:33 -0400 Subject: [PATCH 3/7] Add keep_in_artist option to ftintitle documentation --- docs/plugins/ftintitle.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/plugins/ftintitle.rst b/docs/plugins/ftintitle.rst index 66c9ecd69..920a2cf42 100644 --- a/docs/plugins/ftintitle.rst +++ b/docs/plugins/ftintitle.rst @@ -27,6 +27,8 @@ file. The available options are: - **format**: Defines the format for the featuring X part of the new title field. In this format the ``{0}`` is used to define where the featured artists are placed. Default: ``feat. {0}`` +- **keep_in_artist**: Keep the featuring X part in the artist field. + Defailt: ``no``. Running Manually ---------------- From b8bd504324883452ea3177f56386f04f1a9bb5b7 Mon Sep 17 00:00:00 2001 From: Karl Besser Date: Wed, 10 Jul 2024 10:47:29 -0400 Subject: [PATCH 4/7] Add tests for keep_in_artist option in ftintitle Add functionality tests for the new keep_in_artist option of the ftintitle plugin. --- test/plugins/test_ftintitle.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/plugins/test_ftintitle.py b/test/plugins/test_ftintitle.py index 60dd3668e..650d19d4a 100644 --- a/test/plugins/test_ftintitle.py +++ b/test/plugins/test_ftintitle.py @@ -40,10 +40,13 @@ class FtInTitlePluginFunctional(unittest.TestCase, TestHelper): albumartist=aartist, ) - def _ft_set_config(self, ftformat, drop=False, auto=True): + def _ft_set_config( + self, ftformat, drop=False, auto=True, keep_in_artist=False + ): self.config["ftintitle"]["format"] = ftformat self.config["ftintitle"]["drop"] = drop self.config["ftintitle"]["auto"] = auto + self.config["ftintitle"]["keep_in_artist"] = keep_in_artist def test_functional_drop(self): item = self._ft_add_item("/", "Alice ft Bob", "Song 1", "Alice") @@ -82,6 +85,20 @@ class FtInTitlePluginFunctional(unittest.TestCase, TestHelper): self.assertEqual(item["artist"], "Alice") self.assertEqual(item["title"], "Song 1 with Bob") + def test_functional_keep_in_artist(self): + self._ft_set_config("feat. {0}", keep_in_artist=True) + item = self._ft_add_item("/", "Alice ft Bob", "Song 1", "Alice") + self.run_command("ftintitle") + item.load() + self.assertEqual(item["artist"], "Alice ft Bob") + self.assertEqual(item["title"], "Song 1 feat. Bob") + + item = self._ft_add_item("/", "Alice ft Bob", "Song 1", "Alice") + self.run_command("ftintitle", "-d") + item.load() + self.assertEqual(item["artist"], "Alice ft Bob") + self.assertEqual(item["title"], "Song 1") + class FtInTitlePluginTest(unittest.TestCase): def setUp(self): From a11b557a6d688fa4f1913e0cc6a7fbe393664c18 Mon Sep 17 00:00:00 2001 From: Karl Besser Date: Wed, 10 Jul 2024 13:05:58 -0400 Subject: [PATCH 5/7] Fix typo in docs --- docs/plugins/ftintitle.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plugins/ftintitle.rst b/docs/plugins/ftintitle.rst index 920a2cf42..75b77b65f 100644 --- a/docs/plugins/ftintitle.rst +++ b/docs/plugins/ftintitle.rst @@ -28,7 +28,7 @@ file. The available options are: In this format the ``{0}`` is used to define where the featured artists are placed. Default: ``feat. {0}`` - **keep_in_artist**: Keep the featuring X part in the artist field. - Defailt: ``no``. + Default: ``no``. Running Manually ---------------- From aa891d21d4cc03fdfab0aaf98b86e31d33be1db3 Mon Sep 17 00:00:00 2001 From: Karl Besser Date: Thu, 5 Sep 2024 12:15:53 +0200 Subject: [PATCH 6/7] Add example use case of keep_artist option to docs Update the documentation of the new `keep_in_artist` option, adding an example use case. --- docs/plugins/ftintitle.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/plugins/ftintitle.rst b/docs/plugins/ftintitle.rst index 75b77b65f..63d023dc9 100644 --- a/docs/plugins/ftintitle.rst +++ b/docs/plugins/ftintitle.rst @@ -27,7 +27,9 @@ file. The available options are: - **format**: Defines the format for the featuring X part of the new title field. In this format the ``{0}`` is used to define where the featured artists are placed. Default: ``feat. {0}`` -- **keep_in_artist**: Keep the featuring X part in the artist field. +- **keep_in_artist**: Keep the featuring X part in the artist field. This can + be useful if you still want to be able to search for features in the artist + field. Default: ``no``. Running Manually From 15d652dbaee09a176fb29a54d036549e87d4148f Mon Sep 17 00:00:00 2001 From: Karl Besser Date: Thu, 5 Sep 2024 12:28:51 +0200 Subject: [PATCH 7/7] Update log message for keeping artist in ftintitle Update the log message when the artist is kept unchanged due to setting the keep_in_artist option to true. --- beetsplug/ftintitle.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/beetsplug/ftintitle.py b/beetsplug/ftintitle.py index 0a404c29c..8936f049b 100644 --- a/beetsplug/ftintitle.py +++ b/beetsplug/ftintitle.py @@ -130,7 +130,9 @@ class FtInTitlePlugin(plugins.BeetsPlugin): """ # In case the artist is kept, do not update the artist fields. if keep_in_artist_field: - self._log.info("artist: {0} -> {1}", item.artist, item.artist) + self._log.info( + "artist: {0} (Not changing due to keep_in_artist)", item.artist + ) else: self._log.info("artist: {0} -> {1}", item.artist, item.albumartist) item.artist = item.albumartist