From d53b677e0f9e4618dd605c55dc51372ed8e06071 Mon Sep 17 00:00:00 2001 From: "nath@home" Date: Sun, 13 Nov 2016 00:20:01 +0100 Subject: [PATCH 1/4] convert: initial cleanup of convert_func Get cli options and configuration in a more readable, uniform way --- beetsplug/convert.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index 9b7f49e36..a9a3dcf62 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -385,25 +385,21 @@ 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) + pretend = self.config['pretend'].get(bool) if not pretend: ui.commands.list_items(lib, ui.decargs(args), opts.album) @@ -416,16 +412,15 @@ class ConvertPlugin(BeetsPlugin): 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) + self.copy_album_art(album, dest, path_formats, pretend) else: items = iter(lib.items(ui.decargs(args))) - convert = [self.convert_item(opts.dest, + convert = [self.convert_item(dest, opts.keep_new, path_formats, - opts.format, + fmt, pretend) - for _ in range(opts.threads)] + for _ in range(threads)] pipe = util.pipeline.Pipeline([items, convert]) pipe.run_parallel() From 2e78628507386d759dab8ea1e55d7ef23b9fa69b Mon Sep 17 00:00:00 2001 From: "nath@home" Date: Sun, 13 Nov 2016 00:23:03 +0100 Subject: [PATCH 2/4] convert: Don't ask for confirmation if query result is empty --- beetsplug/convert.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index a9a3dcf62..6639eb7b1 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -401,27 +401,35 @@ class ConvertPlugin(BeetsPlugin): else: pretend = 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 - 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, 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))) + 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, fmt, pretend) for _ in range(threads)] - pipe = util.pipeline.Pipeline([items, convert]) + pipe = util.pipeline.Pipeline([iter(items), convert]) pipe.run_parallel() def convert_on_import(self, lib, item): From 8067d82be8ba65115fcb86359bf7ccf8b8dc7553 Mon Sep 17 00:00:00 2001 From: "nathdwek@laptop" Date: Sun, 13 Nov 2016 17:47:07 +0100 Subject: [PATCH 3/4] convert: test for #2260 --- test/test_convert.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/test_convert.py b/test/test_convert.py index 8d75fbb57..6b2ae9259 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, From 862d89001fae85745e8961bdecf022fff1c43ec2 Mon Sep 17 00:00:00 2001 From: "nathdwek@laptop" Date: Sun, 13 Nov 2016 17:47:47 +0100 Subject: [PATCH 4/4] convert: changelog for #2262 --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) 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`