From e12b60a81225c0c014210642d94019332f26402c Mon Sep 17 00:00:00 2001 From: yomguy Date: Thu, 19 Apr 2012 16:26:20 +0200 Subject: [PATCH] add all graphers to first analyses, set new settings parameter for default size values --- example/sandbox_sqlite/settings.py | 3 +++ telemeta/views/base.py | 35 ++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/example/sandbox_sqlite/settings.py b/example/sandbox_sqlite/settings.py index 2ff3f4d1..b338bd60 100644 --- a/example/sandbox_sqlite/settings.py +++ b/example/sandbox_sqlite/settings.py @@ -149,8 +149,11 @@ TELEMETA_DOWNLOAD_ENABLED = True TELEMETA_STREAMING_FORMATS = ('mp3', 'webm') TELEMETA_DOWNLOAD_FORMATS = ('wav', 'mp3', 'webm') TELEMETA_PUBLIC_ACCESS_PERIOD = 51 +TELEMETA_DEFAULT_WAVEFORM_SIZES = ['360x130', '640x130'] + AUTH_PROFILE_MODULE = 'telemeta.userprofile' SESSION_EXPIRE_AT_BROWSER_CLOSE = False EMAIL_HOST = 'localhost' DEFAULT_FROM_EMAIL = 'webmaster@parisson.com' + diff --git a/telemeta/views/base.py b/telemeta/views/base.py index f43be2a6..59cb9456 100644 --- a/telemeta/views/base.py +++ b/telemeta/views/base.py @@ -630,7 +630,10 @@ class ItemView(object): if request.REQUEST.has_key('grapher_id'): grapher_id = request.REQUEST['grapher_id'] else: - grapher_id = 'waveform' + try: + grapher_id = settings.TELEMETA_DEFAULT_GRAPHER_ID + except: + grapher_id = 'waveform' previous, next = self.item_previous_next(item) mime_type = self.item_analyze(item) @@ -681,7 +684,10 @@ class ItemView(object): if request.REQUEST.has_key('grapher_id'): grapher_id = request.REQUEST['grapher_id'] else: - grapher_id = 'waveform' + try: + grapher_id = settings.TELEMETA_DEFAULT_GRAPHER_ID + except: + grapher_id = 'waveform' previous, next = self.item_previous_next(item) mime_type = self.item_analyze(item) @@ -830,15 +836,40 @@ class ItemView(object): else: analyzers = [] analyzers_sub = [] + graphers_sub = [] + if item.file: decoder = timeside.decoder.FileDecoder(item.file.path) pipe = decoder + for analyzer in self.analyzers: subpipe = analyzer() analyzers_sub.append(subpipe) pipe = pipe | subpipe + + try: + sizes = settings.TELEMETA_DEFAULT_GRAPHER_SIZES + except: + sizes = ['360x130', ] + + for grapher in self.graphers: + for size in sizes: + width = size.split('x')[0] + height = size.split('x')[1] + image_file = '.'.join([item.public_id, grapher.id(), size.replace('x', '_'), 'png']) + path = self.cache_data.dir + os.sep + image_file + graph = grapher(width = int(width), height = int(height)) + graphers_sub.append({'graph' : graph, 'path': path}) + pipe = pipe | graph + pipe.run() + for grapher in graphers_sub: + grapher['graph'].watermark('timeside', opacity=.6, margin=(5,5)) + f = open(grapher['path'], 'w') + grapher['graph'].render(grapher['path']) + f.close() + mime_type = decoder.format() analysis = MediaItemAnalysis(item=item, name='MIME type', analyzer_id='mime_type', unit='', value=mime_type) -- 2.39.5