add option to have direct download instead of torrent
This commit is contained in:
parent
d8fff463de
commit
f3c9d7b7af
9 changed files with 42 additions and 3 deletions
|
|
@ -19,6 +19,9 @@ urlpatterns = patterns("item.views",
|
|||
(r'^(?P<id>[A-Z0-9].*)/torrent$', 'torrent'),
|
||||
(r'^(?P<id>[A-Z0-9].*)/torrent/(?P<filename>.*?)$', 'torrent'),
|
||||
|
||||
#download
|
||||
(r'^(?P<id>[A-Z0-9].*)/download/$', 'download'),
|
||||
|
||||
#export
|
||||
(r'^(?P<id>[A-Z0-9].*)/json$', 'item_json'),
|
||||
(r'^(?P<id>[A-Z0-9].*)/xml$', 'item_xml'),
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue