Look into templates . Calibre uses them for various things like save to disc and they can be customised.
That may help.
It's in the manual.
The calibre template language. The calibre template language is used in various places. It is used to control the folder structure and file name when saving files from the calibre library to the disk or e-book reader. It is also used to define “virtual” columns that contain data from other columns and so on.
https://manual.calibre-ebook.com › t...
The calibre template language — calibre 4.12.0 documentation - calibre User Manual