Quote:
Originally Posted by eschwartz
Ah, yes.
The brackets are reserved in template mode. That's why I like general program mode. Well, that and you can limit yourself to only using one custom column.
Use the general program mode version found here: http://manual.calibre-ebook.com/temp...l-program-mode
Simply fix the "stripped" variable.
PHP Code:
program:
# compute the equivalent of the composite fields and store them in local variables
stripped = re(field('series'), '^(A|The|An)\s+', '');
shortened = shorten(stripped, 4, '-' ,4);
initials = re(stripped, '[\s]?([^\s])[^\s]+(\s|$)', '\1');
# Format the series index. Ends up as empty if there is no series index.
# Note that leading and trailing spaces will be removed by the formatter,
# so we cannot add them here. We will do that in the strcat below.
# Also note that because we are in 'program' mode, we can freely use
# curly brackets in strings, something we cannot do in template mode.
s_index = template('{series_index:0>2.0f}');
# print(stripped, shortened, initials, s_index);
# Now concatenate all the bits together. The switch picks between
# initials and shortened, depending on whether there is a space
# in stripped. We then add the brackets around s_index if it is
# not empty. Finally, add the title. As this is the last function in
# the program, its value will be returned.
strcat(
switch(
stripped,
'.\s',
initials,
'.',
shortened,
field('series')
),
test(
s_index,
strcat(' [', s_index, '] '),
''
),
field('title')
);
|
This worked like a charm, I apprehension I felt when I initially saw this was quite daunting, I did however manage it without a problem. I have absolutely no programming skills whatsoever being more technically inclined.
Also the regex was exactly what I was looking for which just proves I was correct in asking in the first place. I originally thought it was an un-modifiable field other then manually entering in something or downloading the data.
I am very grateful for all your help, a couple of days ago my laptop died and then by backup was corrupted, so I lost everything I had with the exception to what I had stored in the cloud and felt that this was the best time to recreate stuff that I have been wanting to solve for a little while.
So new Laptop and backup drive and calibre is at the point to where I can just sit back and enjoy it.
I do have one small thing that is eluding if you wouldn't mind once again helping me with.
In Metadata Plugboards I have template set up for:
Epub and Any Device
Source template: {title} - {series}{series_index:0>3s| [|]
Destination Field: title
When dealing with series it works perfectly, but when dealing with a book that is not part of a series I have a dash leftover
Example: Ken Follets Book: Edge of Eternity
becomes:
Edge of Eternity - The Century Trilogy [03]
Cottam, F. G. Book: The Lazarus Prophecy
becomes:
The Lazarus Prophecy -
How can I get it to drop the "-" at the end of the title on a book with no series? Yet keep it for series?
Thank you very much eschwartz!