filenames
This commit is contained in:
parent
2b46ad2c16
commit
a35eb0db92
1 changed files with 7 additions and 4 deletions
|
@ -474,6 +474,8 @@ class File(db.Model):
|
||||||
return os.path.join(prefix, self.path)
|
return os.path.join(prefix, self.path)
|
||||||
|
|
||||||
def move(self):
|
def move(self):
|
||||||
|
def format_underscores(string):
|
||||||
|
return re.sub('^\.|\.$|:|/|\?|<|>', '_', string)
|
||||||
prefs = settings.preferences
|
prefs = settings.preferences
|
||||||
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/')
|
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/')
|
||||||
j = self.item.json()
|
j = self.item.json()
|
||||||
|
@ -484,12 +486,13 @@ class File(db.Model):
|
||||||
author = 'Unknown Author'
|
author = 'Unknown Author'
|
||||||
title = j.get('title', 'Untitled')
|
title = j.get('title', 'Untitled')
|
||||||
extension = j['extension']
|
extension = j['extension']
|
||||||
|
|
||||||
if len(title) > 100:
|
if len(title) > 100:
|
||||||
title = title[:100]
|
title = title[:100]
|
||||||
if author.endswith('.'):
|
|
||||||
author = author[:-1] + '_'
|
title = format_underscores(title)
|
||||||
if author.startswith('.'):
|
author = format_underscores(author)
|
||||||
author = '_' + author[1:]
|
|
||||||
filename = '%s.%s' % (title, extension)
|
filename = '%s.%s' % (title, extension)
|
||||||
new_path = os.path.join(author[0].upper(), author, filename)
|
new_path = os.path.join(author[0].upper(), author, filename)
|
||||||
if self.path == new_path:
|
if self.path == new_path:
|
||||||
|
|
Loading…
Reference in a new issue