]> git.parisson.com Git - telemeta.git/commitdiff
Serve audio media through nginx. Remove streaming capability
authorThomas Fillon <thomas@parisson.com>
Wed, 5 Apr 2017 16:21:03 +0000 (18:21 +0200)
committerThomas Fillon <thomas@parisson.com>
Wed, 5 Apr 2017 16:21:03 +0000 (18:21 +0200)
telemeta/views/core.py
telemeta/views/item.py

index 97cd7c5d81dc6abcfc5d5ecd896eab0f36c4fec1..32aa0b81420f76bc1c36d25d83bde62988209100 100644 (file)
@@ -96,24 +96,25 @@ class TelemetaBaseMixin(object):
 
 
 def serve_media(filename, content_type="", buffering=True):
-    if True:
+    if not settings.DEBUG:
         return nginx_media_accel(filename, content_type=content_type,
                                  buffering=buffering)
     else:
-        pass
-    # response = StreamingHttpResponse(stream_from_file(media.file.path), content_type=media.mime_type)
-    # response['Content-Disposition'] = 'attachment; ' + 'filename=' + filename
+        response = StreamingHttpResponse(stream_from_file(filename), content_type=content_type)
+        response['Content-Disposition'] = 'attachment; ' + 'filename=' + filename
+        return response
 
 
 def nginx_media_accel(media_path, content_type="", buffering=True):
     """Send a protected media file through nginx with X-Accel-Redirect"""
 
     response = HttpResponse()
-    url = settings.MEDIA_URL + media_path
+    url = settings.MEDIA_URL + os.path.relpath(media_path, settings.MEDIA_ROOT)
     filename = os.path.basename(media_path)
     response['Content-Disposition'] = "attachment; filename=%s" % (filename)
     response['Content-Type'] = content_type
     response['X-Accel-Redirect'] = url
+
     if not buffering:
         response['X-Accel-Buffering'] = 'no'
 
index 0f87f2b35ab4dbb1a1161a1075733f11ae5f7f35..0e7ac666ddf76355a6b345fa8d17ffa4df6c634f 100644 (file)
@@ -354,24 +354,28 @@ class ItemView(ItemBaseMixin):
             response = serve_media(source, content_type=mime_type)
         else:
             media = self.cache_export.dir + os.sep + file
-            if not self.cache_export.exists(file) or not flag.value:
+            if not os.path.exists(media) or not flag.value:
                 # source > encoder > stream
-                decoder = timeside.core.get_processor('file_decoder')(source)
-                proc = encoder(media, streaming=False, overwrite=True)
                 if extension in mapping.unavailable_extensions:
                     metadata = None
-                proc.set_metadata(metadata)
-                self.cache_export.add_file(file)
-                pipe = decoder | proc
+
+                decoder = get_processor('file_decoder')(source)
+                processor = encoder(media, streaming=False,
+                                    overwrite=True)
+                if metadata:
+                    processor.set_metadata(metadata)
+                pipe = decoder | processor
                 pipe.run()
+
+                self.cache_export.add_file(file)
                 flag.value = True
                 flag.save()
-                return HttpResponse('Plop')
-                response = StreamingHttpResponse(stream_from_processor(decoder, proc, flag), content_type=mime_type)
+
+                response = serve_media(media, content_type=mime_type)  # , buffering=False)
+
             else:
                 # cache > stream
-
-                response = serve_media(media, content_type=mime_type, buffering=False)
+                response = serve_media(media, content_type=mime_type)
 
         return response