filenames

This commit is contained in:
j 2014-05-19 13:09:12 +02:00
parent 2b46ad2c16
commit a35eb0db92
1 changed files with 7 additions and 4 deletions

View File

@ -474,6 +474,8 @@ class File(db.Model):
return os.path.join(prefix, self.path)
def move(self):
def format_underscores(string):
return re.sub('^\.|\.$|:|/|\?|<|>', '_', string)
prefs = settings.preferences
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/')
j = self.item.json()
@ -484,12 +486,13 @@ class File(db.Model):
author = 'Unknown Author'
title = j.get('title', 'Untitled')
extension = j['extension']
if len(title) > 100:
title = title[:100]
if author.endswith('.'):
author = author[:-1] + '_'
if author.startswith('.'):
author = '_' + author[1:]
title = format_underscores(title)
author = format_underscores(author)
filename = '%s.%s' % (title, extension)
new_path = os.path.join(author[0].upper(), author, filename)
if self.path == new_path: