diff --git a/beets/art.py b/beets/art.py index e48be4a57..b8b172594 100644 --- a/beets/art.py +++ b/beets/art.py @@ -50,9 +50,9 @@ def get_art(log, item): return mf.art -def embed_item(log, item, imagepath, maxwidth=None, quality=75, itempath=None, - compare_threshold=0, ifempty=False, as_album=False, - id3v23=None): +def embed_item(log, item, imagepath, maxwidth=None, itempath=None, + compare_threshold=0, ifempty=False, as_album=False, id3v23=None, + quality=0): """Embed an image into the item's media file. """ # Conditions and filters. @@ -84,8 +84,8 @@ def embed_item(log, item, imagepath, maxwidth=None, quality=75, itempath=None, item.try_write(path=itempath, tags={'images': [image]}, id3v23=id3v23) -def embed_album(log, album, maxwidth=None, quality=75, quiet=False, - compare_threshold=0, ifempty=False): +def embed_album(log, album, maxwidth=None, quiet=False, compare_threshold=0, + ifempty=False, quality=0): """Embed album art into all of the album's items. """ imagepath = album.artpath @@ -102,15 +102,16 @@ def embed_album(log, album, maxwidth=None, quality=75, quiet=False, log.info(u'Embedding album art into {0}', album) for item in album.items(): - embed_item(log, item, imagepath, maxwidth, quality, None, - compare_threshold, ifempty, as_album=True) + embed_item(log, item, imagepath, maxwidth, None, compare_threshold, + ifempty, as_album=True, quality=quality) def resize_image(log, imagepath, maxwidth, quality): """Returns path to an image resized to maxwidth. """ log.debug(u'Resizing album art to {0} pixels wide', maxwidth) - imagepath = ArtResizer.shared.resize(maxwidth, quality, syspath(imagepath)) + imagepath = ArtResizer.shared.resize(maxwidth, syspath(imagepath), + quality=quality) return imagepath diff --git a/beets/util/artresizer.py b/beets/util/artresizer.py index 3a6f58752..09d138322 100644 --- a/beets/util/artresizer.py +++ b/beets/util/artresizer.py @@ -59,7 +59,7 @@ def temp_file_for(path): return util.bytestring_path(f.name) -def pil_resize(maxwidth, quality, path_in, path_out=None): +def pil_resize(maxwidth, path_in, path_out=None, quality=0): """Resize using Python Imaging Library (PIL). Return the output path of resized image. """ @@ -80,7 +80,7 @@ def pil_resize(maxwidth, quality, path_in, path_out=None): return path_in -def im_resize(maxwidth, quality, path_in, path_out=None): +def im_resize(maxwidth, path_in, path_out=None, quality=0): """Resize using ImageMagick. Use the ``magick`` program or ``convert`` on older versions. Return @@ -93,11 +93,15 @@ def im_resize(maxwidth, quality, path_in, path_out=None): # "-resize WIDTHx>" shrinks images with the width larger # than the given width while maintaining the aspect ratio # with regards to the height. - cmd = ArtResizer.shared.im_convert_cmd + \ - [util.syspath(path_in, prefix=False), - '-resize', '{0}x>'.format(maxwidth), - '-quality', '{0}x'.format(quality), - util.syspath(path_out, prefix=False)] + cmd = ArtResizer.shared.im_convert_cmd + [ + util.syspath(path_in, prefix=False), + '-resize', '{0}x>'.format(maxwidth), + ] + + if quality > 0: + cmd += ['-quality', '{0}'.format(quality)] + + cmd.append(util.syspath(path_out, prefix=False)) try: util.command_output(cmd) @@ -191,14 +195,14 @@ class ArtResizer(six.with_metaclass(Shareable, object)): self.im_convert_cmd = ['magick'] self.im_identify_cmd = ['magick', 'identify'] - def resize(self, maxwidth, quality, path_in, path_out=None): + def resize(self, maxwidth, path_in, path_out=None, quality=0): """Manipulate an image file according to the method, returning a new path. For PIL or IMAGEMAGIC methods, resizes the image to a temporary file. For WEBPROXY, returns `path_in` unmodified. """ if self.local: func = BACKEND_FUNCS[self.method[0]] - return func(maxwidth, quality, path_in, path_out) + return func(maxwidth, path_in, path_out, quality=quality) else: return path_in diff --git a/beetsplug/convert.py b/beetsplug/convert.py index ab86800f6..e7ac4f3ac 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -422,7 +422,7 @@ class ConvertPlugin(BeetsPlugin): util.displayable_path(album.artpath), util.displayable_path(dest)) if not pretend: - ArtResizer.shared.resize(maxwidth, 75, album.artpath, dest) + ArtResizer.shared.resize(maxwidth, album.artpath, dest) else: if pretend: msg = 'ln' if hardlink else ('ln -s' if link else 'cp') diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index e581a2ddf..61a4d798f 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -60,7 +60,7 @@ class EmbedCoverArtPlugin(BeetsPlugin): 'compare_threshold': 0, 'ifempty': False, 'remove_art_file': False, - 'quality': 95, + 'quality': 0, }) if self.config['maxwidth'].get(int) and not ArtResizer.shared.local: @@ -107,7 +107,8 @@ class EmbedCoverArtPlugin(BeetsPlugin): for item in items: art.embed_item(self._log, item, imagepath, maxwidth, - quality, None, compare_threshold, ifempty) + None, compare_threshold, ifempty, + quality=quality) else: albums = lib.albums(decargs(args)) @@ -116,8 +117,9 @@ class EmbedCoverArtPlugin(BeetsPlugin): return for album in albums: - art.embed_album(self._log, album, maxwidth, quality, - False, compare_threshold, ifempty) + art.embed_album(self._log, album, maxwidth, + False, compare_threshold, ifempty, + quality=quality) self.remove_artfile(album) embed_cmd.func = embed_func diff --git a/test/test_thumbnails.py b/test/test_thumbnails.py index 0cf22d4a1..dc03f06f7 100644 --- a/test/test_thumbnails.py +++ b/test/test_thumbnails.py @@ -154,7 +154,7 @@ class ThumbnailsTest(unittest.TestCase, TestHelper): any_order=True) resize = mock_artresizer.shared.resize - resize.assert_called_once_with(12345, 75, path_to_art, md5_file) + resize.assert_called_once_with(12345, path_to_art, md5_file) plugin.add_tags.assert_called_once_with(album, resize.return_value) mock_shutils.move.assert_called_once_with(resize.return_value, md5_file)