From 88068794e4aa60b8b79597cf20aa23033fd148dc Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 13 Feb 2014 18:48:47 +0000 Subject: [PATCH] merge parts into one file on download --- pandora/item/models.py | 12 ++++++++++++ pandora/item/views.py | 27 +++++++++++++++++++++++++++ vm/firstboot.sh | 1 + 3 files changed, 40 insertions(+) diff --git a/pandora/item/models.py b/pandora/item/models.py index 39b36838d..26b4266c3 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1180,6 +1180,18 @@ class Item(models.Model): Q(file__is_audio=True)|Q(file__is_video=True) ).order_by('file__part', 'file__sort_path') + def merge_streams(self, output): + first = True + cmd = ['mkvmerge', '-o', output] + streams = [s.media.path for s in self.streams()] + if len(streams) > 1: + cmd += [streams[0]] + ['+' + s for s in streams[1:]] + print cmd + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p.wait() + return True + return streams[0] if streams else None + def update_timeline(self, force=False, async=True): streams = self.streams() self.make_timeline() diff --git a/pandora/item/views.py b/pandora/item/views.py index b0927d907..55bd6b3a1 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -13,6 +13,8 @@ from django.db.models import Count, Sum from django.template import RequestContext from django.http import HttpResponse, HttpResponseForbidden, Http404 from django.shortcuts import get_object_or_404, redirect, render_to_response +from django.core.files.temp import NamedTemporaryFile +from django.core.servers.basehttp import FileWrapper from django.conf import settings from ox.utils import json, ET @@ -868,6 +870,31 @@ def download(request, id, index=1): response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8')) return response +def download(request, id): + item = get_object_or_404(models.Item, itemId=id) + resolution = max(settings.CONFIG['video']['resolutions']) + if not item.access(request.user) or not item.rendered: + return HttpResponseForbidden() + ext = '.webm' + filename = "%s - %s %s%s" % ( + item.get('title'), + settings.SITENAME, + item.itemId, + ext + ) + video = NamedTemporaryFile(suffix=ext) + content_type = mimetypes.guess_type(video.name)[0] + r = item.merge_streams(video.name) + if not r: + return HttpResponseForbidden() + elif r == True: + response = HttpResponse(FileWrapper(video), content_type=content_type) + response['Content-Length'] = os.path.getsize(video.name) + else: + response = HttpFileResponse(r, content_type=content_type) + response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8')) + return response + def torrent(request, id, filename=None): item = get_object_or_404(models.Item, itemId=id) if not item.access(request.user): diff --git a/vm/firstboot.sh b/vm/firstboot.sh index 2c60b6f11..71c4f5203 100755 --- a/vm/firstboot.sh +++ b/vm/firstboot.sh @@ -45,6 +45,7 @@ apt-get install -y \ libavcodec-extra-53 \ libav-tools \ ffmpeg2theora \ + mkvtoolnix \ imagemagick \ poppler-utils \ ipython \