11-29-2016, 10:14 PM | #1 |
Enthusiast
Posts: 33
Karma: 1032
Join Date: Nov 2016
Device: Kobo Aura Edition 2, Lenovo Android 10
|
Send to device based on Tag
Hi,
I have the latest calibre (2.73.0) and a standard android 7" tablet (Android 4.4.2). I want to send my fiction books to ebooks/Fiction/ on the SD card, and my non-fiction books to ebooks/Non-Fiction/. I'm okay with the standard title-author file names inside those folders. I tried to play around with the template editor to get this done, after a few tries, here's where I am (it's still not doing what I want): Code:
lookup(tags:Fiction,{Fiction/{title} - {authors}},{Non-Fiction/{title} - {authors}}) |
11-30-2016, 04:24 AM | #2 |
Grand Sorcerer
Posts: 11,863
Karma: 7036239
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
There are several problems with the template. First, in Single Function Mode you cannot use template functions outside of a template item ({ ... }). Second, in Single Function Mode you should not use template items embedded in other template items ({foo {bar}}). Third, lookup doesn't take a search, instead taking metadata field names. Finally, given what you are trying to do, lookup isn't the best function to use.
Given the complexity of what you are trying to do, you should use General Program Mode. That mode gives you much more control over function arguments, in particular permitting nested function calls. Also, I think that the str_in_list function is a better match than lookup. This GPM template does what I think you want. Code:
program: str_in_list( field('tags'), ',', 'Fiction', template('Fiction/{title} - {authors}'), template('Non-Fiction/{title} - {authors}')) Code:
program: ta = strcat(field('title'), ' - ', field('authors')); str_in_list( field('tags'), ',', 'Fiction', strcat('Fiction/', ta), strcat('Non-Fiction/', ta)) |
11-30-2016, 08:44 PM | #3 |
Enthusiast
Posts: 33
Karma: 1032
Join Date: Nov 2016
Device: Kobo Aura Edition 2, Lenovo Android 10
|
Thanks Chaley! I appreciate the help.
Since you said the second is a more efficient template, I am using that one. I cleared my device and started copying some books over. I'm seeing a strange issue. One book, a collection of novellas, specifically: The 13 crimes of science fiction by Asimov and others, does not accurately copy to the Fiction subfolder, instead, it created this folder structure: Code:
{rootLibraryFolder}/es/Fn/{title} - {authors} I only copied a handful of books so far, but I'm double-checking in case there's an issue that should be fixed before more books are copied to the wrong folders Last edited by wishingstar; 11-30-2016 at 08:46 PM. Reason: More info |
12-01-2016, 03:53 AM | #4 |
Grand Sorcerer
Posts: 11,863
Karma: 7036239
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Calibre enforces a maximum path length when sending to devices. IIRC that max is around 225-250 characters. If a path is longer than that then calibre takes characters out of the middle of each path segment until the path "fits". In your case "Fiction" became "Fn". I suspect that the "es" was "ebooks".
You can use the "shorten" template function to ensure that the length of {title} - {authors} is less than some amount. Perhaps you might want to apply shorten separately to each of title and authors. Another possibility is to use only the first author. Up to you. |
12-02-2016, 12:08 AM | #5 |
Enthusiast
Posts: 33
Karma: 1032
Join Date: Nov 2016
Device: Kobo Aura Edition 2, Lenovo Android 10
|
That made a lot of sense, thanks Chaley!
Here's how I worked around the problem, if anyone needs to do this or something similar. I used chaley's second suggestion for the template in General Program Mode: Code:
program: ta = strcat(field('title'), ' - ', field('authors')); str_in_list( field('tags'), ',', 'Fiction', strcat('Fiction/', ta), strcat('Non-Fiction/', ta)) 1st column: Lookup name: firstauth Column Heading: First Author Type: Built from other columns Template: Code:
{authors:sublist(0, 1, & )} Lookup name: serind Column Heading: Series Index Type: Built from other columns Template: Code:
{series_index:0>5.2f} Code:
ta = test(field('series'),strcat(field('series'),'/',field('#serind'),' - ',field('#firstauth'), ' - ',field('title')), strcat(field('#firstauth'),' - ',field('title'))); 1- checks if the book has a series, if yes, go to step 2, if not, go to step 4 2- if there is a series, it puts the book in a subfolder with the series name, the subfolder is inside Fiction or Non-Fiction depending on the tags. 3- name the file by using a five-digit number with leading zeroes, a decimal point, and 2 decimal places for the series index, then add a dash, the name of the first author, another dash, then the book title. End program! 4- if no series, the file goes into the main folder (fiction or non-fiction depending on the tags) 5- the file name is now simply the first author's name, a dash, and the book title. End Program! Hope this help anyone who wants to do a similar thing in calibre. And thanks again chaley for the great insights into the inner workings of Calibre Last edited by wishingstar; 12-02-2016 at 12:11 AM. Reason: realized i had the wrong flowchart in the program steps, added "End program" to clarify |
03-15-2017, 09:33 AM | #6 |
Enthusiast
Posts: 33
Karma: 1032
Join Date: Nov 2016
Device: Kobo Aura Edition 2, Lenovo Android 10
|
Sorry to resurrect an old thread (i'll create a new one if this is against the rules). I recently had to wipe my hard drive and forgot about backing up Calibre config folder. I'm trying to recreate this but the template editor isn't recognizing the fields. I'm using Calibre 2.81.0
When I try to use the template, exactly as I posted above, I get the message: The template contains no {fields}, so all books will have the same name. Is this OK? The template doesn't look at any fields, it uses "Series" for what should be the book series, "Author" and "Title", and for some reason, series index defaults to 3. Any pointers would be appreciated, |
03-15-2017, 10:05 AM | #7 | |
Grand Sorcerer
Posts: 11,863
Karma: 7036239
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
|
|
Tags |
android, file management, send to device, template language |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Using Tags or tag-like column in Save To Disk/Send to Device | BookJunkieLI | Library Management | 34 | 05-03-2015 05:45 AM |
Send tag to device only if tag has more than 1 book? | eosrose | Calibre | 0 | 01-29-2013 07:46 PM |
Automatically tag based on column info? | Iocane | Library Management | 3 | 09-10-2012 12:40 PM |
Different Send to Device routine based on the library. | iatheia | Library Management | 10 | 01-24-2012 12:06 PM |
Send to device based on Metadata | DavidTC | Calibre | 0 | 09-18-2011 01:18 PM |