diff --git a/beets/importer.py b/beets/importer.py index 561cedd2c6..35eaf70653 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -584,9 +584,9 @@ def set_fields(self, lib): displayable_path(self.paths), field, value) - self.album[field] = value + self.album.set_parse(field, format(self.album, value)) for item in items: - item[field] = value + item.set_parse(field, format(item, value)) with lib.transaction(): for item in items: item.store() @@ -963,7 +963,7 @@ def set_fields(self, lib): displayable_path(self.paths), field, value) - self.item[field] = value + self.item.set_parse(field, format(self.item, value)) self.item.store() diff --git a/docs/reference/cli.rst b/docs/reference/cli.rst index d3d5474aad..c2519eda91 100644 --- a/docs/reference/cli.rst +++ b/docs/reference/cli.rst @@ -145,6 +145,8 @@ Optional command flags: Multiple IDs can be specified by simply repeating the option several times. * You can supply ``--set field=value`` to assign `field` to `value` on import. + Values support the same template syntax as beets' + :doc:`path formats `. These assignments will merge with (and possibly override) the :ref:`set_fields` configuration dictionary. You can use the option multiple times on the command line, like so:: diff --git a/docs/reference/config.rst b/docs/reference/config.rst index 642216c8f7..30fdefa832 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -706,6 +706,9 @@ Here's an example:: Other field/value pairs supplied via the ``--set`` option on the command-line override any settings here for fields with the same name. +Values support the same template syntax as beets' +:doc:`path formats `. + Fields are set on both the album and each individual track of the album. Fields are persisted to the media files of each track. diff --git a/test/test_importer.py b/test/test_importer.py index 306491af2c..9ec6043940 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -554,7 +554,8 @@ def test_set_fields(self): config['import']['set_fields'] = { 'collection': collection, - 'genre': genre + 'genre': genre, + 'title': "$title - formatted", } # As-is item import. @@ -566,6 +567,7 @@ def test_set_fields(self): item.load() # TODO: Not sure this is necessary. self.assertEqual(item.genre, genre) self.assertEqual(item.collection, collection) + self.assertEqual(item.title, "Tag Title 1 - formatted") # Remove item from library to test again with APPLY choice. item.remove() @@ -579,6 +581,7 @@ def test_set_fields(self): item.load() self.assertEqual(item.genre, genre) self.assertEqual(item.collection, collection) + self.assertEqual(item.title, "Applied Title 1 - formatted") class ImportTest(_common.TestCase, ImportHelper): @@ -743,7 +746,8 @@ def test_set_fields(self): config['import']['set_fields'] = { 'genre': genre, 'collection': collection, - 'comments': comments + 'comments': comments, + 'album': "$album - formatted", } # As-is album import. @@ -765,6 +769,9 @@ def test_set_fields(self): self.assertEqual( item.get("comments", with_album=False), comments) + self.assertEqual( + item.get("album", with_album=False), + "Tag Album - formatted") # Remove album from library to test again with APPLY choice. album.remove() @@ -788,6 +795,9 @@ def test_set_fields(self): self.assertEqual( item.get("comments", with_album=False), comments) + self.assertEqual( + item.get("album", with_album=False), + "Applied Album - formatted") class ImportTracksTest(_common.TestCase, ImportHelper):