Skip to content

Commit

Permalink
Resize album art when embedding (convert plugin)
Browse files Browse the repository at this point in the history
  • Loading branch information
afontenot committed Feb 10, 2022
1 parent debbe4e commit 07eb26f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
35 changes: 22 additions & 13 deletions beetsplug/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,10 @@ def convert_item(self, dest_dir, keep_new, path_formats, fmt,
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:
Expand Down Expand Up @@ -389,20 +390,10 @@ def copy_album_art(self, album, dest_dir, path_formats, pretend=False,
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))
Expand Down Expand Up @@ -531,6 +522,24 @@ def convert_on_import(self, lib, item):
)
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:
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docs/plugins/convert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down

0 comments on commit 07eb26f

Please sign in to comment.