diff --git a/pandora/item/models.py b/pandora/item/models.py index cf770259..4416bf66 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 583011dd..7fee4708 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 e3f800a9..df214b59 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)