View Single Post
Old 01-03-2011, 05:24 PM   #110
stevehaley
Junior Member
stevehaley began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Nov 2010
Device: Kindle
Many thanks to all who have lead the way on this - I thought I would add my two-pennyworth and findings.

My problem was the normal kindle/series/collection title format problem but I wasnt happy that any one derived format fixed the problem as I could see having collections with one series where just the series number would be ok and others with more than one where I would want to show the series name or a shortened version of this as well.

To implement this flexible solution I created 3 custom columns:-
1) A format picker allowing me to decide which style I want for the particular book. I ended up with
a) Full Series name and series no + title
b) Alt series name (see 2) + number + title
c) Shortened series name as per earlier examples + no + title
d) Series No only + title
e) title only
column lookup name = kindle_title_fmt
column type = Text with fixed list of values
values = Series and Num,Alt and Num,Short and Num,Num only,No Series info

2) A column for an alternative series name if the shortened or full didnt suit
column lookup name = alt_series_name
column type = text

3) An output column showing the final book name as it will appear in the kindle and it is this one that contains all the code.
column lookup name = kindle_title
column type = column built from other columns
column code:-

Code:
program:
stripped = re(field('series'), '^(A|The|An)\s+', '');
shortened = shorten(stripped, 4, '-' ,4);
initials = re(stripped, '[^\w]*(\w?)[^\s]+(\s|$)', '\1');
s_index = template('{series_index:0>2.0f}');
abrv=strcat(
            switch( stripped,
                    '.\s', initials,
                    '.', shortened,
                    field('series')),
            test(s_index, strcat(' ', s_index, ': '), ''),
            field('title'));

str_title1 = template('{series}{series_index:0>2.0f| |: }{title}');
str_title2 = template('{#alt_series_name}{series_index:0>2.0f| |: }{title}');
str_title3 = abrv;
str_title4 = template('{series_index:0>2.0f| |: }{title}');
str_title5 = template('{title}');
str_default = str_title5;
str_input = lowercase(field('#kindle_title_fmt'));

switch(str_input,
           'series and num',str_title1,
           'alt and num',str_title2,
           'short and num',str_title3,
           'num only',str_title4,
           'no series info',str_title5,
           str_default);
Last step is simply to create a new plugboard for the kindle 2 which points title at {#kindle_title}

Personally I would also recomend changing the filename fmt in the kindle 2 plugin to include the series to make it easier if you are using the kindle collection manager

You can change the default simply by re-pointing str_default at one of the other title fmts


Learning notes:-
1) It wasnt immediately obvious to me despite being reasonably documented that you reference custom columns by sticking a '#' on the front of the name. Probably because none of the code examples showed it and I hate reading words as opposed to example code.
2) the switch command is incorrectly documented (missing the switch field) - I have raised a bug for this.
3) Was easiest to just put any old text into the 3rd column when creating it then use the f2 edit later to put the actual code in.

People should be able to easily modify the above to produce their own flexible solutions and it also neatly shows how to use custom columns - hope this helps someone
rgds
Stephen

Note this is my first attempt at the calibre mods/programming and I am sure someone will come up with a better cleaner solution. The code could certainly be better.
Serious props to those that created and maintain calibre
stevehaley is offline   Reply With Quote