From 05848604486e305c4e368e852c953d237b1ca25e Mon Sep 17 00:00:00 2001
From: GNU MediaGoblin system account <mediagoblin@gybs.waa>
Date: Fri, 10 Feb 2017 23:18:19 +0100
Subject: [PATCH] Use audio icon when spectrogram fails. Add note to
doc:media-types.
Fixes Issue #5457
---
docs/source/siteadmin/media-types.rst | 11 +++++--
mediagoblin/media_types/audio/processing.py | 51 +++++++++++++++++++----------
2 files changed, 43 insertions(+), 19 deletions(-)
diff --git a/docs/source/siteadmin/media-types.rst b/docs/source/siteadmin/media-types.rst
index 5cd269d4..e851f29f 100644
|
a
|
b
|
To install these on Debianoid systems, run::
|
| 142 | 142 | not compile it with alsa support. Alsa support is not necessary for the GNU |
| 143 | 143 | MediaGoblin application. |
| 144 | 144 | |
| 145 | | Then install ``scikits.audiolab`` for the spectrograms:: |
| | 145 | Because of a deprecation issue with Numpy (#5457) you need to hold them at the |
| | 146 | following versions for the spectrograms: |
| 146 | 147 | |
| 147 | | ./bin/pip install scikits.audiolab |
| | 148 | .. code-block:: bash |
| | 149 | |
| | 150 | ./bin/pip install numpy==1.9.1 |
| | 151 | ./bin/pip install scikits.audiolab==0.10.2 |
| | 152 | |
| | 153 | For python3 ``scikits.audiolab`` has no package yet. Instead of the cool |
| | 154 | waveform image a static icon is used until we found a replacement. (#5467) |
| 148 | 155 | |
| 149 | 156 | Add ``[[mediagoblin.media_types.audio]]`` under the ``[plugins]`` section in your |
| 150 | 157 | ``mediagoblin_local.ini`` and restart MediaGoblin. |
diff --git a/mediagoblin/media_types/audio/processing.py b/mediagoblin/media_types/audio/processing.py
index 427309de..19254aa8 100644
|
a
|
b
|
class CommonAudioProcessor(MediaProcessor):
|
| 148 | 148 | _log.info('Creating OGG source for spectrogram') |
| 149 | 149 | self.transcoder.transcode(self.process_filename, wav_tmp, |
| 150 | 150 | mux_name='oggmux') |
| | 151 | |
| 151 | 152 | spectrogram_tmp = os.path.join(self.workbench.dir, |
| 152 | 153 | self.name_builder.fill( |
| 153 | 154 | '{basename}-spectrogram.jpg')) |
| 154 | | self.thumbnailer.spectrogram( |
| 155 | | wav_tmp, |
| 156 | | spectrogram_tmp, |
| 157 | | width=max_width, |
| 158 | | fft_size=fft_size) |
| 159 | | |
| 160 | | _log.debug('Saving spectrogram...') |
| 161 | | store_public(self.entry, 'spectrogram', spectrogram_tmp, |
| | 155 | |
| | 156 | try: |
| | 157 | self.thumbnailer.spectrogram( |
| | 158 | wav_tmp, |
| | 159 | spectrogram_tmp, |
| | 160 | width=max_width, |
| | 161 | fft_size=fft_size) |
| | 162 | |
| | 163 | _log.debug('Saving spectrogram...') |
| | 164 | store_public(self.entry, 'spectrogram', thumbnail, |
| 162 | 165 | self.name_builder.fill('{basename}.spectrogram.jpg')) |
| 163 | 166 | |
| 164 | | file_metadata = {'max_width': max_width, |
| | 167 | file_metadata = {'max_width': max_width, |
| 165 | 168 | 'fft_size': fft_size} |
| 166 | | self.entry.set_file_metadata('spectrogram', **file_metadata) |
| | 169 | self.entry.set_file_metadata('spectrogram', **file_metadata) |
| | 170 | |
| | 171 | except IndexError: |
| | 172 | _log.warn( |
| | 173 | 'Your version of Numpy is too new to create the waveform thumbnail (#5457). ' |
| | 174 | "Try\n\t./bin/pip install numpy==1.9.1\n\t./bin/pip install scikits.audiolab==0.10.2") |
| | 175 | |
| | 176 | except Exception as exc: |
| | 177 | _log.warn('Failed to create spectrogram: ' |
| | 178 | + '{0}'.exc) |
| 167 | 179 | |
| 168 | 180 | def generate_thumb(self, size=None): |
| 169 | 181 | if not size: |
| … |
… |
class CommonAudioProcessor(MediaProcessor):
|
| 178 | 190 | '{basename}-thumbnail.jpg')) |
| 179 | 191 | |
| 180 | 192 | # We need the spectrogram to create a thumbnail |
| 181 | | spectrogram = self.entry.media_files.get('spectrogram') |
| 182 | | if not spectrogram: |
| 183 | | _log.info('No spectrogram found, we will create one.') |
| 184 | | self.create_spectrogram() |
| 185 | | spectrogram = self.entry.media_files['spectrogram'] |
| 186 | | |
| 187 | | spectrogram_filepath = mgg.public_store.get_local_path(spectrogram) |
| | 193 | try: |
| | 194 | spectrogram = self.entry.media_files.get('spectrogram') |
| | 195 | if not spectrogram: |
| | 196 | _log.info('No spectrogram found, we will create one.') |
| | 197 | self.create_spectrogram() |
| | 198 | spectrogram = self.entry.media_files['spectrogram'] |
| | 199 | |
| | 200 | spectrogram_filepath = mgg.public_store.get_local_path(spectrogram) |
| | 201 | |
| | 202 | except: |
| | 203 | _log.warn('Failed to create spectrogram, using default audio image instead.') |
| | 204 | spectrogram_filepath = 'mediagoblin/static/images/media_thumbs/audio.png' |
| 188 | 205 | |
| 189 | 206 | self.thumbnailer.thumbnail_spectrogram( |
| 190 | 207 | spectrogram_filepath, |