Quote:
Originally Posted by kcz
Makes sense. Is there a description of the calibre data access layer? I found info on the plugin api and some other info, but nothing on the db layer.
|
No. You must look at source and examples. Existing plugins might be the best place to look for examples, because they are smaller and it is easier to determine what they are trying to do.
Quote:
There is the next problem. I found information on the APIs for the different plugins, but the info does not tell me which plugin type I would have to use.
The manual also does not tell me how to use 'hooks' within calibre.
|
The only type I can imagine using successfully would be a user interface plugin. You would run the plugin on demand to compute the necessary numbers.
Quote:
There are several ways how someone could accomplish this formatting function:
1) create a function to be used by the template language
This function would calculate the 2 info points (as described above) every time it is called. Rather ineffecient, since it would have to loop through all books in the series to find the data.
How do I even write a plugin that provides a function for the template language?
|
You don't. There is no way that a template function can access the calibre DB layer, directly or indirectly. They also cannot access the GUI layer, meaning that they cannot use interface plugins.
Quote:
2) create a function plus a meta data table for the series
A new table with 3 columns (string series, int max_int, int max_fract). In this case calibre would have to update this table, every time a series index is changed/added/deleted. Are there any hooks in calibre or would I have to write this part as well?
|
This also won't work because the template function would need access to this table, which is in the database, which is not visible.
You could do it by creating a text custom column and having the UI plugin store the format string into that for each book. That would permit the template language to see the data.
Quote:
In any case, the documentation did not answer any of my questions and I am afraid I do not have the time to get familiar with the calibre code base and the plugin interfaces, which I would had to do to be actually able to implement my formatting function.
|
It is true that calibre does not have a "developer's guide to calibre internals". I can't see that ever happening for two reasons: 1) no one wants to attempt to write it, and 2) maintaining it would be crushing because calibre changes so fast.
Quote:
I hoped that calibre would already provide a functionality like this, since it seems logical to me that someone would like to have aligned indexes in a filename without having to hardcode the padding. e.g. who wants a filename like 'seriesname [007.000] bookname', if the biggest index is 7.00 and the series has only integers?
|
Actually, you are the first I know of to care about this particular variant. Perhaps some of the people who care don't tell us, or perhaps they use devices like Sony & Kobo or apps like CC that don't require the series in the file name. The issue of db access in template functions has come up before, but IIRC in the context of wanting things like "Series [Book 1 of N]" or "Avg rating: 3.5".
If I were you, I would just solve the problem by hand. Create a custom text column to hold the format string for a book and manually set its content using the mark-1 eyeball to determine the format you want.
Hmmm... the above leads me down another path. You could use the command line interface to dump the series information to a CSV table (calibredb), write a script to process that table and compute the resulting format strings, then use the command line interface to set the value of the custom column for the books in a series (calibredb search to get the ids for the books in a series then calibredb set_custom for each id).