mirror of
https://github.com/beetbox/beets.git
synced 2026-02-24 00:02:20 +01:00
Merge pull request #3927 from bertbesser/set-fields-persist-to-tracks
persist set_fields to media files
This commit is contained in:
commit
eef26d1886
4 changed files with 42 additions and 9 deletions
|
|
@ -572,10 +572,11 @@ class ImportTask(BaseImportTask):
|
|||
util.prune_dirs(os.path.dirname(item.path),
|
||||
lib.directory)
|
||||
|
||||
def set_fields(self):
|
||||
def set_fields(self, lib):
|
||||
"""Sets the fields given at CLI or configuration to the specified
|
||||
values.
|
||||
values, for both the album and all its items.
|
||||
"""
|
||||
items = self.imported_items()
|
||||
for field, view in config['import']['set_fields'].items():
|
||||
value = view.get()
|
||||
log.debug(u'Set field {1}={2} for {0}',
|
||||
|
|
@ -583,7 +584,12 @@ class ImportTask(BaseImportTask):
|
|||
field,
|
||||
value)
|
||||
self.album[field] = value
|
||||
self.album.store()
|
||||
for item in items:
|
||||
item[field] = value
|
||||
with lib.transaction():
|
||||
for item in items:
|
||||
item.store()
|
||||
self.album.store()
|
||||
|
||||
def finalize(self, session):
|
||||
"""Save progress, clean up files, and emit plugin event.
|
||||
|
|
@ -946,9 +952,9 @@ class SingletonImportTask(ImportTask):
|
|||
def reload(self):
|
||||
self.item.load()
|
||||
|
||||
def set_fields(self):
|
||||
def set_fields(self, lib):
|
||||
"""Sets the fields given at CLI or configuration to the specified
|
||||
values.
|
||||
values, for the singleton item.
|
||||
"""
|
||||
for field, view in config['import']['set_fields'].items():
|
||||
value = view.get()
|
||||
|
|
@ -1516,7 +1522,7 @@ def apply_choice(session, task):
|
|||
# because then the ``ImportTask`` won't have an `album` for which
|
||||
# it can set the fields.
|
||||
if config['import']['set_fields']:
|
||||
task.set_fields()
|
||||
task.set_fields(session.lib)
|
||||
|
||||
|
||||
@pipeline.mutator_stage
|
||||
|
|
|
|||
|
|
@ -218,6 +218,8 @@ Other new things:
|
|||
``check_on_import`` config option.
|
||||
* :doc:`/plugins/export`: big speedups when `--include-keys` option is used
|
||||
Thanks to :user:`ssssam`.
|
||||
* The `importer` persists all fields set using :ref:`set_fields` to the
|
||||
mediafiles of all imported tracks.
|
||||
* Added 7z support via the `py7zr`_ library
|
||||
Thanks to :user:`arogl`. :bug:`3906`
|
||||
* Get ISRC identifiers from musicbrainz
|
||||
|
|
|
|||
|
|
@ -683,6 +683,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.
|
||||
|
||||
Fields are set on both the album and each individual track of the album.
|
||||
Fields are persisted to the media files of each track.
|
||||
|
||||
Default: ``{}`` (empty).
|
||||
|
||||
.. _musicbrainz-config:
|
||||
|
|
|
|||
|
|
@ -740,10 +740,12 @@ class ImportTest(_common.TestCase, ImportHelper):
|
|||
def test_set_fields(self):
|
||||
genre = u"\U0001F3B7 Jazz"
|
||||
collection = u"To Listen"
|
||||
comments = u"managed by beets"
|
||||
|
||||
config['import']['set_fields'] = {
|
||||
u'genre': genre,
|
||||
u'collection': collection,
|
||||
u'genre': genre
|
||||
u'comments': comments
|
||||
}
|
||||
|
||||
# As-is album import.
|
||||
|
|
@ -754,7 +756,17 @@ class ImportTest(_common.TestCase, ImportHelper):
|
|||
for album in self.lib.albums():
|
||||
album.load() # TODO: Not sure this is necessary.
|
||||
self.assertEqual(album.genre, genre)
|
||||
self.assertEqual(album.collection, collection)
|
||||
self.assertEqual(album.comments, comments)
|
||||
for item in album.items():
|
||||
self.assertEqual(
|
||||
item.get("genre", with_album=False),
|
||||
genre)
|
||||
self.assertEqual(
|
||||
item.get("collection", with_album=False),
|
||||
collection)
|
||||
self.assertEqual(
|
||||
item.get("comments", with_album=False),
|
||||
comments)
|
||||
# Remove album from library to test again with APPLY choice.
|
||||
album.remove()
|
||||
|
||||
|
|
@ -767,7 +779,17 @@ class ImportTest(_common.TestCase, ImportHelper):
|
|||
for album in self.lib.albums():
|
||||
album.load()
|
||||
self.assertEqual(album.genre, genre)
|
||||
self.assertEqual(album.collection, collection)
|
||||
self.assertEqual(album.comments, comments)
|
||||
for item in album.items():
|
||||
self.assertEqual(
|
||||
item.get("genre", with_album=False),
|
||||
genre)
|
||||
self.assertEqual(
|
||||
item.get("collection", with_album=False),
|
||||
collection)
|
||||
self.assertEqual(
|
||||
item.get("comments", with_album=False),
|
||||
comments)
|
||||
|
||||
|
||||
class ImportTracksTest(_common.TestCase, ImportHelper):
|
||||
|
|
|
|||
Loading…
Reference in a new issue