Working on issue #1028, resize images only once per album.

This commit is contained in:
kerobaros 2014-10-24 15:01:52 -05:00
parent ca431b0bf8
commit 9a191baca4

View file

@ -110,7 +110,7 @@ def album_imported(lib, album):
def embed_item(item, imagepath, maxwidth=None, itempath=None,
compare_threshold=0, ifempty=False):
compare_threshold=0, ifempty=False, asalbum=False):
"""Embed an image into the item's media file.
"""
if compare_threshold:
@ -126,6 +126,8 @@ def embed_item(item, imagepath, maxwidth=None, itempath=None,
displayable_path(imagepath)
))
return
if not asalbum:
imagepath = resize_image(imagepath, maxwidth)
try:
log.debug(u'embedart: embedding {0}'.format(
@ -152,6 +154,8 @@ def embed_album(album, maxwidth=None, quiet=False):
log.error(u'Album art not found at {0}'
.format(displayable_path(imagepath)))
return
if maxwidth:
imagepath = resize_image(imagepath, maxwidth)
log.log(
logging.DEBUG if quiet else logging.INFO,
@ -161,7 +165,16 @@ def embed_album(album, maxwidth=None, quiet=False):
for item in album.items():
embed_item(item, imagepath, maxwidth, None,
config['embedart']['compare_threshold'].get(int),
config['embedart']['ifempty'])
config['embedart']['ifempty'], asalbum=True)
def resize_image(imagepath, maxwidth):
"""Returns path to an image resized to maxwidth.
"""
log.info(u'Resizing album art to {0} pixels wide'
.format(maxwidth))
imagepath = ArtResizer.shared.resize(maxwidth, syspath(imagepath))
return imagepath
def check_art_similarity(item, imagepath, compare_threshold):
@ -201,11 +214,7 @@ def check_art_similarity(item, imagepath, compare_threshold):
def _mediafile_image(image_path, maxwidth=None):
"""Return a `mediafile.Image` object for the path.
If maxwidth is set the image is resized if necessary.
"""
if maxwidth:
image_path = ArtResizer.shared.resize(maxwidth, syspath(image_path))
with open(syspath(image_path), 'rb') as f:
data = f.read()