From baa1b4da9923a3838d498c7776e246f0768ab7d0 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Mon, 20 Jan 2014 16:56:53 +0100 Subject: [PATCH] Adapt analyze method to timeside 0.5.x, update download and streaming format --- example/sandbox/settings.py | 4 ++-- telemeta/views/item.py | 31 +++++++++++++++++++------------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/example/sandbox/settings.py b/example/sandbox/settings.py index 38a8743a..403e116e 100644 --- a/example/sandbox/settings.py +++ b/example/sandbox/settings.py @@ -151,8 +151,8 @@ TELEMETA_EXPORT_CACHE_DIR = MEDIA_ROOT + 'export/' TELEMETA_DATA_CACHE_DIR = TELEMETA_CACHE_DIR + "data/" TELEMETA_DOWNLOAD_ENABLED = True -TELEMETA_STREAMING_FORMATS = ('mp3', 'webm') -TELEMETA_DOWNLOAD_FORMATS = ('wav', 'mp3', 'webm') +TELEMETA_STREAMING_FORMATS = ('mp3', 'ogg') +TELEMETA_DOWNLOAD_FORMATS = ('wav', 'mp3', 'ogg', 'flac') TELEMETA_PUBLIC_ACCESS_PERIOD = 51 TELEMETA_DEFAULT_WAVEFORM_SIZES = ['360x130', '640x130'] diff --git a/telemeta/views/item.py b/telemeta/views/item.py index 766955d1..8330f02e 100644 --- a/telemeta/views/item.py +++ b/telemeta/views/item.py @@ -50,6 +50,8 @@ class ItemView(object): export_enabled = getattr(settings, 'TELEMETA_DOWNLOAD_ENABLED', True) export_formats = getattr(settings, 'TELEMETA_DOWNLOAD_FORMATS', ('mp3', 'wav')) + default_analyzers = ['mean_dc_shift', 'level'] + def get_export_formats(self): formats = [] for encoder in self.encoders: @@ -346,7 +348,7 @@ class ItemView(object): def item_analyze(self, item): analyses = MediaItemAnalysis.objects.filter(item=item) mime_type = '' - + if analyses: for analysis in analyses: if not item.approx_duration and analysis.analyzer_id == 'duration': @@ -368,9 +370,10 @@ class ItemView(object): pipe = decoder for analyzer in self.analyzers: - subpipe = analyzer() - analyzers_sub.append(subpipe) - pipe = pipe | subpipe + if analyzer.id() in self.default_analyzers: + subpipe = analyzer() + analyzers_sub.append(subpipe) + pipe = pipe | subpipe try: sizes = settings.TELEMETA_DEFAULT_GRAPHER_SIZES @@ -415,13 +418,16 @@ class ItemView(object): analyzer_id='duration', unit='s', value=unicode(datetime.timedelta(0,decoder.input_duration))) analysis.save() - + for analyzer in analyzers_sub: - value = analyzer.result() - analysis = MediaItemAnalysis(item=item, name=analyzer.name(), - analyzer_id=analyzer.id(), - unit=analyzer.unit(), value=str(value)) - analysis.save() + for key in analyzer.results.keys(): + result = analyzer.results[key] + value = result.data_object.value + if value.shape[0] == 1: + value = value[0] + analysis = MediaItemAnalysis(item=item, name=result.name, + analyzer_id=result.id, unit=result.unit, value = unicode(value)) + analysis.save() # FIXME: parse tags on first load # tags = decoder.tags @@ -544,10 +550,11 @@ class ItemView(object): media = self.cache_export.dir + os.sep + file if not self.cache_export.exists(file) or not flag.value: # source > encoder > stream - decoder = self.decoders[0](audio) + decoder = timeside.decoder.FileDecoder(audio) decoder.setup() proc = encoder(media, streaming=True, overwrite=True) - proc.setup(channels=decoder.channels(), samplerate=decoder.samplerate()) + proc.setup(channels=decoder.channels(), samplerate=decoder.samplerate(), + blocksize=decoder.blocksize(), totalframes=decoder.totalframes()) if extension in mapping.unavailable_extensions: metadata=None response = HttpResponse(stream_from_processor(decoder, proc, flag, metadata=metadata), mimetype = mime_type) -- 2.39.5