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-02-2018, 11:13 AM   #1
fernandie
Member
fernandie began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Feb 2018
Device: Lenovo Yoga Tab 3
Display smallest format's file size?

In Calibre, the "size" column displays the size of the largest format for any given book. I'd like to be able to create a custom column to display the size of the smallest format of any given book. Is this possible? If so, how should I go about it?
fernandie is offline   Reply With Quote
Old 02-02-2018, 11:42 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Use the formats_sizes() function. But note that doing this is very slow because it means filesystem access for evey format for every book.
kovidgoyal is offline   Reply With Quote
Old 02-02-2018, 04:26 PM   #3
fernandie
Member
fernandie began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Feb 2018
Device: Lenovo Yoga Tab 3
Thanks, Kovid!
fernandie is offline   Reply With Quote
Old 02-15-2018, 02:57 PM   #4
ilovejedd
hopeless n00b
ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.
 
ilovejedd's Avatar
 
Posts: 5,110
Karma: 19597086
Join Date: Jan 2009
Location: in the middle of nowhere
Device: PW4, PW3, Libra H2O, iPad 10.5, iPad 11, iPad 12.9
Question, how do you use formats_sizes() in bulk s&r?

I've tried:

{formats_sizes}
{formats_sizes()}
{id:formats_sizes()}
{title:formats_sizes()}
{self:formats_sizes()}
{book:formats_sizes()}

I get S/R TEMPLATE ERROR on all of them (either unknown field or too many arguments).
ilovejedd is offline   Reply With Quote
Old 02-15-2018, 03:41 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,445
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ilovejedd View Post
Question, how do you use formats_sizes() in bulk s&r?

I've tried:

{formats_sizes}
{formats_sizes()}
{id:formats_sizes()}
{title:formats_sizes()}
{self:formats_sizes()}
{book:formats_sizes()}

I get S/R TEMPLATE ERROR on all of them (either unknown field or too many arguments).
As formats_sizes takes no arguments you cannot use "single function mode" templates, which all of your examples are. SFM templates require a template field and pass that value to the template.

Instead you can use either template program mode
Code:
{:'formats_sizes()'}
or general program mode
Code:
program: formats_sizes()
The choice depends on what you are trying to do.
chaley is offline   Reply With Quote
Old 02-15-2018, 04:26 PM   #6
ilovejedd
hopeless n00b
ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.
 
ilovejedd's Avatar
 
Posts: 5,110
Karma: 19597086
Join Date: Jan 2009
Location: in the middle of nowhere
Device: PW4, PW3, Libra H2O, iPad 10.5, iPad 11, iPad 12.9
Thanks!

This got me the raw data needed:
Code:
{:'select(formats_sizes(),'EPUB')'}
I basically want to replace the default Size (MB) column with a Size (KB) or maybe just Size with the numbers formatted with human_readable() showing the EPUB file size instead of the size of the largest file.

I have another question, if I wanted it displayed as #,### (in KB), can I store in a number-type custom column and use just the display format options to prettify? Or do I need to store the data first in an number-type custom column and then create another custom column (built from other columns) to get the prettified formatting?

For speed, I'm guessing minimizing filesystem access is best so better to have a placeholder for file size rather than call formats_sizes() for each book in the library every time I open Calibre?

Thanks again!
ilovejedd is offline   Reply With Quote
Old 02-15-2018, 06:24 PM   #7
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 31,048
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by ilovejedd View Post
Thanks!

This got me the raw data needed:
Code:
{:'select(formats_sizes(),'EPUB')'}
I basically want to replace the default Size (MB) column with a Size (KB) or maybe just Size with the numbers formatted with human_readable() showing the EPUB file size instead of the size of the largest file.

I have another question, if I wanted it displayed as #,### (in KB), can I store in a number-type custom column and use just the display format options to prettify? Or do I need to store the data first in an number-type custom column and then create another custom column (built from other columns) to get the prettified formatting?

For speed, I'm guessing minimizing filesystem access is best so better to have a placeholder for file size rather than call formats_sizes() for each book in the library every time I open Calibre?

Thanks again!
Not a good plan
That (and some others) field auto updates during the normal management of books.

Use a Custom field for stable data
theducks is offline   Reply With Quote
Old 02-15-2018, 07:58 PM   #8
ilovejedd
hopeless n00b
ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.
 
ilovejedd's Avatar
 
Posts: 5,110
Karma: 19597086
Join Date: Jan 2009
Location: in the middle of nowhere
Device: PW4, PW3, Libra H2O, iPad 10.5, iPad 11, iPad 12.9
Quote:
Originally Posted by theducks View Post
Not a good plan
That (and some others) field auto updates during the normal management of books.

Use a Custom field for stable data
A custom column is what I meant by "better to have a placeholder for file size". My main question was whether I need one custom column or two.

e.g.

#epub_size (int) - {:'select(formats_sizes(),'EPUB')'} set via bulk s&r
then number formatting done via display formats option (is that doable?)

or

#epub_size (int) - {:'select(formats_sizes(),'EPUB')'} set via bulk s&r
#size (composite) - {#epub_size:human_readable()}
ilovejedd is offline   Reply With Quote
Old 02-16-2018, 02:33 AM   #9
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,445
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ilovejedd View Post
A custom column is what I meant by "better to have a placeholder for file size". My main question was whether I need one custom column or two.

e.g.

#epub_size (int) - {:'select(formats_sizes(),'EPUB')'} set via bulk s&r
then number formatting done via display formats option (is that doable?)

or

#epub_size (int) - {:'select(formats_sizes(),'EPUB')'} set via bulk s&r
#size (composite) - {#epub_size:human_readable()}
The number formatter used in numeric custom columns cannot generate a "human readable" string, nor can it divide by 1000. It can add commas and the like. From what you say, this isn't what you want.

You can easily do it with two columns, one containing the value and the other a composite column (built from other columns) that formats the number as you wish, doing any arithmetic needed. The first column can be precomputed or also be a composite column that fetches the data on demand.

You can do it in one composite column in general program mode, fetching the value then formatting it.

You can do it in one composite column where the value to be formatted is precomputed and inserted into the template. How and when you fetch the number to insert into the template is up to you. I think there are two practical possibilities:
  • Use bulk search/replace to update the column for each book. Advantage: easy to set up. Disadvantages: you must remember to run it and it will update last_modified for every book.
  • Use something like the Save Virtual Libraries To Column library-closed plugin. The plugin would compute the appropriate template string for each book then check if the new template equals the existing one. If it does not, update the book. Advantages: the last_modified date isn't updated unless something changes, and the values are automatically updated from time to time. Disadvantage: the values for new/changed books will be wrong until you close and reopent the library.
You could also do it in two columns using the above methods, where the precompute cycle stores the number.

Finally, you can do it in one numeric custom column using the above methods, where the precompute cycle does the appropriate arithmetic so the format string will be able to display the number (probably divide by 1000).
chaley is offline   Reply With Quote
Old 02-07-2021, 09:19 AM   #10
dunhill
Guru
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
Posts: 893
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
The formats_sizes function converts from mb to kb?
Or how would the syntax be for a custom column.
dunhill is offline   Reply With Quote
Old 02-07-2021, 09:47 AM   #11
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,445
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by dunhill View Post
The formats_sizes function converts from mb to kb?
Or how would the syntax be for a custom column.
The formats_sizes function returns a list of all the formats with the size in bytes. If you want the size in some other scale then you must compute it yourself.

For example, this template returns the size of the EPUB format in KB, or the empty string if there isn't an EPUB format.
Code:
program:
	if epub_size = select(formats_sizes(), 'EPUB') then 
		format_number(floor(divide(epub_size, 1024)), '{:,d} KB')
	fi
You can also use the human_readable() function that chooses a reasonable scale factor.
Code:
program:
	human_readable(select(formats_sizes(), 'EPUB'))

Last edited by chaley; 02-07-2021 at 09:51 AM.
chaley is offline   Reply With Quote
Old 02-07-2021, 10:11 AM   #12
dunhill
Guru
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
Posts: 893
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
Thanks for the tip and the example Chaley!
dunhill is offline   Reply With Quote
Old 05-29-2021, 12:00 AM   #13
fernandie
Member
fernandie began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Feb 2018
Device: Lenovo Yoga Tab 3
Quote:
Originally Posted by kovidgoyal View Post
Use the formats_sizes() function. But note that doing this is very slow because it means filesystem access for evey format for every book.
Would this kind of custom column still be very slow or have changes been made since 2018 that this would now be more feasible?
fernandie is offline   Reply With Quote
Old 05-29-2021, 04:52 AM   #14
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,445
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by fernandie View Post
Would this kind of custom column still be very slow or have changes been made since 2018 that this would now be more feasible?
It still must access the file system. However, "very slow" is in the eye of the beholder. Try it and see.
chaley is offline   Reply With Quote
Reply

Tags
custom columns, format size


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best document format for reading with smallest file size. rupeshforu3 General Discussions 21 12-10-2017 04:47 PM
Refresh file size display after changing PDF outside calibre? gingerbeardman Library Management 4 11-12-2017 05:28 AM
Smallest text size stethorn Amazon Kindle 1 10-12-2014 10:19 AM
K3 Smallest Font Size Readability? grownupboy Amazon Kindle 6 09-06-2010 08:19 PM


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


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