Merge pull request #1894 from ali-graham/convert_resize_art

Resize album art in convert plugin
This commit is contained in:
Adrian Sampson 2016-02-27 09:54:10 -08:00
commit cae1a859d5
3 changed files with 35 additions and 7 deletions

View file

@ -29,6 +29,7 @@ from beets import ui, util, plugins, config
from beets.plugins import BeetsPlugin
from beets.util.confit import ConfigTypeError
from beets import art
from beets.util.artresizer import ArtResizer
_fs_lock = threading.Lock()
_temp_files = [] # Keep track of temporary transcoded files for deletion.
@ -132,6 +133,7 @@ class ConvertPlugin(BeetsPlugin):
u'paths': {},
u'never_convert_lossy_files': False,
u'copy_album_art': False,
u'album_art_maxwidth': 0,
})
self.import_stages = [self.auto_convert]
@ -305,8 +307,8 @@ class ConvertPlugin(BeetsPlugin):
dest=converted, keepnew=False)
def copy_album_art(self, album, dest_dir, path_formats, pretend=False):
"""Copies the associated cover art of the album. Album must have at
least one track.
"""Copies or converts the associated cover art of the album. Album must
have at least one track.
"""
if not album or not album.artpath:
return
@ -336,14 +338,31 @@ class ConvertPlugin(BeetsPlugin):
util.displayable_path(album.artpath))
return
if pretend:
resize = False
maxwidth = None
if self.config['album_art_maxwidth']:
maxwidth = self.config['album_art_maxwidth'].get(int)
size = ArtResizer.shared.get_size(album.artpath)
self._log.debug('image size: {}', size)
if size:
resize = size[0] > maxwidth
else:
self._log.warning(u'Could not get size of image (please see '
u'documentation for dependencies).')
if resize:
self._log.info(u'Resizing cover art from {0} to {1}',
util.displayable_path(album.artpath),
util.displayable_path(dest))
if not pretend:
ArtResizer.shared.resize(maxwidth, album.artpath, dest)
else:
self._log.info(u'cp {0} {1}',
util.displayable_path(album.artpath),
util.displayable_path(dest))
else:
self._log.info(u'Copying cover art to {0}',
util.displayable_path(dest))
util.copy(album.artpath, dest)
if not pretend:
util.copy(album.artpath, dest)
def convert_func(self, lib, opts, args):
if not opts.dest:

View file

@ -4,6 +4,12 @@ Changelog
1.3.18 (in development)
-----------------------
New features:
* :doc:`/plugins/convert`: A new `album_art_maxwidth` option which will
downsize destination images if the `copy_album_art` switch is true and the
image is too wide.
Fixes:
* Fix a problem with the :ref:`stats-cmd` in exact mode when filenames on

View file

@ -62,6 +62,9 @@ file. The available options are:
Default: none (system default),
- **copy_album_art**: Copy album art when copying or transcoding albums matched
using the ``-a`` option. Default: ``no``.
- **album_art_maxwidth**: Downscale album art if it's too big. The resize
operation reduces image width to at most ``maxwidth`` pixels. The height is
recomputed so that the aspect ratio is preserved.
- **dest**: The directory where the files will be converted (or copied) to.
Default: none.
- **embed**: Embed album art in converted items. Default: ``yes``.