From 67ac7fdf56154727eccd4d10ebbe50c4922cb16c Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 2 Jan 2011 15:21:39 +0530 Subject: [PATCH] chop can also work for other formats, default sort --- pandora/archive/extract.py | 5 +++-- pandora/item/views.py | 28 ++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/pandora/archive/extract.py b/pandora/archive/extract.py index 87241ea..ba885be 100644 --- a/pandora/archive/extract.py +++ b/pandora/archive/extract.py @@ -403,7 +403,8 @@ def timeline_strip(item, cuts, info, prefix): def chop(video, start, end): t = end - start tmp = tempfile.mkdtemp() - choped_video = '%s/tmp.webm' % tmp + ext = os.path.splitext(video)[1] + choped_video = '%s/tmp%s' % (tmp, ext) cmd = [ 'ffmpeg', '-y', @@ -412,7 +413,7 @@ def chop(video, start, end): '-t', '%.3f'%t, '-vcodec', 'copy', '-acodec', 'copy', - '-f', 'webm', + '-f', ext[1:], choped_video ] p = subprocess.Popen(cmd, stdin=subprocess.PIPE, diff --git a/pandora/item/views.py b/pandora/item/views.py index 40def7d..389a4a9 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -29,10 +29,19 @@ from api.actions import actions def _order_query(qs, sort, prefix='sort__'): order_by = [] if len(sort) == 1: - if sort[0]['key'] in ('title', 'director'): + if sort[0]['key'] == 'title': sort.append({'operator': '-', 'key': 'year'}) - if sort[0]['key'] in ('year', ): sort.append({'operator': '+', 'key': 'director'}) + elif sort[0]['key'] == 'director': + sort.append({'operator': '-', 'key': 'year'}) + sort.append({'operator': '+', 'key': 'title'}) + elif sort[0]['key'] == 'year': + sort.append({'operator': '+', 'key': 'director'}) + sort.append({'operator': '+', 'key': 'title'}) + else: + sort.append({'operator': '+', 'key': 'director'}) + sort.append({'operator': '-', 'key': 'year'}) + sort.append({'operator': '+', 'key': 'title'}) for e in sort: operator = e['operator'] if operator != '-': @@ -420,24 +429,27 @@ def video(request, id, profile): content_type = path.endswith('.mp4') and 'video/mp4' or 'video/webm' #server side cutting t = request.GET.get('t', None) - if content_type == 'video/webm' and t: + if t: t = map(float, t.split(',')) - if len(t) == 2 and t[1] > t[0] and stream.duration>=t[1]: + ext = os.path.splitext(profile)[1] + 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.webm" % ( + filename = "Clip of %s - %s-%s - %s %s%s" % ( item.get('title'), ox.formatDuration(t[0] * 1000), ox.formatDuration(t[1] * 1000), settings.SITENAME, - item.itemId + item.itemId, + ext ) response['Content-Disposition'] = 'attachment; filename="%s"' % filename return response else: - filename = "%s - %s %s.webm" % ( + filename = "%s - %s %s%s" % ( item.get('title'), settings.SITENAME, - item.itemId + item.itemId, + ext ) response = HttpFileResponse(path, content_type=content_type) response['Content-Disposition'] = 'attachment; filename="%s"' % filename