Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 02-15-2023, 08:01 AM   #1
JJanssen
Member
JJanssen began at the beginning.
 
Posts: 16
Karma: 24
Join Date: Jun 2009
Device: Kindle Paperwhite 1
Question Advanced series_index formatting sanity check

I've been away from my Calibre for a While for Reasons that are not relevant here, but anyway, I'm starting to use it again.

I have mine set to email to Kindle Docs and I'm using a variant of the {series}{series_index:| - | - }{title} because... I think because I was masochistic nearly a decade ago frankly, but anyway, what it *does* is, for any given series, I add leading and trailing zeroes such that within the series the numbering is consistent (and sorts correctly on a naive sort), but I don't clutter up a rando trilogy with 001-003 if 1-3 is all thats needed. Oh, and also the fractions are only added on for the fractional books.

So how I accomplished this back in the day:
- Kindle plugboard goes out as {series}{#series_index_formatted:| - | - }{title}
- that column is built as program: finish_formatting(field('series_index'), field("#format_str"),'','')
- the format_str column is a text column and that was built with a manually run external script (that I did find somewhere on my hard drive, which was halfway a surprise) but that has stopped working at some point.

The script is python that runs via calibre-debug -e, and what it spits out (well, used to) is for instance:

- series with only 1-9: 01.0f (and 1-99 gets 02.0f)
- series with only a 1 and a 1.1: 01.0f and 03.1f respectively

etc.

Given that I want to accomplish this goal of getting what I consider properly formatted per-series indexes (in an automated fashion), is this even the way I'd go about it these days? Because if so, I need to figure out how to repair the python script, but if there's a Better Way, well, might as well make it better.
JJanssen is offline   Reply With Quote
Old 02-15-2023, 09:40 AM   #2
isarl
Addict
isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.
 
Posts: 287
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
It is possible to do everything that you want within Calibre and its template language(s). The user manual gives an example of searching for book series and counting the results (see link at bottom of this comment). Once you have the number of books in a given series, the field width you need can be easily calculated with a bit of math. For instance, you want the number of digits needed to represent the largest index number in the series. For the sake of example, suppose that number is 12. First we take the base-10 logarithm: log10(12). In this case we get a number a little bit more than 1, about 1.079. Now, we know that 12 has two digits. So we could just round this up: ceil(log10(12)) gives us two. However, consider now a series with 10 books: log10(10) = 1, and ceil(1) = 1. So this formula chokes every time we add a new digit (it will likewise be wrong for 100, for 1000, etc.). Instead, we want: floor(log10(n))+1. Let's test our examples: floor(log10(12)) = 1, 1+1 = 2. And floor(log10(10)) = 1, 1+1=2. What about just before adding another digit?: floor(log10(9)) = 0, 0+1 = 1.

I will leave it as an exercise to you how to calculate the maximum number of digits you need after the decimal place, but supposing that you've already done so, I will refer to that number as n_decimals. (One way to do this would be to do string operations on the indices; subset the index number string to only the part after the decimal and then take its length, for instance.)

So to summarize, given a series of size n_books, you can calculate n_digits = floor(log10(n_books)) + 1 and then you can construct your format strings like strcat('0', n_digits, '.', n_decimals, 'f').

Hope this helps to unstick you! Happy organizing!

Edit: adding link to manual page. This is the page with an example of searching for series by length. Search for the phrase, “For example this template search uses this function and its companion to find all series with only one book”.

Last edited by isarl; 02-15-2023 at 09:47 AM.
isarl is offline   Reply With Quote
Advert
Reply

Tags
formatting


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bugs "Sanity Check epub" and "Failed Release date" on V 0.91 qkiazd Sigil 5 12-03-2015 04:01 AM
Advanced formatting Fortron Recipes 0 02-25-2013 04:42 PM
Advanced ebook formatting tips Nate the great Workshop 46 03-30-2012 08:54 PM
How do you check your formatting? deferredreward Writers' Corner 2 08-31-2010 03:41 PM
Please help me check formatting on Kindle fakefir Amazon Kindle 1 03-05-2010 04:41 PM


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


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