Ticket #5457: 0001-Use-audio-icon-when-spectrogram-fails.-Add-note-to-d.patch

File 0001-Use-audio-icon-when-spectrogram-fails.-Add-note-to-d.patch, 4.6 KB (added by Jorge, 7 years ago)

Use audio icon if the spectrum creation fails. Add TODOs to drop dependency from scikits.audiolab as suggested in ticket:5467#comment:4.

  • docs/source/siteadmin/media-types.rst

    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::  
    142142    not compile it with alsa support. Alsa support is not necessary for the GNU
    143143    MediaGoblin application.
    144144
    145 Then install ``scikits.audiolab`` for the spectrograms::
     145Because of a deprecation issue with Numpy (#5457) you need to hold them at the
     146following versions for the spectrograms:
    146147
    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
     153For python3 ``scikits.audiolab`` has no package yet. Instead of the cool
     154waveform image a static icon is used until we found a replacement. (#5467)
    148155
    149156Add ``[[mediagoblin.media_types.audio]]`` under the ``[plugins]`` section in your
    150157``mediagoblin_local.ini`` and restart MediaGoblin.
  • mediagoblin/media_types/audio/processing.py

    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):  
    148148        _log.info('Creating OGG source for spectrogram')
    149149        self.transcoder.transcode(self.process_filename, wav_tmp,
    150150                                  mux_name='oggmux')
     151
    151152        spectrogram_tmp = os.path.join(self.workbench.dir,
    152153                                       self.name_builder.fill(
    153154                                           '{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,
    162165                     self.name_builder.fill('{basename}.spectrogram.jpg'))
    163166
    164         file_metadata = {'max_width': max_width,
     167            file_metadata = {'max_width': max_width,
    165168                         '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)
    167179
    168180    def generate_thumb(self, size=None):
    169181        if not size:
    class CommonAudioProcessor(MediaProcessor):  
    178190            '{basename}-thumbnail.jpg'))
    179191
    180192        # 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'
    188205
    189206        self.thumbnailer.thumbnail_spectrogram(
    190207            spectrogram_filepath,