From: Rodney Ewing Date: Tue, 13 Aug 2013 18:30:18 +0000 (-0700) Subject: add audio thumbnail and spectrogram resizer X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2e50e4b5f374f10630e078216e1a15b99a7354fd;p=mediagoblin.git add audio thumbnail and spectrogram resizer --- diff --git a/mediagoblin/media_types/audio/processing.py b/mediagoblin/media_types/audio/processing.py index b70f7841..362d2d3c 100644 --- a/mediagoblin/media_types/audio/processing.py +++ b/mediagoblin/media_types/audio/processing.py @@ -227,7 +227,71 @@ class InitialProcessor(CommonAudioProcessor): self.delete_queue_file() +class Resizer(CommonAudioProcessor): + """ + Thumbnail and spectogram resizing process steps for processed audio + """ + name = 'resize' + description = 'Resize audio thumbnail or spectogram' + + @classmethod + def media_is_eligible(cls, entry=None, state=None): + """ + Determine if this media entry is eligible for processing + """ + if not state: + state = entry.state + return state in 'processed' + + @classmethod + def generate_parser(cls): + parser = argparse.ArgumentParser( + description=cls.description, + prog=cls.name) + + parser.add_argument( + '--quality', + help='vorbisenc quality. Range: -0.1..1') + + parser.add_argument( + '--fft_size', + type=int, + help='spectrogram fft size') + + parser.add_argument( + '--thumb_size', + nargs=2, + metavar=('max_width', 'max_height'), + type=int) + + parser.add_argument( + '--medium_width', + type=int, + help='The width of the spectogram') + + parser.add_argument( + 'file', + choices=['thumb', 'spectrogram']) + + return parser + + @classmethod + def args_to_request(cls, args): + return request_from_args( + args, ['thumb_size', 'file', 'quality', 'fft_size', 'medium_width']) + + def process(self, thumb_size=None, file=None, quality=None, fft_size=None, + medium_width=None): + self.common_setup() + if file == 'thumb': + self.generate_thumb(size=thumb_size) + elif file == 'spectrogram': + self.create_spectrogram(quality=quality, max_width=medium_width, + fft_size=fft_size) + + class AudioProcessingManager(ProcessingManager): def __init__(self): super(self.__class__, self).__init__() self.add_processor(InitialProcessor) + self.add_processor(Resizer)