Thank you JimmXinu.
I'll give it a try.
I was just wondering if there was a simpler / more recent way to do this
Quote:
Originally Posted by JimmXinu
Here's the code I use to force a cover update after updating a book in FanFicFare:
First, I use db.add_format_with_hooks(book_id, options['fileform'], book['outfile'], index_is_id=True) instead of just add_format(). I believe the difference is input plugins being run.
Second, I have code that takes a cover from the ebook, using the first page if there isn't an actual image:
Code:
from calibre.ebooks.metadata.meta import get_metadata as calibre_get_metadata
existingepub = db.format(book_id,'EPUB',index_is_id=True, as_file=True)
epubmi = calibre_get_metadata(existingepub,'EPUB')
if epubmi.cover_data[1] is not None:
try:
db.set_cover(book_id, epubmi.cover_data[1])
except:
logger.info("Failed to set_cover, skipping")
Third, there is the code to insure that Calibre is notified about all the updates:
Code:
if len(add_list):
self.gui.library_view.model().books_added(len(add_list))
self.gui.library_view.model().refresh_ids(add_ids)
if len(update_list):
self.gui.library_view.model().refresh_ids(update_ids)
current = self.gui.library_view.currentIndex()
self.gui.library_view.model().current_changed(current, self.previous)
self.gui.tags_view.recount()
if self.gui.cover_flow:
self.gui.cover_flow.dataChanged()
Note that a lot of this is from years ago, so it may not be the most up-to-date way.
|