better unicode support for download names

This commit is contained in:
j 2012-10-24 17:18:55 +02:00
parent f1a71f23cf
commit ad90b43b4b

View file

@ -6,6 +6,7 @@ from datetime import datetime, timedelta
import mimetypes import mimetypes
import random import random
from urlparse import urlparse from urlparse import urlparse
from urllib import quote
import time import time
import Image import Image
@ -762,7 +763,7 @@ def torrent(request, id, filename=None):
response = HttpResponse(item.get_torrent(request), response = HttpResponse(item.get_torrent(request),
content_type='application/x-bittorrent') content_type='application/x-bittorrent')
filename = utils.safe_filename("%s.torrent" % item.get('title')) filename = utils.safe_filename("%s.torrent" % item.get('title'))
response['Content-Disposition'] = 'attachment; filename="%s"' % filename.encode('utf-8') response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8'))
return response return response
while filename.startswith('/'): while filename.startswith('/'):
filename = filename[1:] filename = filename[1:]
@ -770,8 +771,8 @@ def torrent(request, id, filename=None):
filename = item.path('torrent/%s' % filename) filename = item.path('torrent/%s' % filename)
filename = os.path.abspath(os.path.join(settings.MEDIA_ROOT, filename)) filename = os.path.abspath(os.path.join(settings.MEDIA_ROOT, filename))
response = HttpFileResponse(filename) response = HttpFileResponse(filename)
response['Content-Disposition'] = 'attachment; filename="%s"' % \ response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % \
os.path.basename(filename.encode('utf-8')) quote(os.path.basename(filename.encode('utf-8')))
return response return response
def video(request, id, resolution, format, index=None): def video(request, id, resolution, format, index=None):
@ -817,8 +818,7 @@ def video(request, id, resolution, format, index=None):
item.itemId, item.itemId,
ext ext
) )
filename = filename.encode('utf8') response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8'))
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
return response return response
else: else:
filename = "%s - %s %s%s" % ( filename = "%s - %s %s%s" % (
@ -828,8 +828,7 @@ def video(request, id, resolution, format, index=None):
ext ext
) )
response = HttpFileResponse(path, content_type=content_type) response = HttpFileResponse(path, content_type=content_type)
filename = filename.encode('utf8') response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8'))
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
return response return response
if not settings.XSENDFILE and not settings.XACCELREDIRECT: if not settings.XSENDFILE and not settings.XACCELREDIRECT:
return redirect(stream.video.url) return redirect(stream.video.url)
@ -843,8 +842,8 @@ def srt(request, id, layer, index=None):
response = HttpResponseForbidden() response = HttpResponseForbidden()
else: else:
response = HttpResponse() response = HttpResponse()
filename = "%s.srt" % item.get('title') filename = u"%s.srt" % item.get('title')
response['Content-Disposition'] = 'attachment; filename="%s"' % filename response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8'))
response['Content-Type'] = 'text/x-srt' response['Content-Type'] = 'text/x-srt'
response.write(item.srt(layer)) response.write(item.srt(layer))
return response return response