Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 06-16-2020, 02:20 PM   #1
Irian
Enthusiast
Irian has a complete set of Star Wars action figures.Irian has a complete set of Star Wars action figures.Irian has a complete set of Star Wars action figures.Irian has a complete set of Star Wars action figures.Irian has a complete set of Star Wars action figures.
 
Posts: 47
Karma: 450
Join Date: Mar 2011
Device: PRS-600, PRS-650, Tolino Vision 3 HD, Kobo Libra H20
Book upload, Calibre Save Template sometimes parsed, sometimes not

Hello,

I've got a column defined (with some helper columns) and it displays nicely and correctly in the book detail view for all my books. I called that column "filenamekobo", because it's the filename I want to use on my kobo - surprise.

I now set {#filenamekobo} as my save template in my device configuration.

For many ebooks this works perfectly, books get the right name and path. But for some, it simply totally stops interpreting this column and the name it sends it to the device is #filenamekobo.epub (while still showing the correct value in the book detail view). This only happens for some ebooks and I haven't yet found out what the problem there is. One detail: It always works for the same books and not for others, but it doesn't change from time to time. I have not yet determined a difference between those where it works and where not - no special characters in title or series, for example.

The whole thing starts with the column "serieswithoutthe":

Code:
{series:re(The (.+),\g<1>)}
The other columns I use are the "seriesfolderkobo"...

Code:
{#serieswithoutthe[0]}-Series/{#serieswithoutthe}/{series_index:0>2s} -
and the final "filenamekobo":

Code:
books/{series:test( {#seriesfolderkobo}, other/)}{title}
Anyone has an idea why I get this strange result with some books? Any log where I can see why sometimes #filenamekobo is correctly used and sometimes used as a string itself?

Last edited by Irian; 06-16-2020 at 03:20 PM.
Irian is offline   Reply With Quote
Old 06-17-2020, 05:00 AM   #2
Irian
Enthusiast
Irian has a complete set of Star Wars action figures.Irian has a complete set of Star Wars action figures.Irian has a complete set of Star Wars action figures.Irian has a complete set of Star Wars action figures.Irian has a complete set of Star Wars action figures.
 
Posts: 47
Karma: 450
Join Date: Mar 2011
Device: PRS-600, PRS-650, Tolino Vision 3 HD, Kobo Libra H20
Ok, I probably found the reason: The series was pretty old (I added the first books to my calibre probably more than 10 years ago).

When I renamed the series in all books of it, it worked. Then I renamed it back (to the one that produced the error) and suddenly it also works.

My guess is that something has changed in the way Calibre handles/stores series data in the last years and older series have some property or whatever that confuses the save template.

Additionally, just in case someone stumbles upon the templates, I was (rightly so) told that they are pretty messed up and the result is pretty unpredictable, so I switched to template program mode and did this, instead:

Code:
program:

stripped = re(field('series'), '^(A|The|An|Der|Die|Das)\s+', '');
initial = substr( stripped, 0, 1 );
index = template('{series_index:0>2s}');

foldernameforseries = strcat(initial, '-Series/', field('series'), '/', index, ' - ');
defaultfoldername = 'other/';

finalfolder = test(field('series'), foldernameforseries, defaultfoldername);

strcat('books/', finalfolder, field('title'));
Personally, I like general program mode much better than the single function mode, since it's much clearer to me and requires a lot less brackets ;-)

Last edited by Irian; 06-17-2020 at 06:46 AM.
Irian is offline   Reply With Quote
Advert
Old 06-17-2020, 08:37 AM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
FWIW: the line
Code:
index = template('{series_index:0>2s}');
can be replaced with
Code:
idx = field('series_index');
index = contains(idx, '\.', format_number(idx, '05.2f'), format_number(idx, '02d'));
which has much better performance and deals with floating point series indices.

If you want all series indices to be the same length, in the example's case 5 (nn.nn), then you could use
Code:
format_number(field('series_index'), '05.2f')
chaley is offline   Reply With Quote
Old 06-17-2020, 10:33 AM   #4
Irian
Enthusiast
Irian has a complete set of Star Wars action figures.Irian has a complete set of Star Wars action figures.Irian has a complete set of Star Wars action figures.Irian has a complete set of Star Wars action figures.Irian has a complete set of Star Wars action figures.
 
Posts: 47
Karma: 450
Join Date: Mar 2011
Device: PRS-600, PRS-650, Tolino Vision 3 HD, Kobo Libra H20
Thanks, I appreciate that. While the documentation for the template language is quite ok, do you know of any large collection of examples, because those tend to help a bit?
Irian is offline   Reply With Quote
Old 06-17-2020, 12:22 PM   #5
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
The thread Plugboard, template, and custom composite column recipes has lots of examples.

The thread is a long slog, 59 pages, with much discussion about what templates should do. A lot of the early history discussion isn't correct anymore. If you want to read some recent discussion start at page 50 or so.
chaley is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple regexes in "save book to disk" template? Phssthpok Library Management 1 07-12-2018 04:20 AM
Save Template Help Maverynthia Library Management 10 05-19-2014 12:37 PM
Two XMLs cannot be parsed by Calibre surf Recipes 13 02-10-2013 10:53 AM
A little help with a save template...? Belfaborac Library Management 2 02-04-2011 09:47 PM
How should file names be parsed and prepared for calibre import? Use cases requested GlennMaples Calibre 0 01-09-2011 12:41 AM


All times are GMT -4. The time now is 02:12 PM.


MobileRead.com is a privately owned, operated and funded community.