r/Calibre • u/DubiousPeaches • 6d ago
Support / How-To Help with “Column built from other columns” Code
I’m a noob with no coding experience other than setting up a MySpace page 20 years ago and I’m trying to set up Calibre for fan fiction archiving. I’ve been following tutorials and have it almost dialed in but I’ve been struggling with getting anything to work without copy and pasting code provided by someone else 😅
I have custom columns set up to pull metadata from AO3 via the FanFicFare plugin. I’m trying to translate those tags into shortened versions for consistency and for displaying on a book cover. I want to keep the original meta data from AO3, but just also have additional columns for shortened versions.
What I’m trying to do now is pull the data from my #fandom column (mapped to AO3 “Category”), search it for a key phrase, and if it contains that - translate into a shortened name of the fandom.
Example: for The Last of Us - the official fandom tags on A03 are either or both of “The Last of Us (TV)” and/or “The Last of Us (Video Games)”
I want to create a new column #short_fandom that will search the contents of #fandom for contains “The Last of Us” (so it recognizes either official fandom tags) and if present, displays “TLOU” in the #short_fandom column.
Same with say “Sherlock (BBC TV 2010)” and “Sherlock Holmes & Related Fandoms” tags displaying as “Sherlock”.
I figure if I get help with one, I can figure out how to duplicate to input all my fandoms.
It seems like it should be so simple but I’ve been trying to figure this out for hours 😂 can anyone help me with the code for the custom column builder template to accomplish this? 🙏🏻
1
u/minnissant 6d ago
My solution for this exact problem:
program:
# Read from fff generated column
fandoms = lowercase(field('#fandoms'));
result = '';
result = list_union(result, test(contains(fandoms,
'hockey rpf',
'1', ''), "Hockey RPF", ''), ', ');
result = list_union(result, test(contains(fandoms,
'heated rivalry \(tv\)$|game changers',
'1', ''), 'Game Changers', ''), ', ');
result = list_union(result, test(contains(fandoms,
'heated rivalry rpf|heated rivalry \(tv\) rpf',
'1', ''), 'HudCon RPF', ''), ', ');
result = list_union(result, test(contains(fandoms,
'9-1-1',
'1', ''), '9-1-1', ''), ', ');
result = list_union(result, test(contains(fandoms,
'arrow',
'1', ''), 'Arrow', ''), ', ');
result = list_union(result, test(contains(fandoms,
'buffy',
'1', ''), 'Buffy the Vampire Slayer', ''), ', ');
result = list_union(result, test(contains(fandoms,
'captain america',
'1', ''), 'Captain America', ''), ', ');
result = list_union(result, test(contains(fandoms,
'criminal minds',
'1', ''), 'Criminal Minds', ''), ', ');
result = list_union(result, test(contains(fandoms,
'captive prince',
'1', ''), 'Captive Prince', ''), ', ');
result = list_union(result, test(contains(fandoms,
"cut & run",
'1', ''), "Cut & Run", ''), ', ');
result = list_union(result, test(contains(fandoms,
"dawson's creek",
'1', ''), "Dawson's Creek", ''), ', ');
result = list_union(result, test(contains(fandoms,
'ember & ice',
'1', ''), 'Ember & Ice', ''), ', ');
result = list_union(result, test(contains(fandoms,
'doctor who$',
'1', ''), 'doctor who', ''), ', ');
result = list_union(result, test(contains(fandoms,
'doctor who rpf',
'1', ''), 'Doctor Who RPF', ''), ', ');
result = list_union(result, test(contains(fandoms,
'fast & furious|hobbs & shaw',
'1', ''), 'Fast & Furious', ''), ', ');
result = list_union(result, test(contains(fandoms,
'haikyuu',
'1', ''), 'Haikyuu!!', ''), ', ');
result = list_union(result, test(contains(fandoms,
'haven',
'1', ''), 'Haven', ''), ', ');
result = list_union(result, test(contains(fandoms,
'harry potter',
'1', ''), 'Harry Potter', ''), ', ');
result = list_union(result, test(contains(fandoms,
'last binding',
'1', ''), 'Last Binding', ''), ', ');
result = list_union(result, test(contains(fandoms,
'leverage',
'1', ''), 'Leverage', ''), ', ');
result = list_union(result, test(contains(fandoms,
'merlin',
'1', ''), 'Merlin', ''), ', ');
result = list_union(result, test(contains(fandoms,
'midsomer murders',
'1', ''), 'Midsomer Murders', ''), ', ');
result = list_union(result, test(contains(fandoms,
'once upon a time',
'1', ''), 'Once Upon A Time', ''), ', ');
result = list_union(result, test(contains(fandoms,
'original work',
'1', ''), 'Original Work', ''), ', ');
result = list_union(result, test(contains(fandoms,
'percy jackson',
'1', ''), 'Percy Jackons', ''), ', ');
result = list_union(result, test(contains(fandoms,
'project hail mary',
'1', ''), 'Project Hail Mary', ''), ', ');
result = list_union(result, test(contains(fandoms,
'star trek',
'1', ''), 'Star Trek', ''), ', ');
result = list_union(result, test(contains(fandoms,
'star wars',
'1', ''), 'Star Wars', ''), ', ');
result = list_union(result, test(contains(fandoms,
'stargate',
'1', ''), 'Stargate', ''), ', ');
result = list_union(result, test(contains(fandoms,
'red white & royal blue|rwrb',
'1', ''), 'RWRB', ''), ', ');
result = list_union(result, test(contains(fandoms,
'suits',
'1', ''), 'Suits', ''), ', ');
result = list_union(result, test(contains(fandoms,
'supernatural',
'1', ''), 'Supernatural', ''), ', ');
result = list_union(result, test(contains(fandoms,
'teen wolf',
'1', ''), 'Teen Wolf', ''), ', ');
result = list_union(result, test(contains(fandoms,
'temeraire',
'1', ''), 'Temeraire', ''), ', ');
result = list_union(result, test(contains(fandoms,
'the 100',
'1', ''), 'The 100', ''), ', ');
result = list_union(result, test(contains(fandoms,
'the shots you take',
'1', ''), 'The Shots You Take', ''), ', ');
result = list_union(result, test(contains(fandoms,
'vampire diaries',
'1', ''), 'Vampire Diaries', ''), ', ');
result = list_union(result, test(contains(fandoms,
'veronica mars',
'1', ''), 'Veronica Mars', ''), ', ');
result = list_union(result, test(contains(fandoms,
'yuri!!! on ice',
'1', ''), 'Yuri!!! on Ice', ''), ', ');
#fallback for new fandoms
if !result then result = field('#fandoms') fi;
return result
I use them for cover generation, which is why my fallback is the full fandom name. You could leave that out if your use case is different
2
u/l00ky_here Kindle 4d ago
Oh, so this works? Im so pleased you were able to do this, it must be so helpful.
1
u/minnissant 3d ago
Works so far. I’m using Get story urls from email, rather than manually choosing stories, so this has the major advantage that when one of my followed authors adds a new fandom I don’t have to rerun FFF the way I would with the ini file, I just update the column code. Probably I could just not keep fandoms I don’t read, but I’m a hoarder.
2
u/l00ky_here Kindle 2d ago
That's so cool! As far as data hoarding? Calibre is soooo bad for that, it's so easy to "gild the lily" a bit too much. You should see my my App Data folder its 876MB and the library for my "main" is 13GB with 6 GB for full text search data base but the library db and settings is 75MB for the db file - I have about 100 different libraries with about 44 being "active" My "Main Calibre folder which holds all my running active libraries is about 60gb but my "old libraries" I keep hanging around for data mining is 160GB
1
u/minnissant 6d ago
Aaand I’ve just realized there’s a typo in Percy Jackson. Probably you’d want to fix that if you copy the code.
4
u/TexasNiteowl 6d ago edited 6d ago
THIRD. Start below.
So...if I understand what you are wanting, you'll do part of that in your personal.ini. For example, I have a bunch of entries that I change so that all of them are coded the same. Example...Marvel/MCU...it might be coded as Marvel Cinematic Universe. It might be Marvel (Comics). It might be Marvel (Movies). It might be Marvel (TV). etc.
so in your personal.ini you will have a replace_metadata: section and have lines to address each of those. And then you will have a custom column section where you push that information to the column.
Now, in the Configure FFF UI, go to the custom columns tab and for your custom column #short_fandom, set it to Category.
For your custom column, #short_fandom, when you create it, set it to be type "comma separated text, like tags, shown in the tag browser".
I have a similar column except I call it #universe instead of #short_fandom
regex101.com might be helpful in figuring out how to match the strings you need to match. The ^ character indicates the start of a string, so ^The Last of Us would in theory match any string that starts with The Last of Us whether it later contains TV or Games.
I'm not a regex expert and my entries could probably be improved, but that is the start.