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())