From 18e8b73c33d98b2b66639121aeb7c33bd973e59b Mon Sep 17 00:00:00 2001 From: Duc Nguyen Date: Fri, 25 Feb 2022 18:26:35 +0100 Subject: [PATCH] add option to convert items after import convert items after imports but also keep original files intact --- beetsplug/convert.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index f384656f1..44141c691 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -138,6 +138,7 @@ class ConvertPlugin(BeetsPlugin): }, 'max_bitrate': 500, 'auto': False, + 'auto_keep': False, 'tmpdir': None, 'quiet': False, 'embed': True, @@ -148,7 +149,7 @@ class ConvertPlugin(BeetsPlugin): 'album_art_maxwidth': 0, 'delete_originals': False, }) - self.early_import_stages = [self.auto_convert] + self.early_import_stages = [self.auto_convert, self.auto_convert_keep] self.register_listener('import_task_files', self._cleanup) @@ -184,6 +185,34 @@ class ConvertPlugin(BeetsPlugin): par_map(lambda item: self.convert_on_import(config.lib, item), task.imported_items()) + def auto_convert_keep(self, config, task): + if self.config['auto_keep']: + fmt = self.config['format'].as_str().lower() + + dest = self.config['dest'].get() + if not dest: + raise ui.UserError('no convert destination set') + dest = util.bytestring_path(dest) + + path_formats = ui.get_path_formats(self.config['paths'] or None) + + hardlink = self.config['hardlink'].get(bool) + link = self.config['link'].get(bool) + + threads = self.config['threads'].get(int) + + items = task.imported_items() + convert = [self.convert_item(dest, + False, + path_formats, + fmt, + False, + link, + hardlink) + for _ in range(threads)] + pipe = util.pipeline.Pipeline([iter(items), convert]) + pipe.run_parallel() + # Utilities converted from functions to methods on logging overhaul def encode(self, command, source, dest, pretend=False):