Added x-sendfile support

This commit is contained in:
fergal.moran
2012-09-10 13:55:03 +01:00
parent ef1399f6f7
commit ba9657a40d
11 changed files with 13 additions and 10 deletions

0
_working/create Executable file → Normal file
View File

View File

@@ -215,4 +215,8 @@ PIPELINE_CSS = {
}, },
} }
INTERNAL_IPS = ('127.0.0.1',) INTERNAL_IPS = ('127.0.0.1',)
GOOGLE_ANALYTICS_CODE = localsettings.GOOGLE_ANALYTICS_CODE GOOGLE_ANALYTICS_CODE = localsettings.GOOGLE_ANALYTICS_CODE
SENDFILE_BACKEND = localsettings.SENDFILE_BACKEND
SENDFILE_ROOT = os.path.join(MEDIA_ROOT, 'mixes')
SENDFILE_URL = '/mixes'

0
manage.py Executable file → Normal file
View File

View File

@@ -2,13 +2,9 @@ from wsgiref.util import FileWrapper
from django.conf.urls import url from django.conf.urls import url
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
import os import os
from sendfile import sendfile
from spa.models.Mix import Mix from spa.models.Mix import Mix
class FixedFileWrapper(FileWrapper):
def __iter__(self):
self.filelike.seek(0)
return self
class AudioHandler(object): class AudioHandler(object):
@property @property
def urls(self): def urls(self):
@@ -22,13 +18,15 @@ def start_streaming(request, mix_id):
mix = Mix.objects.get(pk=mix_id) mix = Mix.objects.get(pk=mix_id)
if mix is not None: if mix is not None:
filename = mix.local_file.file.name # Select your file here. filename = mix.local_file.file.name # Select your file here.
wrapper = FixedFileWrapper(open(filename, 'rb')) response = sendfile(request, filename)
response = HttpResponse(wrapper, content_type='audio/mpeg') """
#wrapper = FixedFileWrapper(open(filename, 'rb'))
response = HttpResponse(FileIterWrapper(open(filename)), content_type='audio/mpeg')
response['Content-Length'] = os.path.getsize(filename) response['Content-Length'] = os.path.getsize(filename)
response['Content-Type'] = "audio/mpeg" response['Content-Type'] = "audio/mpeg"
response['Content-Disposition'] = "inline; filename=stream.mp3"
response['Cache-Control'] = "no-cache"
response['Content-Transfer-Encoding'] = "binary" response['Content-Transfer-Encoding'] = "binary"
response['Cache-Control'] = "no-cache"
"""
return response return response
except Exception, ex: except Exception, ex:
print ex print ex

View File

@@ -62,6 +62,7 @@ class Mix(_BaseModel):
return settings.STATIC_URL + 'img/default-track.png' return settings.STATIC_URL + 'img/default-track.png'
def get_stream_path(self): def get_stream_path(self):
#return 'media/%s/' % self.local_file.name
return '/audio/stream/%d' % self.id; return '/audio/stream/%d' % self.id;
@classmethod @classmethod

0
static/bin/sm/soundmanager2.swf Executable file → Normal file
View File

0
static/bin/sm/soundmanager2_debug.swf Executable file → Normal file
View File

0
static/bin/sm/soundmanager2_flash9.swf Executable file → Normal file
View File

0
static/bin/sm/soundmanager2_flash9_debug.swf Executable file → Normal file
View File

0
static/img/whats-on.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

0
static/js/libs/sm/soundmanager2.js Executable file → Normal file
View File