allow templates/formatting of set_fields on import

This commit is contained in:
Duncan Overbruck 2021-10-06 15:40:03 +02:00
parent 636e36ef7a
commit 819ba735bd
No known key found for this signature in database
GPG key ID: 335C1D17EC3D6E35
4 changed files with 20 additions and 5 deletions

View file

@ -584,9 +584,9 @@ class ImportTask(BaseImportTask):
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 @@ class SingletonImportTask(ImportTask):
displayable_path(self.paths),
field,
value)
self.item[field] = value
self.item.set_parse(field, format(self.item, value))
self.item.store()

View file

@ -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 <pathformat>`.
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::

View file

@ -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 <pathformat>`.
Fields are set on both the album and each individual track of the album.
Fields are persisted to the media files of each track.

View file

@ -554,7 +554,8 @@ class ImportSingletonTest(_common.TestCase, ImportHelper):
config['import']['set_fields'] = {
'collection': collection,
'genre': genre
'genre': genre,
'title': "$title - formatted",
}
# As-is item import.
@ -566,6 +567,7 @@ class ImportSingletonTest(_common.TestCase, ImportHelper):
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 @@ class ImportSingletonTest(_common.TestCase, ImportHelper):
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 @@ class ImportTest(_common.TestCase, ImportHelper):
config['import']['set_fields'] = {
'genre': genre,
'collection': collection,
'comments': comments
'comments': comments,
'album': "$album - formatted",
}
# As-is album import.
@ -765,6 +769,9 @@ class ImportTest(_common.TestCase, ImportHelper):
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 @@ class ImportTest(_common.TestCase, ImportHelper):
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):