ok, i am a step closer, i now implemented range requests:

def sendFileRange(req, contenttype, fname, delivername):
        try:
                fsize=os.path.getsize(fname)
        except:
                raise Http404

        pos1=0
        pos2=fsize-1
        if req.META.has_key('HTTP_RANGE'):
                arr=req.META['HTTP_RANGE'].split('=')
                if (len(arr)>1) and (arr[0]=='bytes'):
                        r=arr[1]
                        values=r.split('-')
                        if len(values)>1:
                                if (r[0]=='-'):
                                        p1=0
                                        p2=int(values[1])
                                elif (r[-1]=='-'):
                                        p1=int(values[0])
                                        p2=fsize-1
                                else:
                                        p1=int(values[0])
                                        p2=int(values[1])
                                if (p2>p1):
                                        pos1=p1
                                        pos2=p2

        numbytes=(pos2-pos1)+1

        try:
                f=open(fname,'rb')
                f.seek(pos1)
                data=f.read(numbytes)
                f.close()
        except:
                raise Http404

        resp=HttpResponse(data, contenttype, 206)
        resp['Accept-Ranges']='bytes'
        if req.META.has_key('HTTP_RANGE'):
                resp['Content-Range']='bytes %d-%d/%d' % (pos1, pos2,
fsize)
        resp['Content-Length'] = numbytes
        resp['Content-Disposition'] = 'attachment; filename=%s' %
(delivername)
        return resp

def download(req, video_id, video_type):
        ctype='';
        if (video_type=='ogv'):
                ctype='video/ogg'
        elif (video_type=='mp4'):
                ctype='video/mp4'

        if (ctype==''):
                raise Http404

        fname='%s%s.%s' % (settings.VIDEO_ROOT, 'test', video_type)
        return sendFileRange(req, ctype, fname, 'video%d.%s' %
(int(video_id), video_type))

this works now for firefox and i assume all other theora playing
browsers, but chrome and IE, that play the mp4 file fail, actually the
django server fails:

with IE9 i get:

[24/Dec/2010 21:32:09] code 400, message Bad request version ('RTSP/
1.0')
[24/Dec/2010 21:32:09] "DESCRIBE rtsp://mysite:8000/myapp/download/1.mp4
RTSP/1.0" 400 -
Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/Django-1.2.3-py2.4.egg/django/
core/servers/basehttp.py", line 281, in run
    self.finish_response()
  File "/usr/lib/python2.4/site-packages/Django-1.2.3-py2.4.egg/django/
core/servers/basehttp.py", line 321, in finish_response
    self.write(data)
  File "/usr/lib/python2.4/site-packages/Django-1.2.3-py2.4.egg/django/
core/servers/basehttp.py", line 417, in write
    self._write(data)
  File "/usr/lib64/python2.4/socket.py", line 256, in write
    self.flush()
  File "/usr/lib64/python2.4/socket.py", line 243, in flush
    self._sock.sendall(buffer)
error: (32, 'Broken pipe')

with chrome the same, but without the RTSP lines

any ideas?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to