diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 83c64f004..3ff9cc69d 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -41,6 +41,7 @@ class EmbedCoverArtPlugin(BeetsPlugin): 'maxwidth': 0, 'auto': True, 'compare_threshold': 0, + 'ifempty': False }) if self.config['maxwidth'].get(int) and not ArtResizer.shared.local: @@ -63,13 +64,14 @@ class EmbedCoverArtPlugin(BeetsPlugin): ) maxwidth = config['embedart']['maxwidth'].get(int) compare_threshold = config['embedart']['compare_threshold'].get(int) + ifempty = config['embedart']['ifempty'].get() def embed_func(lib, opts, args): if opts.file: imagepath = normpath(opts.file) for item in lib.items(decargs(args)): embed_item(item, imagepath, maxwidth, None, - compare_threshold) + compare_threshold, ifempty) else: for album in lib.albums(decargs(args)): embed_album(album, maxwidth) @@ -108,13 +110,23 @@ def album_imported(lib, album): def embed_item(item, imagepath, maxwidth=None, itempath=None, - compare_threshold=0): + compare_threshold=0, ifempty=False): """Embed an image into the item's media file. """ if compare_threshold: if not check_art_similarity(item, imagepath, compare_threshold): log.warn(u'Image not similar; skipping.') return + if ifempty: + with NamedTemporaryFile(delete=True) as f: + art = extract(f.name, item) + if not art: continue + else: + log.debug(u'embedart: media file contained art already {0}'.format( + displayable_path(imagepath) + )) + return + try: log.debug(u'embedart: embedding {0}'.format( displayable_path(imagepath) @@ -148,7 +160,8 @@ 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']['compare_threshold'].get(int), + config['embedart']['ifempty']) def check_art_similarity(item, imagepath, compare_threshold):