04-01-2022, 01:34 PM | #1 |
Junior Member
Posts: 6
Karma: 10
Join Date: Apr 2022
Device: none
|
Using IF THEN ELSE in a Calibre Save Template
Hi. I'm hoping for some help please in configuring my Calibre Save Template, and using IF THEN ELSE logic.
I have a custom 'Genre' hierarchical column to organise everything in my library. I got this idea from here many years ago I think, so I assume people will know the kind of thing. Examples of the structure are e.g. fiction fiction.crime fiction.thriller fiction.thriller.historical travel travel.usa travel.usa.ca etc. For a long time I have happily used a nice template, also taken from this forum (thanks!), which breaks down the genre into folders and subfolders based on the "." separator. This is the argument: "{#genre:'re_group($,"([^.]+)\.","[[$]]/")'}/{authors}/{series}/{title} - {authors}" So e.g. John Grisham's Camino Winds, with Genre 'Fiction.Thriller' is sorted to 'Fiction/Thriller/John Grisham/Camino Winds - John Grisham'. [There is also an optional "Series" subfolder level, if the series field is populated.] However, I don't pretend to understand this syntax properly. It just works and I'm very grateful. What I have realised is that for all Fiction books I want to have the {authors} level subfolder, but for all other types of books I want a sort which does not use that subfolder. With Fiction, I tend to know what author I am looking for, but with other types that's not usually the case. So, in simple terms, what I think I am after is something like: IF genre is fiction.* THEN {#genre:'re_group($,"([^.]+)\.","[[$]]/")'}/{authors}/{series}/{title} - {authors} ELSE {#genre:'re_group($,"([^.]+)\.","[[$]]/")'}/{series}/{title} - {authors} The '*' above is meant to be the usual wildcard expression, as there may be no additional genre sub-categories or one sub-category or two or more. Can anybody help put that into Calibre-speak please? Many thanks |
04-02-2022, 12:33 PM | #2 |
Grand Sorcerer
Posts: 11,757
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
It isn't quite clear what you want but I think this is it. This template requires the latest version of calibre (5.40).
Code:
program: # Isolate the first genre. If there is never more than one then use # g = re($#genre, '\.', '/'); g = re(sublist($#genre, 0, 1, ','), '\.', '/'); # Test if the genre starts with 'fiction'. if "^fiction" in g then g & '/' & $authors & '/' & test($series, $series & '/', '') & $title & ' - ' & $authors else g & '/' & test($series, $series & '/', '') & $title & ' - ' & $authors fi Code:
if "^fiction/" in g then Last edited by chaley; 04-02-2022 at 04:05 PM. Reason: small change to program comments |
Advert | |
|
04-02-2022, 04:03 PM | #3 |
Junior Member
Posts: 6
Karma: 10
Join Date: Apr 2022
Device: none
|
Absolutely brilliant, Works like a charm. Many, many thanks.
Last edited by sylvandale; 04-02-2022 at 04:03 PM. Reason: spelling error |
Tags |
genre hierarchy, if then else, save template |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
save as template | ajean4 | Library Management | 12 | 04-15-2021 04:32 PM |
Book upload, Calibre Save Template sometimes parsed, sometimes not | Irian | Calibre | 4 | 06-17-2020 12:22 PM |
save to disk template help | bilaly | Library Management | 2 | 10-19-2018 07:19 PM |
Save Template Help | Maverynthia | Library Management | 10 | 05-19-2014 12:37 PM |
A little help with a save template...? | Belfaborac | Library Management | 2 | 02-04-2011 09:47 PM |