mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-04-11 19:51:59 -04:00
Merge branch 'copilot/fix-cover-image-on-book-records' of https://github.com/kovidgoyal/calibre
This commit is contained in:
commit
8bf08af7b8
@ -20,6 +20,8 @@ def automerge_book(automerge_action, book_id, mi, identical_book_list, newdb, fo
|
||||
at_least_one_format_added = True
|
||||
if at_least_one_format_added and extra_file_map:
|
||||
newdb.add_extra_files(identical_book, extra_file_map, replace=False, auto_rename=True)
|
||||
if mi.cover_data and mi.cover_data[1] and not newdb.field_for('cover', identical_book):
|
||||
newdb.set_cover({identical_book: mi.cover_data[1]})
|
||||
|
||||
if automerge_action == 'new record':
|
||||
incoming_fmts = {fmt.upper() for fmt in format_map}
|
||||
|
||||
@ -194,6 +194,18 @@ class AddAction(InterfaceAction):
|
||||
if fmt:
|
||||
db.add_format_with_hooks(id_, fmt, fpath, index_is_id=True,
|
||||
notify=True)
|
||||
if not db.has_cover(id_):
|
||||
from calibre.ebooks.metadata.meta import get_metadata
|
||||
for fmt, fpath in fmt_map.items():
|
||||
if fmt:
|
||||
try:
|
||||
with open(fpath, 'rb') as f:
|
||||
mi = get_metadata(f, stream_type=fmt.lower())
|
||||
if mi.cover_data and mi.cover_data[1]:
|
||||
db.new_api.set_cover({id_: mi.cover_data[1]})
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
current_idx = self.gui.library_view.currentIndex()
|
||||
if current_idx.isValid():
|
||||
self.gui.library_view.model().current_changed(current_idx, current_idx)
|
||||
|
||||
@ -420,11 +420,17 @@ class Adder(QObject):
|
||||
seen_fmts = set()
|
||||
replace = gprefs['automerge'] == 'overwrite'
|
||||
cover_removed = False
|
||||
cdata = None
|
||||
for identical_book_id in identical_book_ids:
|
||||
ib_fmts = {fmt.upper() for fmt in self.db.formats(identical_book_id)}
|
||||
seen_fmts |= ib_fmts
|
||||
self.add_formats(identical_book_id, paths, mi, replace=replace)
|
||||
self.merged_formats_added_to.add(identical_book_id)
|
||||
if cover_path and not self.db.field_for('cover', identical_book_id):
|
||||
if cdata is None:
|
||||
with open(cover_path, 'rb') as f:
|
||||
cdata = f.read()
|
||||
self.db.set_cover({identical_book_id: cdata})
|
||||
if gprefs['automerge'] == 'new record':
|
||||
incoming_fmts = {path.rpartition(os.extsep)[-1].upper() for path in paths}
|
||||
if incoming_fmts.intersection(seen_fmts):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user