From 1e904a3645eab8a5bfda8e957d18bdd349a9b6a6 Mon Sep 17 00:00:00 2001 From: yomguy Date: Wed, 1 Dec 2010 09:32:50 +0000 Subject: [PATCH] fix media path handling --- .../templates/telemeta/mediaitem_detail.html | 2 +- telemeta/util/logger.py | 1 + telemeta/web/base.py | 26 +++++++------------ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/telemeta/templates/telemeta/mediaitem_detail.html b/telemeta/templates/telemeta/mediaitem_detail.html index 57ac71d0..c7b3ebdd 100644 --- a/telemeta/templates/telemeta/mediaitem_detail.html +++ b/telemeta/templates/telemeta/mediaitem_detail.html @@ -21,7 +21,7 @@
diff --git a/telemeta/util/logger.py b/telemeta/util/logger.py index f9a032c8..35904bc5 100644 --- a/telemeta/util/logger.py +++ b/telemeta/util/logger.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import logging diff --git a/telemeta/web/base.py b/telemeta/web/base.py index a8fb2f2a..8abc8be9 100644 --- a/telemeta/web/base.py +++ b/telemeta/web/base.py @@ -72,8 +72,8 @@ def stream_from_processor(decoder, processor): break def stream_from_file(file): - chunk_size = 0x1000 - f = open(file, 'r') + chunk_size = 0xFFFF + f = open(file, 'r') while True: _chunk = f.read(chunk_size) if not len(_chunk): @@ -90,8 +90,6 @@ class WebView: analyzers = timeside.core.processors(timeside.api.IAnalyzer) cache = TelemetaCache(settings.TELEMETA_DATA_CACHE_DIR) cache_export = TelemetaCache(settings.TELEMETA_EXPORT_CACHE_DIR) - #FIXME fir dev only - logger = Logger('/tmp/telemeta.log') def index(self, request): """Render the homepage""" @@ -134,8 +132,7 @@ class WebView: analyzers = [] analyzers_sub = [] if item.file: - audio = os.path.join(os.path.dirname(__file__), item.file.path) - decoder = timeside.decoder.FileDecoder(audio) + decoder = timeside.decoder.FileDecoder(item.file.path) self.pipe = decoder for analyzer in self.analyzers: subpipe = analyzer() @@ -183,12 +180,11 @@ class WebView: size = width + '_' + height file = '.'.join([public_id, grapher_id, size, 'png']) - + if not self.cache.exists(file): if item.file: item = MediaItem.objects.get(public_id=public_id) - audio = os.path.join(os.path.dirname(__file__), item.file.path) - decoder = timeside.decoder.FileDecoder(audio) + decoder = timeside.decoder.FileDecoder(item.file.path) graph = grapher(width=int(width), height=int(height)) pipe = decoder | graph pipe.run() @@ -219,20 +215,18 @@ class WebView: mime_type = encoder.mime_type() file = public_id + '.' + encoder.file_extension() - media = self.cache_export.dir + os.sep + file item = MediaItem.objects.get(public_id=public_id) - audio = os.path.join(os.path.dirname(__file__), item.file.path) - - decoder = timeside.decoder.FileDecoder(audio) + decoder = timeside.decoder.FileDecoder(item.file.path) if decoder.format() == mime_type: # source > stream - self.logger.info(audio) - response = HttpResponse(stream_from_file(audio), mimetype = mime_type) + #print item.file.path + response = HttpResponse(stream_from_file(item.file.path), mimetype = mime_type) else: if not self.cache_export.exists(file): # source > encoder > stream + media = self.cache_export.dir + os.sep + file decoder.setup() proc = encoder(media) proc.setup(decoder.channels(), decoder.samplerate()) @@ -240,7 +234,7 @@ class WebView: #enc.set_metadata(metadata) response = HttpResponse(stream_from_processor(decoder, proc), mimetype = mime_type) else: - response = HttpResponse(stream_from_file(media), mimetype = mime_type) + response = HttpResponse(self.cache_export.read_stream_bin(file), mimetype = mime_type) response['Content-Disposition'] = 'attachment' return response -- 2.39.5