forked from 0x2620/pandora
merge parts into one file on download
This commit is contained in:
parent
cd0284a15c
commit
88068794e4
3 changed files with 40 additions and 0 deletions
|
@ -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()
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -45,6 +45,7 @@ apt-get install -y \
|
|||
libavcodec-extra-53 \
|
||||
libav-tools \
|
||||
ffmpeg2theora \
|
||||
mkvtoolnix \
|
||||
imagemagick \
|
||||
poppler-utils \
|
||||
ipython \
|
||||
|
|
Loading…
Reference in a new issue