diff --git a/beets/util/__init__.py b/beets/util/__init__.py index f50ce109e..428de312a 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -633,14 +633,13 @@ def command_output(cmd, shell=False): Python 2.6 and which can have problems if lots of output is sent to stderr. """ - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - close_fds=platform.system() != 'Windows', - shell=shell) - stdout, stderr = proc.communicate() - + with open(os.devnull, 'wb') as devnull: + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=devnull, + close_fds=platform.system() != 'Windows', + shell=shell) + stdout, _ = proc.communicate() if proc.returncode: - raise subprocess.CalledProcessError(proc.returncode, cmd, stderr) + raise subprocess.CalledProcessError(proc.returncode, cmd) return stdout diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 0289f7362..eadb77843 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -17,6 +17,7 @@ import os.path import logging import imghdr import subprocess +import platform from tempfile import NamedTemporaryFile from beets.plugins import BeetsPlugin @@ -25,7 +26,7 @@ from beets import ui from beets.ui import decargs from beets.util import syspath, normpath, displayable_path from beets.util.artresizer import ArtResizer -from beets import config, util +from beets import config log = logging.getLogger('beets') @@ -159,15 +160,20 @@ def check_art_similarity(item, imagepath, compare_threshold): 'compare -metric PHASH - null:'.format(syspath(imagepath), syspath(art)) - try: - phashDiff = util.command_output(cmd, shell=True) - except subprocess.CalledProcessError, e: - if e.returncode != 1: + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + close_fds=platform.system() != 'Windows', + shell=True) + stdout, stderr = proc.communicate() + if proc.returncode: + if proc.returncode != 1: log.warn(u'embedart: IM phashes compare failed for {0}, \ - {1}'.format(displayable_path(imagepath), - displayable_path(art))) + {1}'.format(displayable_path(imagepath), + displayable_path(art))) return - phashDiff = float(e.output) + phashDiff = float(stderr) + else: + phashDiff = float(stdout) log.info(u'embedart: compare PHASH score is {0}'.format(phashDiff)) if phashDiff > compare_threshold: