]> git.parisson.com Git - telemeta.git/commitdiff
Adapt analyze method to timeside 0.5.x, update download and streaming format
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 20 Jan 2014 15:56:53 +0000 (16:56 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 20 Jan 2014 16:42:40 +0000 (17:42 +0100)
example/sandbox/settings.py
telemeta/views/item.py

index 38a8743ac72e11b3ffa6f01bd9f7e8553a149189..403e116e613f0bf9a0696f0bc65e6e6d8dc77e5b 100644 (file)
@@ -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']
 
index 766955d1c72d579ccff9f55a0f1ee88f280a5cb2..8330f02e57a0ddcb8b9714428abc843558c3338c 100644 (file)
@@ -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)