View Single Post
Old 08-30-2021, 04:59 AM   #10
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,090
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
Generate cover action

Note: This action is now available as part of the builtin Single Field Edit Action.

Code:
from calibre.ebooks.covers import generate_cover
from calibre.gui2.covers import CoverSettingsWidget
from calibre_plugins.action_chains.actions.base import ChainAction

class ConfigWidget(CoverSettingsWidget):
    def __init__(self, plugin_action):
        CoverSettingsWidget.__init__(self)
        self.plugin_action = plugin_action
        self.gui = plugin_action.gui
        self.db = self.gui.current_db

    def load_settings(self, settings):
        self.apply_prefs(settings)

    def save_settings(self):
        return self.current_prefs

class GenerateCover(ChainAction):

    name = 'Generate Cover'
    support_scopes = True

    def run(self, gui, settings, chain):
        db = gui.current_db
        book_ids = chain.scope().get_book_ids()

        for book_id in book_ids:
            mi = db.get_metadata(book_id, index_is_id=True)
            cdata = generate_cover(mi, settings)
            db.new_api.set_cover({book_id:cdata})

    def config_widget(self):
        return ConfigWidget

Last edited by capink; 09-24-2021 at 04:17 AM.
capink is offline   Reply With Quote