Resize album art when embedding (convert plugin)

Fixes #2116
This commit is contained in:
Adam Fontenot 2022-02-08 16:39:46 -08:00
parent debbe4efa5
commit 07eb26f276
3 changed files with 26 additions and 14 deletions

View file

@ -343,9 +343,10 @@ class ConvertPlugin(BeetsPlugin):
if self.config['embed'] and not linked:
album = item._cached_album
if album and album.artpath:
maxwidth = self._get_art_resize(album.artpath)
self._log.debug('embedding album art from {}',
util.displayable_path(album.artpath))
art.embed_item(self._log, item, album.artpath,
art.embed_item(self._log, item, album.artpath, maxwidth,
itempath=converted, id3v23=id3v23)
if keep_new:
@ -389,20 +390,10 @@ class ConvertPlugin(BeetsPlugin):
return
# Decide whether we need to resize the cover-art image.
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('Could not get size of image (please see '
'documentation for dependencies).')
maxwidth = self._get_art_resize(album.artpath)
# Either copy or resize (while copying) the image.
if resize:
if maxwidth is not None:
self._log.info('Resizing cover art from {0} to {1}',
util.displayable_path(album.artpath),
util.displayable_path(dest))
@ -531,6 +522,24 @@ class ConvertPlugin(BeetsPlugin):
)
util.remove(source_path, False)
def _get_art_resize(self, artpath):
"""For a given piece of album art, determine whether or not it needs
to be resized according to the user's settings. If so, returns the
new size. If not, returns None.
"""
newwidth = None
if self.config['album_art_maxwidth']:
maxwidth = self.config['album_art_maxwidth'].get(int)
size = ArtResizer.shared.get_size(artpath)
self._log.debug('image size: {}', size)
if size:
if size[0] > maxwidth:
newwidth = maxwidth
else:
self._log.warning('Could not get size of image (please see '
'documentation for dependencies).')
return newwidth
def _cleanup(self, task, session):
for path in task.old_paths:
if path in _temp_files:

View file

@ -15,6 +15,8 @@ New features:
Bug fixes:
* :doc:`/plugins/convert`: Resize album art when embedding
:bug:`2116`
* :doc:`/plugins/deezer`: Fix auto tagger pagination issues (fetch beyond the
first 25 tracks of a release).
* :doc:`/plugins/spotify`: Fix auto tagger pagination issues (fetch beyond the

View file

@ -72,7 +72,8 @@ file. The available options are:
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 while
preserving the aspect ratio.
preserving the aspect ratio. The specified image size will apply to both
embedded album art and external image files.
- **dest**: The directory where the files will be converted (or copied) to.
Default: none.
- **embed**: Embed album art in converted items. Default: ``yes``.