Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 07-26-2021, 07:40 AM   #1
McStubb
Connoisseur
McStubb began at the beginning.
 
Posts: 52
Karma: 10
Join Date: May 2014
Device: None
Suggestion: Expose Batch Cover trim

So I am working to clean up a large library. I am using the batch remove cover keyboard shortcut quite a bit. But the Mass Trim Cover option isnt available to set as a shortcut. Any chance this can be exposed/made available?
McStubb is offline   Reply With Quote
Old 07-26-2021, 08:44 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
This is rather more work than is worth it to me. Removing covers already has an action under the remove books menu, so it's straightforward to assign it a shortcut. trimming covers does not.
kovidgoyal is offline   Reply With Quote
Advert
Old 07-26-2021, 11:03 AM   #3
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,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
If you are familiar with the Action Chains plugin, you can achieve what you want:
  • Copy past this custom action into the plugin's module editor
    Code:
    from functools import partial
    
    from PyQt5.Qt import (QApplication, Qt)
    
    from calibre.gui2 import error_dialog
    
    from calibre_plugins.action_chains.common_utils import DoubleProgressDialog
    from calibre_plugins.action_chains.actions.base import ChainAction
    
    class Test(ChainAction):
    
        name = 'Trim Covers'
        support_scopes = True
    
        def trim_covers(self, db, book_ids, pbar):
    
            from calibre.utils.img import (
                image_from_data, image_to_data, remove_borders_from_image
            )
            
            pbar.update_overall(len(book_ids))
            
            for book_id in book_ids:
                cdata = db.new_api.cover(book_id)
                if cdata:
                    img = image_from_data(cdata)
                    nimg = remove_borders_from_image(img)
                    if nimg is not img:
                        cdata = image_to_data(nimg)
                        db.new_api.set_cover({book_id:cdata})
                msg = _('Trimming cover for book_id: {}'.format(book_id))
                pbar.update_progress(1, msg)
    
        def run(self, gui, settings, chain):
            db = gui.current_db
            book_ids = chain.scope().get_book_ids()
    
            callback = partial(self.trim_covers, db, book_ids)
            pd = DoubleProgressDialog(1, callback, gui, window_title=_('Trimming ...'))
    
            gui.tags_view.blockSignals(True)
            QApplication.setOverrideCursor(Qt.ArrowCursor)
            try:
                pd.exec_()
    
                pd.thread = None
    
                if pd.error is not None:
                    return error_dialog(gui, _('Failed'),
                            pd.error[0], det_msg=pd.error[1],
                            show=True)
            finally:
                QApplication.restoreOverrideCursor()
                gui.tags_view.recount()
  • Create a chain containing the action you just added: Trim Covers.
  • Assign a keyboard shortcut your want to the chain (Add/Modify Chains > Keyboard shortcuts)
capink is offline   Reply With Quote
Old 07-29-2021, 10:29 PM   #4
McStubb
Connoisseur
McStubb began at the beginning.
 
Posts: 52
Karma: 10
Join Date: May 2014
Device: None
Thanks, that worked like a charm
McStubb is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
suggestion for kobo cover lo5boy01 Kobo Developer's Corner 0 10-29-2019 11:24 PM
calibre-server, expose all libraries asok Library Management 6 09-11-2015 03:39 AM
Trim Cover Arrowhead Calibre 2 09-11-2012 01:30 PM
Suggestion on batch program. GustavoB Workshop 4 03-23-2012 01:58 PM
set the cover for the book from....batch chrisix Calibre 6 07-08-2010 12:22 PM


All times are GMT -4. The time now is 07:39 AM.


MobileRead.com is a privately owned, operated and funded community.