From 569098a31804a72529e25d3a3a47cd9df7d1bb51 Mon Sep 17 00:00:00 2001 From: Bart Kleijngeld Date: Tue, 30 May 2017 16:56:33 +0200 Subject: [PATCH] store_dict parser action now stores unicode, and implementend set_fields functionality in importer --- beets/importer.py | 28 +++++++++++++++++++++++++++- beets/ui/__init__.py | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/beets/importer.py b/beets/importer.py index ce9ebc01c..801e0cdca 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -419,7 +419,7 @@ class ImportTask(BaseImportTask): from the `candidates` list. * `find_duplicates()` Returns a list of albums from `lib` with the - same artist and album name as the task. + same artist and album name as the task. * `apply_metadata()` Sets the attributes of the items from the task's `match` attribute. @@ -429,6 +429,9 @@ class ImportTask(BaseImportTask): * `manipulate_files()` Copy, move, and write files depending on the session configuration. + * `set_fields()` Sets the fields given at CLI or configuration to + the specified values. + * `finalize()` Update the import progress and cleanup the file system. """ @@ -529,6 +532,14 @@ class ImportTask(BaseImportTask): util.remove(item.path) util.prune_dirs(os.path.dirname(item.path), lib.directory) + def set_fields(self): + set_fields_dict = config['import']['set_fields'] + for field in set_fields_dict.keys(): + print(type(set_fields_dict[field].get())) + value = set_fields_dict[field].get() + log.debug(u'Set field {1}={2} for {0}', displayable_path(self.paths), field, value) + self.album[field] = value + self.album.store() def finalize(self, session): """Save progress, clean up files, and emit plugin event. @@ -877,6 +888,16 @@ class SingletonImportTask(ImportTask): def reload(self): self.item.load() + def set_fields(self): + """Similar to ``ImportTask.set_fields``, but for singleton items. + """ + set_fields_dict = config['import']['set_fields'] + for field in set_fields_dict.keys(): + value = set_fields_dict[field].get() + log.debug(u'Set field {1}={2} for {0}', displayable_path(self.paths), field, value) + self.item[field] = value + self.item.store() + # FIXME The inheritance relationships are inverted. This is why there # are so many methods which pass. More responsibility should be delegated to @@ -1385,6 +1406,11 @@ def apply_choice(session, task): task.add(session.lib) + # If ``set_fields`` is set, set those fields to the + # configured values. + if config['import']['set_fields']: + task.set_fields() + @pipeline.mutator_stage def plugin_stage(session, func, task): diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 0a215535b..7091dbbaf 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -1075,7 +1075,7 @@ class SubcommandsOptionParser(CommonOptionsParser): setattr(parser.values, dest, dict()) option_values = getattr(parser.values, dest) - key, value = value.split('=') + key, value = map(lambda s: util.text_string(s), value.split('=')) option_values[key] = value