mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
calibredb add: Fix --cover option not working with non-empty books
This commit is contained in:
parent
0b511fd5b3
commit
f0e3b74151
@ -15,7 +15,7 @@ from calibre.db.adding import (
|
||||
run_import_plugins, run_import_plugins_before_metadata
|
||||
)
|
||||
from calibre.ebooks.metadata import MetaInformation, string_to_authors
|
||||
from calibre.ebooks.metadata.book.serialize import read_cover
|
||||
from calibre.ebooks.metadata.book.serialize import read_cover, serialize_cover
|
||||
from calibre.ebooks.metadata.meta import get_metadata, metadata_from_formats
|
||||
from calibre.ptempfile import TemporaryDirectory
|
||||
from calibre.srv.changes import books_added
|
||||
@ -160,7 +160,7 @@ def do_add(
|
||||
continue
|
||||
ids, dups, book_title = dbctx.run(
|
||||
'add', 'book', dbctx.path(book), os.path.basename(book), fmt, add_duplicates,
|
||||
otitle, oauthors, oisbn, otags, oseries, oseries_index, read_cover(ocover) if ocover else None,
|
||||
otitle, oauthors, oisbn, otags, oseries, oseries_index, serialize_cover(ocover) if ocover else None,
|
||||
oidentifiers, olanguages
|
||||
)
|
||||
added_ids |= set(ids)
|
||||
|
@ -24,14 +24,18 @@ def ensure_unicode(obj, enc=preferred_encoding):
|
||||
return obj
|
||||
|
||||
|
||||
def serialize_cover(path):
|
||||
with lopen(path, 'rb') as f:
|
||||
cd = f.read()
|
||||
return what(None, cd), cd
|
||||
|
||||
|
||||
def read_cover(mi):
|
||||
if mi.cover_data and mi.cover_data[1]:
|
||||
return mi
|
||||
if mi.cover:
|
||||
try:
|
||||
with lopen(mi.cover, 'rb') as f:
|
||||
cd = f.read()
|
||||
mi.cover_data = what(None, cd), cd
|
||||
mi.cover_data = serialize_cover(mi.cover)
|
||||
except EnvironmentError:
|
||||
pass
|
||||
return mi
|
||||
|
Loading…
x
Reference in New Issue
Block a user