View Single Post
Old 12-21-2011, 02:56 AM   #1
Ruskie_it
Fanatic
Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.
 
Posts: 538
Karma: 1000000
Join Date: Dec 2011
Location: Rome, Italy
Device: Kindle PW5, Kindle PW4, Kindle 4 NT
Making references to other fields in template functions

Hello everybody, this is my first attempt at dealing with python and with calibre programming / customization so apologies if the terminology is not correct.

I'm messing with the templates calibre uses while exporting books to devices. Currently my template is the following:

{series}/{author_sort}/{series_index:0>2s|| - }{title} - {authors}

Correct me if I am wrong, with this template if the book isn't part of a series ({series} is null) calibre creates a directory named after the book author, and in that folder it puts the book. If the book _is_ part of a series calibre creates a folder with the name of the series, a subfolder named after the author and in there it puts the book. Correct?

Now, what I would like to achieve is: if the book has NOT a series, create a top folder named after the author and place the book there. If it HAS a series, create a folder with that name, but do _NOT_ create a subfolder with the autor name!

Given that if the {series} field is empty calibre automatically ignores it, I thought I could do something like:

{series}/{author_sort:MAGIC_GOES_HERE}....

Where the magic should be: if field {series} is empty, put $ - the value of author_sort -, if {series} is not empty do not put anything.

But how can I get this? In my understanding if I do something like:

{author_sort:'ifempty(val,str)'} the functions ifempty refers to the value of author_sort, while I'd like to check {series}. Can I refer to the series field value in "val"? Is there a way to achieve that?

Thank you!!!
Rus

Last edited by Ruskie_it; 12-21-2011 at 03:04 AM.
Ruskie_it is offline   Reply With Quote