add option to have direct download instead of torrent

This commit is contained in:
j 2013-09-14 14:09:37 +00:00
commit f3c9d7b7af
9 changed files with 42 additions and 3 deletions

View file

@ -831,6 +831,36 @@ def timeline(request, id, size, position=-1, format='jpg', mode=None):
path = timeline()
return HttpFileResponse(path, content_type='image/jpeg')
def download(request, id, index=1):
item = get_object_or_404(models.Item, itemId=id)
resolution = max(settings.CONFIG['video']['resolutions'])
format = 'webm'
if not item.access(request.user):
return HttpResponseForbidden()
if index:
index = int(index) - 1
else:
index = 0
streams = item.streams()
if index + 1 > streams.count():
raise Http404
stream = streams[index].get(resolution, format)
if not stream.available or not stream.media:
raise Http404
path = stream.media.path
content_type = mimetypes.guess_type(path)[0]
ext = os.path.splitext(path)[-1]
filename = "%s - %s %s%s" % (
item.get('title'),
settings.SITENAME,
item.itemId,
ext
)
response = HttpFileResponse(path, 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):