Repository: beetbox/beets

Issue:
Convert asks for confirmation even if the query did not match anything
![](http://imgur.com/e6t6ZKT.gif)


Discussion:
That's no good. Thanks for filing this.


Resolving patch:
diff --git a/beetsplug/convert.py b/beetsplug/convert.py
--- a/beetsplug/convert.py
+++ b/beetsplug/convert.py
@@ -385,48 +385,51 @@ def copy_album_art(self, album, dest_dir, path_formats, pretend=False):
                 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'])
-        else:
-            path_formats = ui.get_path_formats()
-
-        if not opts.format:
-            opts.format = self.config['format'].as_str().lower()
+        path_formats = ui.get_path_formats(self.config['paths'] or None)
 
-        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)
+        fmt = opts.format or self.config['format'].as_str().lower()
 
-            if not (opts.yes or ui.input_yn(u"Convert? (Y/n)")):
-                return
+        if opts.pretend is not None:
+            pretend = opts.pretend
+        else:
+            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):


Test patch:
diff --git a/test/test_convert.py b/test/test_convert.py
--- a/test/test_convert.py
+++ b/test/test_convert.py
@@ -20,7 +20,7 @@
 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 @@ def test_pretend(self):
         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,