![]() |
#1 |
Member
![]() 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/ |
![]() |
![]() |
![]() |
#2 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
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 |
|
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Member
![]() Posts: 10
Karma: 10
Join Date: Aug 2023
Device: none
|
Quote:
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} EXCEPTION: The function book_count can be used only in the GUI |
|
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
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 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. |
![]() |
![]() |
![]() |
#5 | |
Member
![]() Posts: 10
Karma: 10
Join Date: Aug 2023
Device: none
|
Quote:
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 |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Moderator Notice
Moved to its own thread |
![]() |
![]() |
![]() |
#7 | ||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
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 Quote:
|
||
![]() |
![]() |
![]() |
#8 |
Member
![]() 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. |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |