Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 03-23-2025, 03:02 PM   #1456
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
After adding the tweak and restarting, do the following:
  • Add the following custom action:
    Code:
    from calibre import prints
    from calibre.constants import DEBUG
    
    from calibre_plugins.action_chains.actions.single_field import SingleFieldAction, get_possible_cols
    
    class SingleFieldActionModified(SingleFieldAction):
    
        name = 'Modified Single Field Edit'
        support_scopes = True
    
        def run(self, gui, settings, chain):
            db = gui.current_db
    
            col_name = chain.chain_vars.get('_variant_argument')
            if col_name in get_possible_cols(db):
                settings['value_type'] = 'prompt'
                settings['col_name'] = col_name
                SingleFieldAction.run(self, gui, settings, chain)
            else:
                prints(f'ERROR: column name ({col_name}) is not valid')
    
    
        def validate(self, settings):
            return True
    
        def config_widget(self):
            return None
    This action is a modification of the single edit that will let you edit at runtime a column. It reads the column name from a chain variable.
  • Create a chain and add the action just added above (Modified Single Edit)
  • In the Add/Modify Chain dialog, double click the chain > Chain Variations > add the following template
    Code:
    program:
        columns = 'title,authors,tags,#genre';
        for col in columns:
            add_chain_variant('Edit ' & col, col, 'The name of the submenu')
        rof
    Change the columns variable to include the custom columns you want.
Now you should have a submenu with multiple chain variants, for each column you want.
capink is offline   Reply With Quote
Old 03-23-2025, 03:30 PM   #1457
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
Posts: 6,636
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
Quote:
Originally Posted by capink View Post
[*]In the Add/Modify Chain dialog, double click the chain > Chain Variations > add the following template
Problem is, I don't get the entry for "Chain variations" (see attached pictures), although I've added the tweak,
Attached Thumbnails
Click image for larger version

Name:	Tweak.png
Views:	45
Size:	2.7 KB
ID:	214602   Click image for larger version

Name:	Add_Chain.png
Views:	60
Size:	66.3 KB
ID:	214603  
Terisa de morgan is offline   Reply With Quote
Old 03-23-2025, 04:26 PM   #1458
correoparaappzz
Connoisseur
correoparaappzz began at the beginning.
 
Posts: 66
Karma: 10
Join Date: Nov 2023
Device: Kindle Oasis
Quote:
Originally Posted by Terisa de morgan View Post
Problem is, I don't get the entry for "Chain variations" (see attached pictures), although I've added the tweak,
You have to right clic
Attached Thumbnails
Click image for larger version

Name:	Captura de pantalla 2025-03-23 132348.png
Views:	63
Size:	46.9 KB
ID:	214608  
correoparaappzz is offline   Reply With Quote
Old 03-23-2025, 05:08 PM   #1459
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
Posts: 6,636
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
Quote:
Originally Posted by correoparaappzz View Post
You have to right clic
Thank you very much, I usually forget about it
Terisa de morgan is offline   Reply With Quote
Old 03-23-2025, 05:08 PM   #1460
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
Posts: 6,636
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
Quote:
Originally Posted by capink View Post
After adding the tweak and restarting, do the following:

Now you should have a submenu with multiple chain variants, for each column you want.
Thank you, it's working.
Terisa de morgan is offline   Reply With Quote
Old 03-23-2025, 08:29 PM   #1461
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by Terisa de morgan View Post
Thank you, it's working.
My mistake, I said double click instead of right click. Haven't been sleeping enough the past month.
capink is offline   Reply With Quote
Old 03-23-2025, 09:59 PM   #1462
correoparaappzz
Connoisseur
correoparaappzz began at the beginning.
 
Posts: 66
Karma: 10
Join Date: Nov 2023
Device: Kindle Oasis
Help

Hi, I don't know what to do with one of my chains. The end of the chain is supposed to count the ebook's pages using the 'Count Pages' plugin using the Goodreads metadata. Everything is fine. The problem is that sometimes Goodreads doesn't have the page count in its metadata, which leaves me with a blank space in the corresponding column.

I have to enter the value manually or press 'Estimate page/word count' in the 'Count Pages' plugin. I added it to the chain and added the condition that it would run if the column was empty, but it doesn't work.

I don't know what to do.
correoparaappzz is offline   Reply With Quote
Old 03-23-2025, 10:23 PM   #1463
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
I am not a user of the Count Page plugin, so I can't help much. But the common error people do, is that they assume that conditions check every book which is not the case. It only works on the single active book selection. And conditions are meant as a binary on/off switch on the action as the whole.

What you want to do here is, at the end of your chain, limit the selection using "Search Using Templates" action with the following template:
Code:
program:
    book_ids = '';
    for book_id in from_selection('id'):
        if book_field(book_id, '#page_count') == '' then
            book_ids = list_union(book_ids, book_id, ',')
        fi
    rof
Notes:
  • Make sure to change the column name highlighted in red with the appropriate column name.
  • Make sure the "Select books" Checkbox is ticked.
  • Make sure the "Search is a list of book ids" radio button is selected.

After that apply the Count Pages plugin on the newly selected books.

Edit: To solve the solution in an easier way without needing to write templates, I am considering adding a new action called 'Restrict current selection', which will narrow down the selected books using a regular calibre search e.g. #page_count:false. Or maybe amend Selection Modifier to add this feature.

This can already be done using scopes, but "Calibre Actions" does not support scopes and relies instead on the "Selection Modifier"

Last edited by capink; 03-23-2025 at 10:32 PM.
capink is offline   Reply With Quote
Old 03-23-2025, 10:44 PM   #1464
correoparaappzz
Connoisseur
correoparaappzz began at the beginning.
 
Posts: 66
Karma: 10
Join Date: Nov 2023
Device: Kindle Oasis
Quote:
Originally Posted by capink View Post
I am not a user of the Count Page plugin, so I can't help much. But the common error people do, is that they assume that conditions check every book which is not the case. It only works on the single active book selection.
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.
correoparaappzz is offline   Reply With Quote
Old 03-23-2025, 10:55 PM   #1465
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by correoparaappzz View Post
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.

Last edited by capink; 03-23-2025 at 11:09 PM.
capink is offline   Reply With Quote
Old 03-29-2025, 06:48 PM   #1466
Alinara
Member
Alinara began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Nov 2023
Device: none
Thanks and a Question about Metadata download

Thanks for your help last time! I made now some Phyton scripts that help with my condition problem that I had before! I use them together with integrated options like search and replace.

It saved me a lot of manual work

---

I wanted to download specific Metadata from one site. I found a script in the Action Chain Resource Thread. (https://www.mobileread.com/forums/sh...9&postcount=28) But I do not understand how to use it.
If I try to use it in a Chain it tells me "run" is missing.

It would be nice if you have some advice how that script is meant to be used.
Alinara is offline   Reply With Quote
Old 04-03-2025, 04:47 PM   #1467
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,998
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Chain: Add Purchase Information, has single-field edit for #purchasesource (enum) and also other fields.

Other chain sets #purchasesource to specific value then calls the Add Purchase Information. Can skip the redundant SFE with condition?

Last edited by ownedbycats; 04-03-2025 at 05:31 PM.
ownedbycats is online now   Reply With Quote
Old 04-04-2025, 05:53 PM   #1468
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
Chain: Add Purchase Information, has single-field edit for #purchasesource (enum) and also other fields.

Other chain sets #purchasesource to specific value then calls the Add Purchase Information. Can skip the redundant SFE with condition?
One way to do it would be a condition like this on the SFE action(s):
Code:
program:
    if globals(_caller) inlist 'my first chain,my second chain, ....' then
        'skip'
    fi
value type > text
comparison operator > !=
Condition value > skip

You can also use a condition to check the value of the said field, presuming the default value in nil.

Last edited by capink; 04-04-2025 at 07:28 PM.
capink is offline   Reply With Quote
Old 04-04-2025, 05:55 PM   #1469
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by Alinara View Post
Thanks for your help last time! I made now some Phyton scripts that help with my condition problem that I had before! I use them together with integrated options like search and replace.

It saved me a lot of manual work

---

I wanted to download specific Metadata from one site. I found a script in the Action Chain Resource Thread. (https://www.mobileread.com/forums/sh...9&postcount=28) But I do not understand how to use it.
If I try to use it in a Chain it tells me "run" is missing.

It would be nice if you have some advice how that script is meant to be used.
I haven't used this action since writing it. I am currently traveling and don't have my laptop with me, so I cannot test that action. But double check you copied it correctly including the run() function.
capink is offline   Reply With Quote
Old 04-05-2025, 11:20 AM   #1470
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,998
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by capink View Post
One way to do it would be a condition like this on the SFE action(s):
Code:
program:
    if globals(_caller) inlist 'my first chain,my second chain, ....' then
        'skip'
    fi
value type > text
comparison operator > !=
Condition value > skip

You can also use a condition to check the value of the said field, presuming the default value in nil.
Second one worked.

What would I use specifically for the first one? I wasn't sure if it'd be if globals(_caller) inlist 'Cleanup: Kobo, Add Purchase Information' or something else.
ownedbycats is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Editor Plugin] Editor Chains capink Plugins 106 06-17-2025 05:36 PM
Action Chains Resources capink Plugins 77 06-16-2025 12:45 PM
[GUI Plugin] Noosfere_util, a companion plugin to noosfere DB lrpirlet Plugins 2 08-18-2022 03:15 PM
[GUI Plugin] Save Virtual Libraries To Column (GUI) chaley Plugins 14 04-04-2021 05:25 AM


All times are GMT -4. The time now is 05:22 PM.


MobileRead.com is a privately owned, operated and funded community.