View Single Post
Old 08-05-2025, 05:01 AM   #79
un_pogaz
Chalut o/
un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.
 
un_pogaz's Avatar
 
Posts: 726
Karma: 741392
Join Date: Dec 2017
Device: Kobo
Re-calc Book Size

A little module to re-calc the size column of a book.
Useful if you've had edited the book files by a third-party program.

EDIT: If your have Quality Check 1.14.3 and above installed, you can use directly the same action in "Imported From Other Plugin > Quality Check > Run Quality Check fix" and select "Check and repair book size"

Code:
import os
from collections import defaultdict

from calibre_plugins.action_chains.actions.base import ChainAction

class ReCalcSize(ChainAction):
    
    name = 'Re-calc Size'
    
    def run(self, gui, settings, chain):
        db = gui.current_db.new_api
        ids = chain.scope().get_book_ids()
        updated = defaultdict(set)
        
        for book_id in ids:
            for fmt in db.formats(book_id):
                path = db.format_abspath(book_id, fmt)
                if path and os.path.exists(path):
                    size_db = db.format_db_size(book_id, fmt)
                    size_new = os.path.getsize(path)
                    if size_db != size_new:
                        db.format_metadata(book_id, fmt, update_db=True)
                        updated[book_id].add(fmt)
        
        db.update_last_modified(updated.keys())
        
        msg = f'Size updated for {len(updated)} books'
        gui.status_bar.showMessage(msg)
Attached Files
File Type: py Re-calc Size.py (966 Bytes, 42 views)

Last edited by un_pogaz; 05-07-2026 at 05:07 AM.
un_pogaz is offline   Reply With Quote