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 08-12-2023, 10:05 PM   #1
imnnrv
Member
imnnrv began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Aug 2023
Device: none
Save-to-disk template using count of books by author

My non-fiction collection consist mostly of 1-2 books of each author and i would like export these books into one directory, except rare cases when i have many books of this author.
Is there any way to make export template which creates directory .../category/author for author only if there are more than X books of this author? If there less than X his books, then put them into .../category/
imnnrv is offline   Reply With Quote
Old 08-14-2023, 08:09 AM   #2
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
Quote:
Originally Posted by imnnrv View Post
My non-fiction collection consist mostly of 1-2 books of each author and i would like export these books into one directory, except rare cases when i have many books of this author.
Is there any way to make export template which creates directory .../category/author for author only if there are more than X books of this author? If there less than X his books, then put them into .../category/
You don't say what "category" is or what to do with multiple authors. I used 'tags' for category, which is probably wrong.

Customize this template to give the answer you want. I used the 'template()' function because that might be easier for you. If I was doing this for me then I would construct the results myself.
Code:
program:
	first_author = list_item($authors, 0, '&');
	books_by_author = book_count('authors:"""=' & first_author & '"""', 0);
	X = 2;
	if books_by_author < X then
		answer = template('{tags}')
	else
		answer = template('{tags}/{authors:list_item(0,&)}')
	fi;
	answer
chaley is offline   Reply With Quote
Old 08-15-2023, 06:21 PM   #3
imnnrv
Member
imnnrv began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Aug 2023
Device: none
Quote:
Originally Posted by chaley View Post
You don't say what "category" is or what to do with multiple authors. I used 'tags' for category, which is probably wrong.
Category is my own column with hierarchy (for example: history.europe).
So perfect scenario for me is:

If Library = fiction:
If main author have less than X books:
Fiction/{languages}/{author_sort} - {pubdate} - {title}
If main author have more than X books:
Fiction/{languages}/{author_sort:sublist(0,1,&)}/{series}/{series:|| }{series_index:|| - }{pubdate} - {title}

If Library = nonfiction….:
If main author have less than X books in this category:
Non-fiction/Category/Subcategory/{author_sort} - {pubdate} - {title}
If main author have more than X books in this category:
Non-fiction/Category/Subcategory/{author_sort:sublist(0,1,&)}/{series}/{series:|| }{series_index:|| - }{pubdate} - {title}

Quote:
Originally Posted by chaley View Post
Customize this template to give the answer you want. I used the 'template()' function because that might be easier for you. If I was doing this for me then I would construct the results myself.
EXCEPTION: The function book_count can be used only in the GUI
imnnrv is offline   Reply With Quote
Old 08-16-2023, 06:33 AM   #4
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
Quote:
Originally Posted by imnnrv View Post
EXCEPTION: The function book_count can be used only in the GUI
Ignore that message, and also the one that follows saying that no fields are in the template. Both of these are historical artifacts that I haven't bothered to try to fix.

EDIT2: I submitted changes to @kovid to remove the errors.
EDIT3: The changes are in calibre source.

If you don't want to ignore the messages then create a new "Column built from other columns" and put the template there. Use the new column's lookup key in the save to disk template. In this case you must set the tweak
Code:
allow_template_database_functions_in_composites
as described in this post.

EDIT: for performance reasons it would be best to hide the new column in the book list so it isn't frequently evaluated.

For your if tests, see General Program Mode in the template language manual..

Last edited by chaley; 08-16-2023 at 01:05 PM.
chaley is offline   Reply With Quote
Old 08-16-2023, 08:42 PM   #5
imnnrv
Member
imnnrv began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Aug 2023
Device: none
Quote:
Originally Posted by chaley View Post
Ignore that message, and also the one that follows saying that no fields are in the template. Both of these are historical artifacts that I haven't bothered to try to fix.
Thank you for you help!

It almost works, except it doesn't count some of authors/books: it think there is less than X books of this authors even if there are 10 and more books.
I've tried to rename them, move these books to new library - all the same (so it doesn't depends on library size). Tried to make X=1 and even then there was 1 author (3 books) counted as <1.
Made test with plugin "Author Book Count': it counts right, so i don't think it's problem with tags.

Can you please check the code for mistakes?

program:
first_author = list_item($authors, 0, '&');
books_by_author = book_count('authors:"""=' & first_author & '"""', 0);
X = 2;
if books_by_author < X then
answer = template('Fiction/{languages}/{author_sort} - {pubdate} - {title}')
else
answer = template('Fiction/{languages}/{author_sort:sublist(0,1,&)}/{series}/{series:|| }{series_index:|| - }{pubdate} - {title}')
fi;
answer
imnnrv is offline   Reply With Quote
Old 08-17-2023, 05:34 AM   #6
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
Moderator Notice
Moved to its own thread
chaley is offline   Reply With Quote
Old 08-17-2023, 05:38 AM   #7
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
Quote:
Originally Posted by imnnrv View Post
Thank you for you help!

It almost works, except it doesn't count some of authors/books: it think there is less than X books of this authors even if there are 10 and more books.
I've tried to rename them, move these books to new library - all the same (so it doesn't depends on library size). Tried to make X=1 and even then there was 1 author (3 books) counted as <1.
Made test with plugin "Author Book Count': it counts right, so i don't think it's problem with tags.

Can you please check the code for mistakes?

program:
first_author = list_item($authors, 0, '&');
books_by_author = book_count('authors:"""=' & first_author & '"""', 0);
X = 2;
if books_by_author < X then
answer = template('Fiction/{languages}/{author_sort} - {pubdate} - {title}')
else
answer = template('Fiction/{languages}/{author_sort:sublist(0,1,&)}/{series}/{series:|| }{series_index:|| - }{pubdate} - {title}')
fi;
answer
I forgot to specify numeric comparison instead of lexical (string) comparison in my original template. In lexical comparison, '10' is less than '2'.

Try this:
Code:
program:
	first_author = list_item($authors, 0, '&');
	books_by_author = book_count('authors:"""=' & first_author & '"""', 0);
	X = 2;
	if books_by_author <# X then
		answer = template('Fiction/{languages}/{author_sort} - {pubdate} - {title}')
	else
		answer = template('Fiction/{languages}/{author_sort:sublist(0,1,&)}/{series}/{series:|| }{series_index:|| - }{pubdate} - {title}')
	fi;
	answer
The change is
Quote:
if books_by_author <# X then
chaley is offline   Reply With Quote
Old 08-19-2023, 10:58 PM   #8
imnnrv
Member
imnnrv began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Aug 2023
Device: none
Thank you very much!

Just one more question: all "pubdates" are one day wrong. For example: 01.01.2023 in calibre -> 31.12.2022 in filename. I suppose it's something about timezones, but can't find solution.
imnnrv is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to save books to disk by Author - Title? (Non Calibre folders) geza Library Management 5 02-08-2025 10:45 AM
Save to Disk Template Help Tanjamuse Library Management 2 08-09-2019 09:35 AM
save to disk template help bilaly Library Management 2 10-19-2018 07:19 PM
Save Books to Disk Template Problem Buckskin Library Management 5 11-15-2015 11:37 AM
Need help on a Save to Disk template fidvo Library Management 2 08-12-2012 03:34 PM


All times are GMT -4. The time now is 11:49 AM.


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