From 1d38cede3b1176df518f8a358bcd945420f3458d Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 27 Jun 2011 21:40:44 +0200 Subject: [PATCH] expose parts --- pandora/item/models.py | 2 +- pandora/item/urls.py | 4 ++-- pandora/item/views.py | 15 ++++++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index cf770259a..4416bf667 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -589,7 +589,7 @@ class Item(models.Model): def main_videos(self): #FIXME: needs to check if more than one user has main files and only # take from "higher" user - videos = self.files.filter(is_main=True, is_video=True, available=True).order_by('part') + videos = self.files.filter(is_main=True, is_video=True, available=True, instances__gt=0).order_by('part') if videos.count()>0: first = videos[0] user = first.instances.all()[0].volume.user diff --git a/pandora/item/urls.py b/pandora/item/urls.py index 583011dd7..7fee4708f 100644 --- a/pandora/item/urls.py +++ b/pandora/item/urls.py @@ -6,8 +6,8 @@ from django.conf.urls.defaults import * urlpatterns = patterns("item.views", (r'^(?P[A-Z0-9].*)/frame/(?P\d+)/(?P[0-9\.,]+).jpg$', 'frame'), - (r'^(?P[A-Z0-9].*)/(?P.*.webm)$', 'video'), - (r'^(?P[A-Z0-9].*)/(?P.*.mp4)$', 'video'), + (r'^(?P[A-Z0-9].*)/(?P[a-f0-9]+)/(?P.*.[webm|ogv|mp4])$', 'video'), + (r'^(?P[A-Z0-9].*)/(?P.*.[webm|ogv|mp4])$', 'video'), (r'^(?P[A-Z0-9].*)/poster\.(?P\d+)\.jpg$', 'poster'), (r'^(?P[A-Z0-9].*)/poster\.(?Plarge)\.jpg$', 'poster'), (r'^(?P[A-Z0-9].*)/poster\.jpg$', 'poster'), diff --git a/pandora/item/views.py b/pandora/item/views.py index e3f800a9d..df214b598 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -3,6 +3,7 @@ from __future__ import division import os.path from datetime import datetime +import mimetypes from django.db.models import Count, Sum, Max from django.http import HttpResponse, Http404 @@ -581,16 +582,20 @@ def timeline_overview(request, id, size): return HttpFileResponse(timeline, content_type='image/png') -def video(request, id, profile): +def video(request, id, profile, oshash=None): item = get_object_or_404(models.Item, itemId=id) - stream = get_object_or_404(item.streams, profile=profile) - path = stream.video.path - content_type = path.endswith('.mp4') and 'video/mp4' or 'video/webm' + if oshash: + stream = get_object_or_404(item.files, oshash=oshash) + path = stream.video.path + else: + stream = get_object_or_404(item.streams, profile=profile) + path = stream.video.path #server side cutting t = request.GET.get('t') if t: t = map(float, t.split(',')) ext = os.path.splitext(profile)[1] + content_type = mimetypes.guess_type(path)[0] if len(t) == 2 and t[1] > t[0] and stream.info['duration']>=t[1]: response = HttpResponse(extract.chop(path, t[0], t[1]), content_type=content_type) filename = "Clip of %s - %s-%s - %s %s%s" % ( @@ -613,4 +618,4 @@ def video(request, id, profile): response = HttpFileResponse(path, content_type=content_type) response['Content-Disposition'] = 'attachment; filename="%s"' % filename return response - return HttpFileResponse(path, content_type=content_type) + return HttpFileResponse(path)