aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Sturmfels <ben@sturm.com.au>2019-09-12 19:58:32 +1000
committerBen Sturmfels <ben@sturm.com.au>2019-09-12 19:59:11 +1000
commit97dcfe3725d11bd4d2212a232c156c25810322a2 (patch)
tree613e79ec17d3b3f13ad5440748f852141656245a
parent8f18381bbc7d12e9a988d5ce332491ba487fc73d (diff)
downloadmediagoblin-97dcfe3725d11bd4d2212a232c156c25810322a2.tar.lz
mediagoblin-97dcfe3725d11bd4d2212a232c156c25810322a2.tar.xz
mediagoblin-97dcfe3725d11bd4d2212a232c156c25810322a2.zip
Work around lack of scikits.audiolab support on Python 3.
-rw-r--r--docs/source/siteadmin/media-types.rst5
-rw-r--r--extlib/freesound/audioprocessing.py25
2 files changed, 29 insertions, 1 deletions
diff --git a/docs/source/siteadmin/media-types.rst b/docs/source/siteadmin/media-types.rst
index 8f9239be..e06739ec 100644
--- a/docs/source/siteadmin/media-types.rst
+++ b/docs/source/siteadmin/media-types.rst
@@ -131,10 +131,13 @@ To install these on Debianoid systems, run::
not compile it with alsa support. Alsa support is not necessary for the GNU
MediaGoblin application.
-Then install ``scikits.audiolab`` for the spectrograms::
+If you're running Python 2, install ``scikits.audiolab`` for the spectrograms::
./bin/pip install scikits.audiolab
+Audio spectrograms are currently not available on Python 3, since scikits.audiolab
+does not provide Python 3 support.
+
Add ``[[mediagoblin.media_types.audio]]`` under the ``[plugins]`` section in your
``mediagoblin.ini`` and restart MediaGoblin.
diff --git a/extlib/freesound/audioprocessing.py b/extlib/freesound/audioprocessing.py
index 7ef8d5d4..b9a96a97 100644
--- a/extlib/freesound/audioprocessing.py
+++ b/extlib/freesound/audioprocessing.py
@@ -44,6 +44,31 @@ try:
import scikits.audiolab as audiolab
except ImportError:
print("WARNING: audiolab is not installed so wav2png will not work")
+
+ # Hack to prevent errors when uploading audio files. The issue is that
+ # scikits.audiolab does not support Python 3. By replacing it with a mock
+ # implementation here, we can accept audio files, but we won't get the nice
+ # waveform image.
+ import six
+ if six.PY3:
+ class MockSndfile(object):
+ def __init__(self, *args, **kwargs):
+ self.nframes = 0
+ self.channels = 1
+ self.samplerate = 44100
+
+ def read_frames(self, *args):
+ return []
+
+ def seek(self, *args):
+ return
+
+ def close(self):
+ return
+ import unittest.mock as mock
+ audiolab = mock.Mock()
+ audiolab.Sndfile = MockSndfile
+
import subprocess
class AudioProcessingException(Exception):