Ensure there is never a double space after the title when creating file/folder names in the calibre library

This commit is contained in:
Kovid Goyal 2014-09-14 10:37:54 +05:30
parent 9713536660
commit e7a2bd2691

View File

@ -1111,7 +1111,9 @@ class DB(object):
book_id = ' (%d)' % book_id book_id = ' (%d)' % book_id
l = self.PATH_LIMIT - (len(book_id) // 2) - 2 l = self.PATH_LIMIT - (len(book_id) // 2) - 2
author = ascii_filename(author)[:l].decode('ascii', 'replace') author = ascii_filename(author)[:l].decode('ascii', 'replace')
title = ascii_filename(title)[:l].decode('ascii', 'replace') title = ascii_filename(title.lstrip())[:l].decode('ascii', 'replace').rstrip()
if not title:
title = 'Unknown'[:l]
try: try:
while author[-1] in (' ', '.'): while author[-1] in (' ', '.'):
author = author[:-1] author = author[:-1]
@ -1135,7 +1137,9 @@ class DB(object):
if l < 5: if l < 5:
raise ValueError('Extension length too long: %d' % extlen) raise ValueError('Extension length too long: %d' % extlen)
author = ascii_filename(author)[:l].decode('ascii', 'replace') author = ascii_filename(author)[:l].decode('ascii', 'replace')
title = ascii_filename(title)[:l].decode('ascii', 'replace') title = ascii_filename(title.lstrip())[:l].decode('ascii', 'replace').rstrip()
if not title:
title = 'Unknown'[:l]
name = title + ' - ' + author name = title + ' - ' + author
while name.endswith('.'): while name.endswith('.'):
name = name[:-1] name = name[:-1]