View Single Post
Old 03-07-2021, 12:48 PM   #369
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,139
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
You can try the following code (copy/past into the module editor):

Code:
from calibre.ebooks.metadata.meta import metadata_from_formats
from calibre_plugins.action_chains.actions.base import ChainAction

class CoverFromBook(ChainAction):

    name = 'Cover from book'
    support_scopes = True

    def run(self, gui, settings, chain):
        db = gui.current_db.new_api
        book_ids = chain.scope().get_book_ids()
        for book_id in book_ids:
            fmts = db.formats(book_id, verify_formats=False)
            paths = list(filter(None, [db.format_abspath(book_id, fmt) for fmt in fmts]))
            mi = metadata_from_formats(paths)
            if mi.cover_data:
                cdata = mi.cover_data[-1]
            if cdata is not None:
                db.set_cover({book_id: cdata})

Last edited by capink; 07-16-2021 at 04:41 AM.
capink is offline   Reply With Quote