titles are not filename safe
This commit is contained in:
parent
06069b71e2
commit
0700bf7b95
3 changed files with 13 additions and 4 deletions
|
@ -919,13 +919,14 @@ class Item(models.Model):
|
||||||
shutil.rmtree(base)
|
shutil.rmtree(base)
|
||||||
ox.makedirs(base)
|
ox.makedirs(base)
|
||||||
|
|
||||||
base = self.path('torrent/%s' % self.get('title'))
|
filename = utils.sefe_filename(self.get('title'))
|
||||||
|
base = self.path('torrent/%s' % filename)
|
||||||
base = os.path.abspath(os.path.join(settings.MEDIA_ROOT, base))
|
base = os.path.abspath(os.path.join(settings.MEDIA_ROOT, base))
|
||||||
size = 0
|
size = 0
|
||||||
duration = 0.0
|
duration = 0.0
|
||||||
if streams.count() == 1:
|
if streams.count() == 1:
|
||||||
url = "%s/torrent/%s.webm" % (self.get_absolute_url(),
|
url = "%s/torrent/%s.webm" % (self.get_absolute_url(),
|
||||||
quote(self.get('title').encode('utf-8')))
|
quote(filename.encode('utf-8')))
|
||||||
video = "%s.webm" % base
|
video = "%s.webm" % base
|
||||||
v = streams[0]
|
v = streams[0]
|
||||||
os.symlink(v.video.path, video)
|
os.symlink(v.video.path, video)
|
||||||
|
@ -936,7 +937,7 @@ class Item(models.Model):
|
||||||
part = 1
|
part = 1
|
||||||
os.makedirs(base)
|
os.makedirs(base)
|
||||||
for v in streams:
|
for v in streams:
|
||||||
video = "%s/%s.Part %d.webm" % (base, self.get('title'), part)
|
video = "%s/%s.Part %d.webm" % (base, filename, part)
|
||||||
part += 1
|
part += 1
|
||||||
os.symlink(v.video.path, video)
|
os.symlink(v.video.path, video)
|
||||||
size += v.video.size
|
size += v.video.size
|
||||||
|
|
|
@ -6,6 +6,14 @@ import re
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import ox
|
import ox
|
||||||
|
|
||||||
|
def safe_filename(filename):
|
||||||
|
filename = filename.replace('_ ', ': ')
|
||||||
|
filename = filename.replace('/', '_')
|
||||||
|
filename = filename.replace('\\', '_')
|
||||||
|
if filename.endswith('.'):
|
||||||
|
filename = filename[:-1] + '_'
|
||||||
|
return filename
|
||||||
|
|
||||||
def decode_id(id):
|
def decode_id(id):
|
||||||
try:
|
try:
|
||||||
id = ox.fromAZ(id)
|
id = ox.fromAZ(id)
|
||||||
|
|
|
@ -725,7 +725,7 @@ def torrent(request, id, filename=None):
|
||||||
if not filename or filename.endswith('.torrent'):
|
if not filename or filename.endswith('.torrent'):
|
||||||
response = HttpResponse(item.get_torrent(request),
|
response = HttpResponse(item.get_torrent(request),
|
||||||
content_type='application/x-bittorrent')
|
content_type='application/x-bittorrent')
|
||||||
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="%s"' % filename.encode('utf-8')
|
||||||
return response
|
return response
|
||||||
while filename.startswith('/'):
|
while filename.startswith('/'):
|
||||||
|
|
Loading…
Reference in a new issue