diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 51d401af8..65aa53433 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -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 diff --git a/docs/plugins/embedart.rst b/docs/plugins/embedart.rst index 68ea0f664..c31284a54 100644 --- a/docs/plugins/embedart.rst +++ b/docs/plugins/embedart.rst @@ -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. \ No newline at end of file diff --git a/test/test_embedart.py b/test/test_embedart.py index 1622fffb4..7023d7cbe 100644 --- a/test/test_embedart.py +++ b/test/test_embedart.py @@ -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')