View Single Post
Old 08-05-2023, 06:44 PM   #74
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: 11,110
Karma: 77213681
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Another Action Chains post-processing to fix a FanFicFare limitation:

If you use a Ratings column, there's a issue where FanFicFare will concatenate all the ratings on an anthology, producing something like Mature, General Audiences, Mature, Not Rated. Here's my method for fixing this.

1. Edit defaults.ini to standardize your ratings.

Code:
[defaults]

replace_metadata: 
## Ratings
 rating=>^(K|K\+)$=>General Audiences
 rating=>^Teen And Up Audiences$=>Teen and Up Audiences
 rating=>^T$=>Teen and Up Audiences
 rating=>^Mature$=>Mature Audiences
 rating=>^M$=>Mature Audiences
2. In Calibre, go to Preferences > Advanced > Template Functions > Stored Templates tab. Type first_in_list to the template name and paste in this code:

Code:
python:
def evaluate(book, context):
	args = context.arguments
	if args is None or len(args) != 3:
		raise ValueError('first_in_list requires 3 arguments')
	sep = args[1]
	lst = tuple(l.strip() for l in args[0].split(',') if l.strip())
	test_lst = tuple(l.strip() for l in args[2].split(',') if l.strip())
	if not test_lst:
		return ''
	for v in test_lst:
		if v in lst:
			return v
	return ''
Then press the 'Create' button and apply results.

3. Create an Action Chain with a Single-Field Edit affecting your ratings column. Use this template:

Code:
program: 
	first_in_list($#fanficrating, ',', 'Explicit, Mature Audiences, Teen and Up Audiences, General Audiences, Not Rated')
This template will take the aforementioned Mature, General Audiences, Mature, Not Rated and then extract 'Mature' because it's firstmost available item in the provided list. If you'd rather have it in a different order, just change the order of the items in the template.

Thanks to chaley for the python code.

Last edited by ownedbycats; 08-05-2023 at 06:48 PM.
ownedbycats is offline   Reply With Quote