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'
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