]> git.parisson.com Git - telemeta.git/commitdiff
speed up forst process by adding the default waveform to the pipe
authoryomguy <yomguy@parisson.com>
Tue, 29 Mar 2011 23:21:44 +0000 (01:21 +0200)
committeryomguy <yomguy@parisson.com>
Tue, 29 Mar 2011 23:21:44 +0000 (01:21 +0200)
telemeta/web/base.py

index 6d9a7f62016003d828f3a0c761b5118b062ee455..8275aa8edcdc74d86f3cfec4ccd2d8c4a4aaf3ae 100644 (file)
@@ -389,6 +389,13 @@ class WebView(object):
                         item.approx_duration = str(time)
                         item.save()
         else:
+            # process first waveform to speed up imports
+            width = 360
+            height = 130
+            size =  str(width) + '_' + str(height)
+            grapher_id = 'waveform'
+            image_file = '.'.join([public_id, grapher_id, size, 'png'])
+            
             analyzers = []
             analyzers_sub = []
             if item.file:
@@ -398,7 +405,18 @@ class WebView(object):
                     subpipe = analyzer()
                     analyzers_sub.append(subpipe)
                     pipe = pipe | subpipe
+                if not self.cache_data.exists(image_file):
+                    path = self.cache_data.dir + os.sep + image_file
+                    for grapher in self.graphers:
+                        if grapher.id() == grapher_id:
+                            break
+                    graph = grapher(width = int(width), height = int(height))
+                    pipe = pipe | graph
                 pipe.run()
+                if not self.cache_data.exists(image_file):
+                    f = open(path, 'w')
+                    graph.render(path)
+                    f.close()
                 mime_type = decoder.format()
                 analyzers.append({'name': 'Mime type', 'id': 'mime_type', 'unit': '', 'value': mime_type})
                 analyzers.append({'name': 'Channels', 'id': 'channels', 'unit': '', 'value': decoder.channels()})