diff options
author | Jorge <mediagoblin@gybs.wa> | 2017-02-10 23:18:19 +0100 |
---|---|---|
committer | Ben Sturmfels <ben@sturm.com.au> | 2020-04-02 16:58:11 +1100 |
commit | 2b487fc16de2fc7c961f8df725c5ece0e5f56e3a (patch) | |
tree | f522d45e4d2369bd529dd42c5f75d6d5e91c3b03 /mediagoblin/media_types | |
parent | 853147339b318ea6e862eab1983653d0765bb433 (diff) | |
download | mediagoblin-2b487fc16de2fc7c961f8df725c5ece0e5f56e3a.tar.lz mediagoblin-2b487fc16de2fc7c961f8df725c5ece0e5f56e3a.tar.xz mediagoblin-2b487fc16de2fc7c961f8df725c5ece0e5f56e3a.zip |
Use audio icon when spectrogram fails. Add note to doc:media-types.
In addition to side-stepping spectrograms completely in Python 3 in 1038aea8,
this commit adds some fallbacks that will help with potential issues in Python 2.
Fixes Issue #5457
Signed-off-by: Ben Sturmfels <ben@sturm.com.au>
Author: Jorge <mediagoblin@gybs.waa>
Diffstat (limited to 'mediagoblin/media_types')
-rw-r--r-- | mediagoblin/media_types/audio/processing.py | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/mediagoblin/media_types/audio/processing.py b/mediagoblin/media_types/audio/processing.py index 427309de..19254aa8 100644 --- a/mediagoblin/media_types/audio/processing.py +++ b/mediagoblin/media_types/audio/processing.py @@ -148,22 +148,34 @@ class CommonAudioProcessor(MediaProcessor): _log.info('Creating OGG source for spectrogram') self.transcoder.transcode(self.process_filename, wav_tmp, mux_name='oggmux') + spectrogram_tmp = os.path.join(self.workbench.dir, self.name_builder.fill( '{basename}-spectrogram.jpg')) - self.thumbnailer.spectrogram( - wav_tmp, - spectrogram_tmp, - width=max_width, - fft_size=fft_size) - - _log.debug('Saving spectrogram...') - store_public(self.entry, 'spectrogram', spectrogram_tmp, + + try: + self.thumbnailer.spectrogram( + wav_tmp, + spectrogram_tmp, + width=max_width, + fft_size=fft_size) + + _log.debug('Saving spectrogram...') + store_public(self.entry, 'spectrogram', thumbnail, self.name_builder.fill('{basename}.spectrogram.jpg')) - file_metadata = {'max_width': max_width, + file_metadata = {'max_width': max_width, 'fft_size': fft_size} - self.entry.set_file_metadata('spectrogram', **file_metadata) + self.entry.set_file_metadata('spectrogram', **file_metadata) + + except IndexError: + _log.warn( + 'Your version of Numpy is too new to create the waveform thumbnail (#5457). ' + "Try\n\t./bin/pip install numpy==1.9.1\n\t./bin/pip install scikits.audiolab==0.10.2") + + except Exception as exc: + _log.warn('Failed to create spectrogram: ' + + '{0}'.exc) def generate_thumb(self, size=None): if not size: @@ -178,13 +190,18 @@ class CommonAudioProcessor(MediaProcessor): '{basename}-thumbnail.jpg')) # We need the spectrogram to create a thumbnail - spectrogram = self.entry.media_files.get('spectrogram') - if not spectrogram: - _log.info('No spectrogram found, we will create one.') - self.create_spectrogram() - spectrogram = self.entry.media_files['spectrogram'] - - spectrogram_filepath = mgg.public_store.get_local_path(spectrogram) + try: + spectrogram = self.entry.media_files.get('spectrogram') + if not spectrogram: + _log.info('No spectrogram found, we will create one.') + self.create_spectrogram() + spectrogram = self.entry.media_files['spectrogram'] + + spectrogram_filepath = mgg.public_store.get_local_path(spectrogram) + + except: + _log.warn('Failed to create spectrogram, using default audio image instead.') + spectrogram_filepath = 'mediagoblin/static/images/media_thumbs/audio.png' self.thumbnailer.thumbnail_spectrogram( spectrogram_filepath, |