diff options
author | Ben Sturmfels <ben@sturm.com.au> | 2020-04-01 16:52:05 +1100 |
---|---|---|
committer | Ben Sturmfels <ben@sturm.com.au> | 2020-04-01 16:52:05 +1100 |
commit | 1038aea822fdc8a84745bd44cc96ed97d66bbc28 (patch) | |
tree | 4f684a61a72f9b5b612e864ee1e455f3651381eb /mediagoblin/media_types | |
parent | ad3a0aea833a26735d1d2986f427e9f286dbac21 (diff) | |
download | mediagoblin-1038aea822fdc8a84745bd44cc96ed97d66bbc28.tar.lz mediagoblin-1038aea822fdc8a84745bd44cc96ed97d66bbc28.tar.xz mediagoblin-1038aea822fdc8a84745bd44cc96ed97d66bbc28.zip |
Fix audio thumbnailing once and for all.
This change adds a Python 3-specific audio thumbnailer that side-steps the
bundled Python 2-only `audioprocessing` module. Instead of an audio spectrogram,
Python 3 users will get a static image.
This also allows me to remove my ineffective customisations to
`audioprocessing`, returning it to the upstream version as should always be the
case for vendored code in "extlib".
Diffstat (limited to 'mediagoblin/media_types')
-rw-r--r-- | mediagoblin/media_types/audio/transcoders.py | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/mediagoblin/media_types/audio/transcoders.py b/mediagoblin/media_types/audio/transcoders.py index f86528de..f78cbf28 100644 --- a/mediagoblin/media_types/audio/transcoders.py +++ b/mediagoblin/media_types/audio/transcoders.py @@ -20,8 +20,6 @@ try: except ImportError: import Image -from mediagoblin.media_types.audio import audioprocessing - _log = logging.getLogger(__name__) CPU_COUNT = 2 # Just assuming for now @@ -46,13 +44,17 @@ from gi.repository import GObject, Gst Gst.init(None) import numpy +import six -class AudioThumbnailer(object): +class Python2AudioThumbnailer(object): def __init__(self): _log.info('Initializing {0}'.format(self.__class__.__name__)) def spectrogram(self, src, dst, **kw): + # This third-party bundled module is Python 2-only. + from mediagoblin.media_types.audio import audioprocessing + width = kw['width'] height = int(kw.get('height', float(width) * 0.3)) fft_size = kw.get('fft_size', 2048) @@ -111,6 +113,25 @@ class AudioThumbnailer(object): th.save(dst) +class Python3AudioThumbnailer(Python2AudioThumbnailer): + """Dummy thumbnailer for Python 3. + + The Python package used for audio spectrograms, "scikits.audiolab", does not + support Python 3 and is a constant source of problems for people installing + MediaGoblin. Until the feature is rewritten, this thumbnailer class simply + provides a generic image. + + """ + def spectrogram(self, src, dst, **kw): + # Using PIL here in case someone wants to swap out the image for a PNG. + # This will convert to JPEG, where simply copying the file won't. + img = Image.open('mediagoblin/static/images/media_thumbs/video.jpg') + img.save(dst) + + +AudioThumbnailer = Python3AudioThumbnailer if six.PY3 else Python2AudioThumbnailer + + class AudioTranscoder(object): def __init__(self): _log.info('Initializing {0}'.format(self.__class__.__name__)) |