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)