Skip to content

Commit

Permalink
clearart asks for permission before deleting embedded albumart
Browse files Browse the repository at this point in the history
  • Loading branch information
konman2 committed Oct 8, 2017
1 parent e370286 commit fdeef05
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
8 changes: 7 additions & 1 deletion beetsplug/embedart.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,14 @@ def extract_func(lib, opts, args):
'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

Expand Down
3 changes: 2 additions & 1 deletion docs/plugins/embedart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
24 changes: 24 additions & 0 deletions test/test_embedart.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,30 @@ def test_extracted_extension(self):

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')
Expand Down

0 comments on commit fdeef05

Please sign in to comment.