Quote:
Originally Posted by correoparaappzz
My problem isn't that the column is blank. My problem is that when the Chain run 'Count Pages' (Goodreads) and the column is blank, 'Estimate Page/Word Count' is supposed to be activated. This is the condition I set:
Code:
program:
if 'goodreads:' inlist $identifiers && $#book_pages == ''
then 'yes'
else 'x'
fi
The conclusion I came to is that since 'Count Pages' runs these options as Jobs, the chain skips them for the next part of the chain, even when it hasn't finished extracting the metadata from Goodreads yet.   
|
The problem is not the jobs part, because "Calibre Actions" has an option to wait out for jobs to finish before proceeding to the next action. But as far as I remember, Count Pages pops up proceed question dialog after the jobs are finished, and before applying the values to columns that thwarts this whole option. I made it clear before that I don't have the interest nor the ability to work around problems pertaining to individual plugins.
I have my own primitive "Count Pages" chain, that uses a python action to count pages based on the number of characters in a book. Here is the python action if you are interested:
Code:
import os
import traceback
from calibre.ebooks.oeb.polish.container import get_container
from calibre_plugins.editor_chains.etree import get_text, etree
chars_per_page = 2100
col = '#pages'
book_format = 'epub'
def create_container(book_path):
if not book_path:
raise FileNotFoundError
if not os.access(book_path, os.W_OK):
raise PermissionError
container = get_container(book_path)
return container
def run(gui, settings, chain):
db = gui.current_db
book_ids = chain.scope().get_book_ids()
book_id_page_map = {}
for book_id in book_ids:
book_title = db.title(book_id, index_is_id=True)
print(f'Processing book: {book_title}')
try:
fmts_string = db.formats(book_id, index_is_id=True)
if fmts_string:
available_fmts = [ fmt.strip() for fmt in fmts_string.split(',') ]
if book_format.upper() in available_fmts and ( book_format.upper() in ['EPUB', 'AZW3'] ):
book_path = db.format_abspath(book_id, book_format, index_is_id=True)
container = create_container(book_path)
spine_names = [name for name, is_linear in container.spine_names]
ch_count = 0
for name in spine_names:
root = container.parsed(name)
#text = get_text(root)
text = etree.tostring(root, encoding='unicode', method='text')
ch_count += len(text)
book_id_page_map[book_id] = ch_count / chars_per_page
print(' Done.')
else:
print(f' Format ({book_format}) not found for book.')
except:
print(f'FAILURE: {book_title} ({book_id})')
traceback.print_exc()
db.new_api.set_field(col, book_id_page_map)
Change the variables
highlighted in red to suit your need.