diff --git a/beetsplug/convert.py b/beetsplug/convert.py index 9b7f49e36..6639eb7b1 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -385,48 +385,51 @@ class ConvertPlugin(BeetsPlugin): util.copy(album.artpath, dest) def convert_func(self, lib, opts, args): - if not opts.dest: - opts.dest = self.config['dest'].get() - if not opts.dest: + dest = opts.dest or self.config['dest'].get() + if not dest: raise ui.UserError(u'no convert destination set') - opts.dest = util.bytestring_path(opts.dest) + dest = util.bytestring_path(dest) - if not opts.threads: - opts.threads = self.config['threads'].get(int) + threads = opts.threads or self.config['threads'].get(int) - if self.config['paths']: - path_formats = ui.get_path_formats(self.config['paths']) + path_formats = ui.get_path_formats(self.config['paths'] or None) + + fmt = opts.format or self.config['format'].as_str().lower() + + if opts.pretend is not None: + pretend = opts.pretend else: - path_formats = ui.get_path_formats() - - if not opts.format: - opts.format = self.config['format'].as_str().lower() - - pretend = opts.pretend if opts.pretend is not None else \ - self.config['pretend'].get(bool) - - if not pretend: - ui.commands.list_items(lib, ui.decargs(args), opts.album) - - if not (opts.yes or ui.input_yn(u"Convert? (Y/n)")): - return + pretend = self.config['pretend'].get(bool) if opts.album: albums = lib.albums(ui.decargs(args)) - items = (i for a in albums for i in a.items()) - if self.config['copy_album_art']: - for album in albums: - self.copy_album_art(album, opts.dest, path_formats, - pretend) + items = [i for a in albums for i in a.items()] + if not pretend: + for a in albums: + ui.print_(format(a, u'')) else: - items = iter(lib.items(ui.decargs(args))) - convert = [self.convert_item(opts.dest, + items = list(lib.items(ui.decargs(args))) + if not pretend: + for i in items: + ui.print_(format(i, u'')) + + if not items: + self._log.error(u'Empty query result.') + return + if not (pretend or opts.yes or ui.input_yn(u"Convert? (Y/n)")): + return + + if opts.album and self.config['copy_album_art']: + for album in albums: + self.copy_album_art(album, dest, path_formats, pretend) + + convert = [self.convert_item(dest, opts.keep_new, path_formats, - opts.format, + fmt, pretend) - for _ in range(opts.threads)] - pipe = util.pipeline.Pipeline([items, convert]) + for _ in range(threads)] + pipe = util.pipeline.Pipeline([iter(items), convert]) pipe.run_parallel() def convert_on_import(self, lib, item): diff --git a/docs/changelog.rst b/docs/changelog.rst index 607746c4a..a69f8b5a9 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -52,6 +52,8 @@ The are a couple of small new features: And there are a few bug fixes too: +* :doc:`/plugins/convert`: The plugin no longer asks for confirmation if the + query did not return anything to convert. :bug:`2260` :bug:`2262` * :doc:`/plugins/embedart`: The plugin now uses ``jpg`` as an extension rather than ``jpeg``, to ensure consistency with :doc:`plugins/fetchart`. Thanks to :user:`tweitzel`. :bug:`2254` :bug:`2255` diff --git a/test/test_convert.py b/test/test_convert.py index 123550e54..0d1804288 100644 --- a/test/test_convert.py +++ b/test/test_convert.py @@ -20,7 +20,7 @@ import os.path from test import _common from test._common import unittest from test import helper -from test.helper import control_stdin +from test.helper import control_stdin, capture_log from beets.mediafile import MediaFile from beets import util @@ -215,6 +215,11 @@ class ConvertCliTest(unittest.TestCase, TestHelper, ConvertCommand): converted = os.path.join(self.convert_dest, b'converted.mp3') self.assertFalse(os.path.exists(converted)) + def test_empty_query(self): + with capture_log('beets.convert') as logs: + self.run_convert('An impossible query') + self.assertEqual(logs[0], u'convert: Empty query result.') + @_common.slow_test() class NeverConvertLossyFilesTest(unittest.TestCase, TestHelper,