Skip to content

Commit

Permalink
Merge pull request #2262 from beetbox/fix-2260
Browse files Browse the repository at this point in the history
Convert: Don't prompt for confirmation if query result is empty
Fix #2260
  • Loading branch information
nathdwek authored Nov 13, 2016
2 parents a0a9f5a + 862d890 commit 2eae2d6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
63 changes: 33 additions & 30 deletions beetsplug/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
7 changes: 6 additions & 1 deletion test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2eae2d6

Please sign in to comment.