mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Save to Disk: Fix a bug where when multiple books are being saved to disk, if the save to disk template results in identical filenames, the filenames were not being properly disambiguated.
This commit is contained in:
parent
4cfcad0024
commit
18bd7879ed
@ -29,18 +29,17 @@ from calibre.library.save_to_disk import sanitize_args, get_path_components, fin
|
||||
BookId = namedtuple('BookId', 'title authors')
|
||||
|
||||
def ensure_unique_components(data): # {{{
|
||||
cmap = {}
|
||||
cmap = defaultdict(set)
|
||||
bid_map = {}
|
||||
for book_id, (mi, components, fmts) in data.iteritems():
|
||||
c = tuple(components)
|
||||
if c in cmap:
|
||||
cmap[c].add(book_id)
|
||||
else:
|
||||
cmap[c] = {book_id}
|
||||
cmap[tuple(components)].add(book_id)
|
||||
bid_map[book_id] = components
|
||||
|
||||
for book_ids in cmap.itervalues():
|
||||
if len(book_ids) > 1:
|
||||
for i, book_id in enumerate(sorted(book_ids)[1:]):
|
||||
suffix = ' (%d)' % (i + 1)
|
||||
components = bid_map[book_id]
|
||||
components[-1] = components[-1] + suffix
|
||||
# }}}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user