View Single Post
Old 12-30-2020, 11:30 AM   #22
chris33
Enthusiast
chris33 began at the beginning.
 
Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
Question

Hi,
I tried to adapt but unfortunately get_metadata only returns the following fields correctly:
Title, Title sort, Author(s), Publisher, Tags , Series, Languages, Timestamp, Published
but no cover_data

Here is my code:
This overwrites the ebook file and works fine
Code:
self.gui.current_db.new_api.add_format(searchId, fmt, path, replace=True, run_hooks=True)
Then if I go to the ebook metadata GUI and press button "Set the cover for the book from the selected format" I can see the first pages of the new imported book.
But the cover is not updated from this list (default first page)

Code:
mi = self.gui.current_db.new_api.format_metadata(searchId, fmt, allow_cache=True, update_db=True)
OR
mi = self.gui.current_db.new_api.get_metadata(searchId, get_cover=True, get_user_categories=False, cover_as_data=True)
Printing the mi contents doesn't show any cover_data: only Title, Title sort, Author(s), Publisher, Tags , Series, Languages, Timestamp, Published

Code:
self.gui.current_db.new_api.set_cover({searchId, mi.cover_data[1]})
Fails with:

Quote:
File "calibre_plugins.reimport.main", line 159, in process
self.gui.current_db.new_api.set_cover({searchId, mi.cover_data[1]})
File "calibre/db/cache.py", line 72, in call_func_with_lock
File "calibre/db/cache.py", line 1301, in set_cover
File "polyglot/builtins.py", line 92, in iteritems
AttributeError: 'set' object has no attribute 'items'

I think that the cover needs to be generated before being saved in a temporary file so I can send the buffer in the metadata cover field.
Unfortunately I've found no way to generate the cover at least page 1.

How can I force cover generation from a given book id and format ?
Thank you

chris33 is offline   Reply With Quote