View Single Post
Old 08-05-2025, 04: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: 446
Karma: 672378
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.

Code:
import os

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()
        rslt = {}
        
        for book_id in ids:
            sizes = [0]
            for fmt in db.fields['formats'].for_book(book_id):
                path = db.format_abspath(book_id, fmt)
                sizes.append(os.path.getsize(path))
            max_size = max(sizes)
            if max_size != db.fields['size'].for_book(book_id):
                rslt[book_id] = max_size
        
        db.fields['size'].table.update_sizes(rslt)
        db.update_last_modified(rslt.keys())
Attached Files
File Type: py Re-calc Size.py (751 Bytes, 13 views)

Last edited by un_pogaz; 08-06-2025 at 04:29 AM.
un_pogaz is offline   Reply With Quote