r/Calibre • • 3d 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? 🙏🏻

7 Upvotes

28 comments sorted by

4

u/TexasNiteowl 3d ago edited 3d 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.

replace_metadata:
 category=>^Marvel$=>Marvel Cinematic Universe
 category=>^Marvel \(Comics\)$=>Marvel Cinematic Universe
 category=>Thor.*=>Marvel Cinematic Universe
 category=>Iron Man.*=>Marvel Cinematic Universe

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.

1

u/DubiousPeaches 3d ago

Ok, interesting! I thought putting that in the personal.ini would change it before it got to my columns in Calibre? I could very well be wrong though since I obviously can barely configure it correctly 😅 I wanted to keep the metadata from AO3 intact, so I want the full official fandom tags to still be associated with the fic, but just have an additional column that has the shortened name too. But maybe what you suggested will still do that?

2

u/TexasNiteowl 3d ago

Here is a screenshot of what all this gets me. Is this basically what you are wanting? Different fandoms of course.

Where my "main universe" is your "short_fandom"?

1

u/DubiousPeaches 3d ago

Yes, exactly! Ok, I’m going to try all those tonight and see if I can get it to work. Thank you!!

1

u/TexasNiteowl 2d ago

just curious if you had a chance to start trying this. if you have any questions about what I wrote, I will try to answer!

1

u/DubiousPeaches 2d ago

I did and I got it to work!! Thank you so much for your help ♥️

1

u/TexasNiteowl 2d ago

awesome!

2

u/TexasNiteowl 3d ago edited 3d ago

FIRST.

OK. I'm backing up one step.

If you haven't already done it, make sure you create a custom column to hold all of the metadata that FFF downloads.

That custom column, mine is called fffmeta is type "long text, like comments, not shown in tag browser" and is set to "interpret this column as: plain text".

Then, in the Configure FFF UI, go to the custom columns tab and at the bottom there is a Special column section and there is a line for "Saved Metadata Column"...make sure to set that to your fffmeta column.

Doing this saves all the metadata to a column so that in future you already have it without having to contact AO3. But also, makes testing easier as again, you don't have to contact AO3 every time to see how things are working.

2

u/TexasNiteowl 3d ago edited 3d ago

SECOND

In your case then, I would create 2 custom columns.

Call the first one ao3fandoms. Call the second one short_fandoms. Both will be "comma separated text, like tags, shown in the tag browser".

To keep the full fandom tags, in your personal.ini in the ao3 section, have this:

custom_columns_settings:
 fandoms=>#ao3fandoms

That will put the full fandoms in the ao3fandoms custom column so you have the original fandom tags.

Then go back to the first response I wrote with messes with the category metadata.

1

u/TexasNiteowl 3d ago

yes and no. So confusingly, there is both "fandoms" and "category". Initially they are essentially the same. That is...if you look at the fff documentation for the defaults.ini, there is a line about 'include_in_category:fandoms'.

So...hold on...I'll write more in a minute...

1

u/kaitriana137 2d ago

Wait I’ve been trying to do something very similar to this for aaaaggggeess! Are you telling me it’s that simple? 😭

Though would this work for crossover fics as well? 🤔

Currently, my setup is 3 custom columns (2 of which is done manually by using the Reading Plugin. It’s tedious but I need them for my organization):

- Source Fandoms which is the direct unchanged fandom tags from AO3 and populated by FFF.

- Fandom which is the simplified version of the fandom, I.e. Iron Man>Marvel, Thor>Marvel, etc. but sometimes include 2 fandoms as I read crossovers

- and then Main Fandom which is where if it’s a crossover fic I choose the fandom where the setting is placed (I.e. a Marvel character is placed in the DC universe so DC would be in the Main Fandom column)

So would the setup you have here work to put both “simplified” universes, again Marvel and DC for example, in the created Fandom column? I would love not to keep manually inputting the data for 2 columns if I can help it.

Also, side question, if it is possible, can you please explain how do you know what to put in the personal.ini in regards to the names of the fandom in the code? I saw you had examples for Iron Man and Thor, but for the rest that appear, how did you know what to put? There’s a lot of *>\/:’ in the code and I would not know what I was supposed to put in for each one, and considering there’s a lot I would have to do put in the code to get the one fandom (again Marvel for example)? Thats very daunting. And I have no experience in coding at all, like literally consider me dumb as a rock when it comes to that. I just follow tutorials 😅

1

u/TexasNiteowl 2d ago

hmmm...yes and no. I've actually played with having 2 fandoms listed...a first universe and a second universe (in their own columns). The problem comes down to how the author has things tagged in part and in what order. And I'm not sure how to auto-populate 2 values (ie. Marvel, DCU) into just the one column.

For example...let's say I have 3 columns:

  1. ao3fandoms (as in my instructions in this thread, this would be your untouched entries from AO3)
  2. mainfandom (short fandom name of first tagged fandom)
  3. secondfandom (short fandom name of second different fandom)

Looking at a story (Man of Iron, Child of Magic), the fandoms tagged by the author are: Harry Potter - J. K. Rowling, The Avengers (Marvel Movies), Iron Man (Movies)

which I can make into this:

1

u/kaitriana137 2d ago

Ah yeah I see hmm 🤔 well I don’t want to have to make another column in order to get both fandoms unfortunately. If I do set it up though, it will only show one fandom? Would I be able to add another fandom manually by using the reading plugin? It isn’t ideal but I can always try it as it doesn’t hurt to try.

1

u/TexasNiteowl 2d ago

Actually...hmm...I'm thinking about this. I think it can be done. As long as you setup all the replace_metadata in the personal.ini and update it as needed. For example, because of list, I was able to do this automatically.

ao3fandom is direct from AO3, Universe is my shortened ones.

Because in my list I set Iron Man, Marvel, and The Avengers to all be "Marvel Cinematic Universe" that because just 1 shortened entry.

1

u/kaitriana137 2d ago

Wait that’s perfect! The Marvel tag was automatically added and then you just used the reading plugin to add the second tag, Harry Potter?

1

u/TexasNiteowl 2d ago

no, no plugin. all via personal.ini/fff/custom columns.

"Harry Potter - J.K. Rowling" was shorted to "Harry Potter"

"Iron Man" was changed to "Marvel Cinematic Universe"

"The Avengers" was changed to "Marvel Cinematic Universe"

That essentially made the list to be "Harry Potter" + 3 instances of "Marvel Cinematic Universe" which results in just one entry since it is the same.

i honestly don't even know what the reading plugin is.

Ok, let me look back through the instructions above (the FIRST, SECOND, etc.) and then figure out how to explain some of the rest.

1

u/kaitriana137 2d ago

Alright thank you so much for your help! 🙏🏼🙏🏼 And the reading plugin is just a plugin that lets you add books to a list that you can view at anytime (similar to virtual library just slightly different) but you can also set it up so that if you add a book to the list it adds the list name to a column you designate. So using the first example I gave earlier, I would use the plugin to add “Marvel, DC” to Fandom and then just “DC” to Main Fandom.

2

u/TexasNiteowl 1d ago edited 1d ago

ok...I was trying to figure out how to absolutely limit the second column to only 2...which I think I have a regex line that is working.

Now...they may not always be the 2 entries you want unless you are disciplined with the replace_metadata list. (ie. Iron Man > MCU, Wonder Woman > DCU, or whatever.)

So...I'll try to get this written up.

editing to add...it's getting late here so this is going to be tomorrow.

1

u/kaitriana137 1d ago

No worries, take your time! Thank you again for helping! 🙏🏼 And if it makes it easier for you tomorrow, you can dm me, but up to you 🙂

→ More replies

1

u/TexasNiteowl 2d ago

if this is what you want, I can try to write up what's different from the instructions above. You might still have to set your main universe manually as the author might tag something as Marvel first for the character instead of DCU first for setting. But technically as shown in pics above you can set the first tagged fandom into that column automatically.

1

u/TexasNiteowl 2d ago

as for what to put in...it just takes time. I have quite a few entries because instead of having 20 different entries that are all MCU, I change them all to be MCU. If you change all of them to the same thing, then now you only have a single short fandom name.

An author may literally tag: MCU, Iron Man, Thor, Captain America, The Avengers, Black Widow, Hulk, Ant Man, etc. So I just define all of those to be MCU. And every time you think you have your list complete an author will do something weird or odd or even just make a typo and then you have to add something else to your list.

Some of the things are there to tell the code how to match them to. The "^" means start of string. The "$" means end of string. A "\" indicates the next character is a special character. I am happy to share some of what I've done (more than I pictured above).

Or if you link a couple of sample stories I can give you a sample line.

1

u/kaitriana137 2d ago

Oh please would you share it? 🙏🏼 It would be so much easier lol as I have no idea what I’m doing 😅

1

u/minnissant 2d 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 1d ago

Oh, so this works? Im so pleased you were able to do this, it must be so helpful.

1

u/minnissant 2d 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.