simplify stream lookup

This commit is contained in:
j 2011-08-19 20:10:28 +02:00
parent af671dc779
commit 181d8196fc

View file

@ -2,7 +2,7 @@
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import division from __future__ import division
import os.path import os.path
from datetime import datetime from datetime import datetime, timedelta
import mimetypes import mimetypes
from django.db.models import Count, Sum, Max from django.db.models import Count, Sum, Max
@ -22,7 +22,7 @@ import models
import utils import utils
import tasks import tasks
from archive.models import File from archive.models import File, Stream
from archive import extract from archive import extract
from annotation.models import Annotation from annotation.models import Annotation
@ -658,14 +658,13 @@ def video(request, id, resolution, format, index=None):
index = int(index) - 1 index = int(index) - 1
else: else:
index = 0 index = 0
videos = item.main_videos() streams= Stream.objects.filter(file__item__itemId=item.itemId,
if index > len(videos): resolution=resolution, format=format)
if index > streams.count():
raise Http404 raise Http404
stream = streams[index]
stream = videos[index].streams.filter(resolution=resolution, format=format) if not stream.available or not stream.video:
if stream.count() == 0:
raise Http404 raise Http404
stream = stream[0]
path = stream.video.path path = stream.video.path
#server side cutting #server side cutting
@ -699,4 +698,6 @@ def video(request, id, resolution, format, index=None):
return response return response
if not settings.XSENDFILE and not settings.XACCELREDIRECT: if not settings.XSENDFILE and not settings.XACCELREDIRECT:
return redirect(stream.video.url) return redirect(stream.video.url)
return HttpFileResponse(path) response = HttpFileResponse(path)
response['Cache-Control'] = 'public'
return response