chop can also work for other formats, default sort

This commit is contained in:
j 2011-01-02 15:21:39 +05:30
parent a00b88acd9
commit 67ac7fdf56
2 changed files with 23 additions and 10 deletions

View file

@ -403,7 +403,8 @@ def timeline_strip(item, cuts, info, prefix):
def chop(video, start, end): def chop(video, start, end):
t = end - start t = end - start
tmp = tempfile.mkdtemp() tmp = tempfile.mkdtemp()
choped_video = '%s/tmp.webm' % tmp ext = os.path.splitext(video)[1]
choped_video = '%s/tmp%s' % (tmp, ext)
cmd = [ cmd = [
'ffmpeg', 'ffmpeg',
'-y', '-y',
@ -412,7 +413,7 @@ def chop(video, start, end):
'-t', '%.3f'%t, '-t', '%.3f'%t,
'-vcodec', 'copy', '-vcodec', 'copy',
'-acodec', 'copy', '-acodec', 'copy',
'-f', 'webm', '-f', ext[1:],
choped_video choped_video
] ]
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, p = subprocess.Popen(cmd, stdin=subprocess.PIPE,

View file

@ -29,10 +29,19 @@ from api.actions import actions
def _order_query(qs, sort, prefix='sort__'): def _order_query(qs, sort, prefix='sort__'):
order_by = [] order_by = []
if len(sort) == 1: if len(sort) == 1:
if sort[0]['key'] in ('title', 'director'): if sort[0]['key'] == 'title':
sort.append({'operator': '-', 'key': 'year'}) sort.append({'operator': '-', 'key': 'year'})
if sort[0]['key'] in ('year', ):
sort.append({'operator': '+', 'key': 'director'}) 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: for e in sort:
operator = e['operator'] operator = e['operator']
if operator != '-': if operator != '-':
@ -420,24 +429,27 @@ def video(request, id, profile):
content_type = path.endswith('.mp4') and 'video/mp4' or 'video/webm' content_type = path.endswith('.mp4') and 'video/mp4' or 'video/webm'
#server side cutting #server side cutting
t = request.GET.get('t', None) t = request.GET.get('t', None)
if content_type == 'video/webm' and t: if t:
t = map(float, t.split(',')) 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) 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'), item.get('title'),
ox.formatDuration(t[0] * 1000), ox.formatDuration(t[0] * 1000),
ox.formatDuration(t[1] * 1000), ox.formatDuration(t[1] * 1000),
settings.SITENAME, settings.SITENAME,
item.itemId item.itemId,
ext
) )
response['Content-Disposition'] = 'attachment; filename="%s"' % filename response['Content-Disposition'] = 'attachment; filename="%s"' % filename
return response return response
else: else:
filename = "%s - %s %s.webm" % ( filename = "%s - %s %s%s" % (
item.get('title'), item.get('title'),
settings.SITENAME, settings.SITENAME,
item.itemId item.itemId,
ext
) )
response = HttpFileResponse(path, content_type=content_type) response = HttpFileResponse(path, content_type=content_type)
response['Content-Disposition'] = 'attachment; filename="%s"' % filename response['Content-Disposition'] = 'attachment; filename="%s"' % filename