Skip to content

Commit

Permalink
log subprocess output
Browse files Browse the repository at this point in the history
  • Loading branch information
brennv committed Oct 15, 2017
1 parent 3ae6550 commit f2849ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pydub/audio_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import wave
import sys
import struct
from .logging_utils import log_conversion
from .logging_utils import log_conversion, log_subprocess_output
import base64

try:
Expand Down Expand Up @@ -511,6 +511,9 @@ def is_format(f):
p = subprocess.Popen(conversion_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p_out, p_err = p.communicate()

log_subprocess_output(p_out)
log_subprocess_output(p_err)

if p.returncode != 0:
raise CouldntDecodeError("Decoding failed. ffmpeg returned error code: {0}\n\nOutput from ffmpeg/avlib:\n\n{1}".format(p.returncode, p_err))

Expand Down Expand Up @@ -674,6 +677,9 @@ def export(self, out_f=None, format='mp3', codec=None, bitrate=None, parameters=
p = subprocess.Popen(conversion_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p_out, p_err = p.communicate()

log_subprocess_output(p_out)
log_subprocess_output(p_err)

if p.returncode != 0:
raise CouldntEncodeError("Encoding failed. ffmpeg/avlib returned error code: {0}\n\nCommand:{1}\n\nOutput from ffmpeg/avlib:\n\n{2}".format(p.returncode, conversion_command, p_err))

Expand Down
7 changes: 6 additions & 1 deletion pydub/logging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
converter_logger = logging.getLogger("pydub.converter")

def log_conversion(conversion_command):
converter_logger.debug("subprocess.call(%s)", repr(conversion_command))
converter_logger.debug("subprocess.call(%s)", repr(conversion_command))

def log_subprocess_output(output):
if output:
for line in output.rstrip().splitlines():
converter_logger.debug('subprocess output: %s', line.rstrip())

0 comments on commit f2849ab

Please sign in to comment.