Make freesound compatible with python3

Freesound is a lib used for audio processing. Unfortunately, it doesn't
work with python3.

It lives in extlib, so we don't own the code. But, since the patch is
pretty trivial, it was decided to merge it anyway and propose the fix to
upstream. Which was done in https://github.com/MTG/freesound/pull/700 .
Also, a bugreport was opened to use upstream version instead of our
local, when it gets merged, ticket 5403.
This commit is contained in:
Boris Bobrov 2016-01-22 01:36:27 +03:00
parent 525e851e17
commit 45aa5360d6

View File

@ -300,7 +300,7 @@ class WaveformImage(object):
"""
def __init__(self, image_width, image_height, palette=1):
if image_height % 2 == 0:
raise AudioProcessingException, "Height should be uneven: images look much better at uneven height"
raise AudioProcessingException("Height should be uneven: images look much better at uneven height")
if palette == 1:
background_color = (0,0,0)
@ -493,7 +493,7 @@ def convert_to_pcm(input_filename, output_filename):
"""
if not os.path.exists(input_filename):
raise AudioProcessingException, "file %s does not exist" % input_filename
raise AudioProcessingException("file %s does not exist" % input_filename)
sound_type = get_sound_type(input_filename)
@ -512,7 +512,7 @@ def convert_to_pcm(input_filename, output_filename):
if process.returncode != 0 or not os.path.exists(output_filename):
if "No space left on device" in stderr + " " + stdout:
raise NoSpaceLeftException
raise AudioProcessingException, "failed converting to pcm data:\n" + " ".join(cmd) + "\n" + stderr + "\n" + stdout
raise AudioProcessingException("failed converting to pcm data:\n" + " ".join(cmd) + "\n" + stderr + "\n" + stdout)
return True
@ -523,7 +523,7 @@ def stereofy_and_find_info(stereofy_executble_path, input_filename, output_filen
"""
if not os.path.exists(input_filename):
raise AudioProcessingException, "file %s does not exist" % input_filename
raise AudioProcessingException("file %s does not exist" % input_filename)
cmd = [stereofy_executble_path, "--input", input_filename, "--output", output_filename]
@ -533,7 +533,7 @@ def stereofy_and_find_info(stereofy_executble_path, input_filename, output_filen
if process.returncode != 0 or not os.path.exists(output_filename):
if "No space left on device" in stderr + " " + stdout:
raise NoSpaceLeftException
raise AudioProcessingException, "failed calling stereofy data:\n" + " ".join(cmd) + "\n" + stderr + "\n" + stdout
raise AudioProcessingException("failed calling stereofy data:\n" + " ".join(cmd) + "\n" + stderr + "\n" + stdout)
stdout = (stdout + " " + stderr).replace("\n", " ")
@ -568,7 +568,7 @@ def convert_to_mp3(input_filename, output_filename, quality=70):
"""
if not os.path.exists(input_filename):
raise AudioProcessingException, "file %s does not exist" % input_filename
raise AudioProcessingException("file %s does not exist" % input_filename)
command = ["lame", "--silent", "--abr", str(quality), input_filename, output_filename]
@ -576,7 +576,7 @@ def convert_to_mp3(input_filename, output_filename, quality=70):
(stdout, stderr) = process.communicate()
if process.returncode != 0 or not os.path.exists(output_filename):
raise AudioProcessingException, stdout
raise AudioProcessingException(stdout)
def convert_to_ogg(input_filename, output_filename, quality=1):
"""
@ -584,7 +584,7 @@ def convert_to_ogg(input_filename, output_filename, quality=1):
"""
if not os.path.exists(input_filename):
raise AudioProcessingException, "file %s does not exist" % input_filename
raise AudioProcessingException("file %s does not exist" % input_filename)
command = ["oggenc", "-q", str(quality), input_filename, "-o", output_filename]
@ -592,7 +592,7 @@ def convert_to_ogg(input_filename, output_filename, quality=1):
(stdout, stderr) = process.communicate()
if process.returncode != 0 or not os.path.exists(output_filename):
raise AudioProcessingException, stdout
raise AudioProcessingException(stdout)
def convert_using_ffmpeg(input_filename, output_filename):
"""
@ -600,10 +600,10 @@ def convert_using_ffmpeg(input_filename, output_filename):
"""
TIMEOUT = 3 * 60
def alarm_handler(signum, frame):
raise AudioProcessingException, "timeout while waiting for ffmpeg"
raise AudioProcessingException("timeout while waiting for ffmpeg")
if not os.path.exists(input_filename):
raise AudioProcessingException, "file %s does not exist" % input_filename
raise AudioProcessingException("file %s does not exist" % input_filename)
command = ["ffmpeg", "-y", "-i", input_filename, "-ac","1","-acodec", "pcm_s16le", "-ar", "44100", output_filename]
@ -613,4 +613,4 @@ def convert_using_ffmpeg(input_filename, output_filename):
(stdout, stderr) = process.communicate()
signal.alarm(0)
if process.returncode != 0 or not os.path.exists(output_filename):
raise AudioProcessingException, stdout
raise AudioProcessingException(stdout)