mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
newdb: Fix temp duplicate catalog entries in book list
Creating a catalog with an already existing catalog in the library would cause a temporary duplicate entry in the book list (the entry would go away on restart. Also fix the author sort for catalogs generated in the AZW3 format not being correct.
This commit is contained in:
parent
40cf046a07
commit
4751aa1286
@ -106,6 +106,7 @@ def add_catalog(cache, path, title):
|
|||||||
from calibre.utils.date import utcnow
|
from calibre.utils.date import utcnow
|
||||||
|
|
||||||
fmt = os.path.splitext(path)[1][1:].lower()
|
fmt = os.path.splitext(path)[1][1:].lower()
|
||||||
|
new_book_added = False
|
||||||
with lopen(path, 'rb') as stream:
|
with lopen(path, 'rb') as stream:
|
||||||
with cache.write_lock:
|
with cache.write_lock:
|
||||||
matches = cache._search('title:="%s" and tags:="%s"' % (title.replace('"', '\\"'), _('Catalog')), None)
|
matches = cache._search('title:="%s" and tags:="%s"' % (title.replace('"', '\\"'), _('Catalog')), None)
|
||||||
@ -118,17 +119,19 @@ def add_catalog(cache, path, title):
|
|||||||
except:
|
except:
|
||||||
mi = Metadata(title, ['calibre'])
|
mi = Metadata(title, ['calibre'])
|
||||||
mi.title, mi.authors = title, ['calibre']
|
mi.title, mi.authors = title, ['calibre']
|
||||||
|
mi.author_sort = 'calibre' # The MOBI/AZW3 format sets author sort to date
|
||||||
mi.tags = [_('Catalog')]
|
mi.tags = [_('Catalog')]
|
||||||
mi.pubdate = mi.timestamp = utcnow()
|
mi.pubdate = mi.timestamp = utcnow()
|
||||||
if fmt == 'mobi':
|
if fmt == 'mobi':
|
||||||
mi.cover, mi.cover_data = None, (None, None)
|
mi.cover, mi.cover_data = None, (None, None)
|
||||||
if db_id is None:
|
if db_id is None:
|
||||||
db_id = cache._create_book_entry(mi, apply_import_tags=False)
|
db_id = cache._create_book_entry(mi, apply_import_tags=False)
|
||||||
|
new_book_added = True
|
||||||
else:
|
else:
|
||||||
cache._set_metadata(db_id, mi)
|
cache._set_metadata(db_id, mi)
|
||||||
cache.add_format(db_id, fmt, stream) # Cant keep write lock since post-import hooks might run
|
cache.add_format(db_id, fmt, stream) # Cant keep write lock since post-import hooks might run
|
||||||
|
|
||||||
return db_id
|
return db_id, new_book_added
|
||||||
|
|
||||||
def add_news(cache, path, arg):
|
def add_news(cache, path, arg):
|
||||||
from calibre.ebooks.metadata.meta import get_metadata
|
from calibre.ebooks.metadata.meta import get_metadata
|
||||||
|
@ -252,8 +252,8 @@ class LibraryDatabase(object):
|
|||||||
return recursive_import(self, root, single_book_per_directory=single_book_per_directory, callback=callback, added_ids=added_ids)
|
return recursive_import(self, root, single_book_per_directory=single_book_per_directory, callback=callback, added_ids=added_ids)
|
||||||
|
|
||||||
def add_catalog(self, path, title):
|
def add_catalog(self, path, title):
|
||||||
book_id = add_catalog(self.new_api, path, title)
|
book_id, new_book_added = add_catalog(self.new_api, path, title)
|
||||||
if book_id is not None:
|
if book_id is not None and new_book_added:
|
||||||
self.data.books_added((book_id,))
|
self.data.books_added((book_id,))
|
||||||
return book_id
|
return book_id
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user