clearart asks for permission before deleting embedded albumart

This commit is contained in:
konman2 2017-10-07 20:42:01 -07:00
parent e370286c2f
commit fdeef05cc9
3 changed files with 33 additions and 2 deletions

View file

@ -163,8 +163,14 @@ class EmbedCoverArtPlugin(BeetsPlugin):
'clearart',
help=u'remove images from file metadata',
)
clear_cmd.parser.add_option(
u"-y", u"--yes", action="store_true", help=u"skip confirmation"
)
def clear_func(lib, opts, args):
items = lib.items(decargs(args))
# Confirm with user.
if not opts.yes and not _confirm(items, False):
return
art.clear(self._log, lib, decargs(args))
clear_cmd.func = clear_func

View file

@ -99,4 +99,5 @@ embedded album art:
automatically.
* ``beet clearart QUERY``: removes all embedded images from all items matching
the query. (Use with caution!)
the query. (Use with caution!) The command prompts for confirmation before
making the change unless you specify the ``-y`` (``--yes``) option.

View file

@ -195,6 +195,30 @@ class EmbedartCliTest(_common.TestCase, TestHelper):
self.assertExists(os.path.join(albumpath, b'extracted.jpg'))
def test_clear_art_with_yes_input(self):
self._setup_data()
album = self.add_album_fixture()
item = album.items()[0]
self.io.addinput('y')
self.run_command('embedart', '-f', self.small_artpath)
self.io.addinput('y')
self.run_command('clearart')
mediafile = MediaFile(syspath(item.path))
#print(mediafile.images[0].data == self.image_data)
self.assertEqual(len(mediafile.images), 0)
def test_clear_art_with_no_input(self):
self._setup_data()
album = self.add_album_fixture()
item = album.items()[0]
self.io.addinput('y')
self.run_command('embedart', '-f', self.small_artpath)
self.io.addinput('n')
self.run_command('clearart')
mediafile = MediaFile(syspath(item.path))
#print(mediafile.images[0].data == self.image_data)
self.assertEqual(mediafile.images[0].data, self.image_data)
@patch('beets.art.subprocess')
@patch('beets.art.extract')