mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When doing device book matching: on UUID matches, generate covers only if the last_modified date of the book in the db is later than the date on the book on the device, or if existing thumbnail is not the size that the device asked for.
This commit is contained in:
parent
9e1627569f
commit
d2866a2208
@ -1661,9 +1661,11 @@ class DeviceMixin(object): # {{{
|
|||||||
update_metadata = device_prefs['manage_device_metadata'] == 'on_connect'
|
update_metadata = device_prefs['manage_device_metadata'] == 'on_connect'
|
||||||
|
|
||||||
get_covers = False
|
get_covers = False
|
||||||
|
desired_thumbnail_height = 0
|
||||||
if update_metadata and self.device_manager.is_device_connected:
|
if update_metadata and self.device_manager.is_device_connected:
|
||||||
if self.device_manager.device.WANTS_UPDATED_THUMBNAILS:
|
if self.device_manager.device.WANTS_UPDATED_THUMBNAILS:
|
||||||
get_covers = True
|
get_covers = True
|
||||||
|
desired_thumbnail_height = self.device_manager.device.THUMBNAIL_HEIGHT
|
||||||
|
|
||||||
# Force a reset if the caches are not initialized
|
# Force a reset if the caches are not initialized
|
||||||
if reset or not hasattr(self, 'db_book_title_cache'):
|
if reset or not hasattr(self, 'db_book_title_cache'):
|
||||||
@ -1698,17 +1700,28 @@ class DeviceMixin(object): # {{{
|
|||||||
# will be used by books_on_device to indicate matches. While we are
|
# will be used by books_on_device to indicate matches. While we are
|
||||||
# going by, update the metadata for a book if automatic management is on
|
# going by, update the metadata for a book if automatic management is on
|
||||||
|
|
||||||
|
def update_book(id_, book) :
|
||||||
|
if not update_metadata:
|
||||||
|
return
|
||||||
|
mi = db.get_metadata(id_, index_is_id=True, get_cover=get_covers)
|
||||||
|
book.smart_update(mi, replace_metadata=True)
|
||||||
|
if get_covers:
|
||||||
|
if book.cover and os.access(book.cover, os.R_OK):
|
||||||
|
book.thumbnail = self.cover_to_thumbnail(open(book.cover, 'rb').read())
|
||||||
|
else:
|
||||||
|
book.thumbnail = self.default_thumbnail
|
||||||
|
|
||||||
for booklist in booklists:
|
for booklist in booklists:
|
||||||
for book in booklist:
|
for book in booklist:
|
||||||
book.in_library = None
|
book.in_library = None
|
||||||
if getattr(book, 'uuid', None) in self.db_book_uuid_cache:
|
if getattr(book, 'uuid', None) in self.db_book_uuid_cache:
|
||||||
id_ = db_book_uuid_cache[book.uuid]
|
id_ = db_book_uuid_cache[book.uuid]
|
||||||
if (update_metadata and
|
if (db.metadata_last_modified(id_, index_is_id=True) !=
|
||||||
db.metadata_last_modified(id_, index_is_id=True) !=
|
getattr(book, 'last_modified', None)
|
||||||
getattr(book, 'last_modified', None)):
|
or (not book.thumbnail
|
||||||
mi = db.get_metadata(id_, index_is_id=True,
|
or max(book.thumbnail[0], book.thumbnail[1]) !=
|
||||||
get_cover=get_covers)
|
desired_thumbnail_height)):
|
||||||
book.smart_update(mi, replace_metadata=True)
|
update_book(id_, book)
|
||||||
book.in_library = 'UUID'
|
book.in_library = 'UUID'
|
||||||
# ensure that the correct application_id is set
|
# ensure that the correct application_id is set
|
||||||
book.application_id = id_
|
book.application_id = id_
|
||||||
@ -1721,23 +1734,15 @@ class DeviceMixin(object): # {{{
|
|||||||
# will match if any of the db_id, author, or author_sort
|
# will match if any of the db_id, author, or author_sort
|
||||||
# also match.
|
# also match.
|
||||||
if getattr(book, 'application_id', None) in d['db_ids']:
|
if getattr(book, 'application_id', None) in d['db_ids']:
|
||||||
if update_metadata:
|
id_ = getattr(book, 'application_id', None)
|
||||||
id_ = getattr(book, 'application_id', None)
|
update_book(id_, book)
|
||||||
book.smart_update(db.get_metadata(id_,
|
|
||||||
index_is_id=True,
|
|
||||||
get_cover=get_covers),
|
|
||||||
replace_metadata=True)
|
|
||||||
book.in_library = 'APP_ID'
|
book.in_library = 'APP_ID'
|
||||||
# app_id already matches a db_id. No need to set it.
|
# app_id already matches a db_id. No need to set it.
|
||||||
continue
|
continue
|
||||||
# Sonys know their db_id independent of the application_id
|
# Sonys know their db_id independent of the application_id
|
||||||
# in the metadata cache. Check that as well.
|
# in the metadata cache. Check that as well.
|
||||||
if getattr(book, 'db_id', None) in d['db_ids']:
|
if getattr(book, 'db_id', None) in d['db_ids']:
|
||||||
if update_metadata:
|
update_book(book.db_id, book)
|
||||||
book.smart_update(db.get_metadata(book.db_id,
|
|
||||||
index_is_id=True,
|
|
||||||
get_cover=get_covers),
|
|
||||||
replace_metadata=True)
|
|
||||||
book.in_library = 'DB_ID'
|
book.in_library = 'DB_ID'
|
||||||
book.application_id = book.db_id
|
book.application_id = book.db_id
|
||||||
continue
|
continue
|
||||||
@ -1752,20 +1757,12 @@ class DeviceMixin(object): # {{{
|
|||||||
book_authors = clean_string(authors_to_string(book.authors))
|
book_authors = clean_string(authors_to_string(book.authors))
|
||||||
if book_authors in d['authors']:
|
if book_authors in d['authors']:
|
||||||
id_ = d['authors'][book_authors]
|
id_ = d['authors'][book_authors]
|
||||||
if update_metadata:
|
update_book(id_, book)
|
||||||
book.smart_update(db.get_metadata(id_,
|
|
||||||
index_is_id=True,
|
|
||||||
get_cover=get_covers),
|
|
||||||
replace_metadata=True)
|
|
||||||
book.in_library = 'AUTHOR'
|
book.in_library = 'AUTHOR'
|
||||||
book.application_id = id_
|
book.application_id = id_
|
||||||
elif book_authors in d['author_sort']:
|
elif book_authors in d['author_sort']:
|
||||||
id_ = d['author_sort'][book_authors]
|
id_ = d['author_sort'][book_authors]
|
||||||
if update_metadata:
|
update_book(id_, book)
|
||||||
book.smart_update(db.get_metadata(id_,
|
|
||||||
index_is_id=True,
|
|
||||||
get_cover=get_covers),
|
|
||||||
replace_metadata=True)
|
|
||||||
book.in_library = 'AUTH_SORT'
|
book.in_library = 'AUTH_SORT'
|
||||||
book.application_id = id_
|
book.application_id = id_
|
||||||
else:
|
else:
|
||||||
@ -1779,12 +1776,6 @@ class DeviceMixin(object): # {{{
|
|||||||
|
|
||||||
if update_metadata:
|
if update_metadata:
|
||||||
if self.device_manager.is_device_connected:
|
if self.device_manager.is_device_connected:
|
||||||
if self.device_manager.device.WANTS_UPDATED_THUMBNAILS:
|
|
||||||
for blist in booklists:
|
|
||||||
for book in blist:
|
|
||||||
if book.cover and os.access(book.cover, os.R_OK):
|
|
||||||
book.thumbnail = \
|
|
||||||
self.cover_to_thumbnail(open(book.cover, 'rb').read())
|
|
||||||
plugboards = self.library_view.model().db.prefs.get('plugboards', {})
|
plugboards = self.library_view.model().db.prefs.get('plugboards', {})
|
||||||
self.device_manager.sync_booklists(
|
self.device_manager.sync_booklists(
|
||||||
FunctionDispatcher(self.metadata_synced), booklists,
|
FunctionDispatcher(self.metadata_synced), booklists,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user