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 09-15-2018, 03:09 PM   #1
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
Saving ebooks Template Problem

Hi.

Could it be possible to use composite columns in the template for saving to disk?

I have the following template but it reverts back to the one before when I try to use it:

Code:
'{#fandom_main} - {#fandom_secondary}/{author}/{title} ({#story_id})
If it's not possible to use composite columns, can I use only the first 2 tags in the Fandom column? They are split with a &.

Otherwise some of the names of folders it saves to ends up being longer than my windows can handle like the following:

Quote:
Buffy the Vampire Slayer,Cheers (TV),Cupid (TV 1998),Star Trek_ Deep Space Nine Ties - Fandom,Charmed,Greek and Roman Mythology,A-Team (TV),I Dream of Jeannie
Thanks so much.

Edit: After further thought, could I create a template where only part of it is activated based on conditions like amount of tags in a custom tag-column?

Last edited by Tanjamuse; 09-16-2018 at 05:34 AM.
Tanjamuse is offline   Reply With Quote
Old 09-16-2018, 05:58 AM   #2
Divingduck
Wizard
Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.
 
Posts: 1,161
Karma: 1404241
Join Date: Nov 2010
Location: Germany
Device: Sony PRS-650
You can use composite columns. You can use the function sublist e.g.
{tags:sublist(0,2,\,)} to extract values from a list like tags.
https://manual.calibre-ebook.com/gen...ndex-separator

Last edited by Divingduck; 09-16-2018 at 06:01 AM.
Divingduck is offline   Reply With Quote
Old 09-16-2018, 06:00 AM   #3
Divingduck
Wizard
Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.
 
Posts: 1,161
Karma: 1404241
Join Date: Nov 2010
Location: Germany
Device: Sony PRS-650
@Kovid,

I think, there seems to be something wrong in the manual. Missing/wrong character for backslash.

First place:
https://manual.calibre-ebook.com/template_lang.html, section:
"Using functions in templates - single-function mode"

Quote:
Arguments are separated by commas. Commas inside arguments must be preceeded by a backslash ( ‘' ). The last (or only) argument cannot contain a closing parenthesis ( ‘)’ ). Functions return the value of the field used in the template, suitably modified.
( ‘' ) --> [‘] instead of [\]

Second place:
https://manual.calibre-ebook.com/gen...ndex-separator

Quote:
Examples using basic template mode and assuming that the tags column (which is comma-separated) contains "A, B, C": {tags:sublist(0,1,,)} returns "A". {tags:sublist(-1,0,,)} returns "C". {tags:sublist(0,-1,,)} returns "A, B".
instead of
Quote:
Examples using basic template mode and assuming that the tags column (which is comma-separated) contains "A, B, C": {tags:sublist(0,1,\,)} returns "A". {tags:sublist(-1,0,\,)} returns "C". {tags:sublist(0,-1,\,)} returns "A, B".
Divingduck is offline   Reply With Quote
Old 09-16-2018, 06:19 AM   #4
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
Quote:
Originally Posted by Divingduck View Post
You can use composite columns. You can use the function sublist e.g.
{tags:sublist(0,2,\,)} to extract values from a list like tags.
https://manual.calibre-ebook.com/gen...ndex-separator
Could you show me how to based on my columns if I add what I've got in them?
Tanjamuse is offline   Reply With Quote
Old 09-16-2018, 06:43 AM   #5
Divingduck
Wizard
Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.
 
Posts: 1,161
Karma: 1404241
Join Date: Nov 2010
Location: Germany
Device: Sony PRS-650
For the template
{#fandom_main} - {#fandom_secondary}/{author}/{title} ({#story_id})

change to:

{#fandom_main:sublist(0,2,\,)} - {#fandom_secondary:sublist(0,2,\,)}/{author}/{title} ({#story_id})

In case your column definition is like tags. If not, you need to check if your list separator is a comma or something else and correct the separator to what ever you are using.


The result should be something like
fandom_main1,fandom_main2 - fandom_secondary,fandom_secondary\author\title (story_id)

It takes from each of your two fandom columns list the first two items.
Divingduck is offline   Reply With Quote
Old 09-16-2018, 06:55 AM   #6
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
The separator is a &.

Alternate I have a composite column like this:

Code:
{#fandoms:count(&)}
Could it be possible to create a template that says:

if it's more than 2 fandoms add Multi-Crossovers to the folder it saves to?
Tanjamuse is offline   Reply With Quote
Old 09-16-2018, 07:24 AM   #7
Divingduck
Wizard
Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.
 
Posts: 1,161
Karma: 1404241
Join Date: Nov 2010
Location: Germany
Device: Sony PRS-650
What is your column definition exactly for both columns (with an example)?
Is it only a text column like
Buffy the Vampire Slayer,Cheers (TV)&Cupid (TV 1998)&Star Trek_ Deep Space Nine Ties

Then your separator should be & or \&

In the end you can do do everything you want in a template. If you want to do more complex combinations use the program mode in the template, e.g.

Spoiler:
program:
lib = current_library_name();
tmp1 = template('MainLib/{author_sort}/{author_sort}{series:| - |} {series_index:0>2s} - {title}');
tmp2 = template('OtherLibs/{author_sort}/{author_sort}{series:| - |} {series_index:0>2s} - {title}');
contains(lib,"Calibre Bibliothek",tmp1,tmp2);

This one will move books to two different folders (MainLib, OtherLibs) depending on a library name. "Calibre Bibliothek" goes to MainLib and all others go to OtherLibs.


For now I haven't the time to help more but this evening I can spend some time to help if you give me some more input of your structure (or maybe someone else can jump in too).
Divingduck is offline   Reply With Quote
Old 09-16-2018, 07:43 AM   #8
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
Ok, I'll try:

I've added screenshots for all the columns involved.

I think I would prefer this solution:

If the count of fandoms is more than 2, have the template put the story in a folder called: Multiple Crossovers without adding the fandoms. The rest of it would be like the one I have (it will always end with this):

Code:
/{author}/{title} ({#story_id})
If I can create a whole bunch of templates, does that mean that I can create a lot of different versions based on the libaries I have?
Attached Thumbnails
Click image for larger version

Name:	Fandoms.png
Views:	114
Size:	25.9 KB
ID:	166329   Click image for larger version

Name:	Main Fandom.png
Views:	106
Size:	29.2 KB
ID:	166330   Click image for larger version

Name:	Secondary Fandom.png
Views:	110
Size:	29.7 KB
ID:	166331   Click image for larger version

Name:	Count Fandoms.png
Views:	106
Size:	29.5 KB
ID:	166332  
Tanjamuse is offline   Reply With Quote
Old 09-16-2018, 08:49 AM   #9
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: 43,844
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
https://github.com/kovidgoyal/calibr...af0b50ad768902

should take care of it when the manual is rebuilt for the next release.
kovidgoyal is offline   Reply With Quote
Old 09-17-2018, 02:45 AM   #10
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
I've looked over the template language in the manual and found this thread: https://www.mobileread.com/forums/sh...d.php?t=294354

Which got me to here:

Code:
{#fandoms:sublist(0,1,&)||/}{#fandoms:sublist(0,2,&)||/}/{author}/{title} ({#story_id})
The fandoms column is a tag column, but with names, which means the separator is &.

The template above gives me this:

Code:
Buffy the Vampire Slayer,Cheers (gy,A-Team (TV),I Dream of Jeannie
I would much prefer a option like I posted yesterday with counting and then adding them to a folder called: Multiple Crossovers, that would make them much easier to find.
Tanjamuse is offline   Reply With Quote
Old 09-17-2018, 03:11 AM   #11
Divingduck
Wizard
Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.
 
Posts: 1,161
Karma: 1404241
Join Date: Nov 2010
Location: Germany
Device: Sony PRS-650
Quote:
Originally Posted by kovidgoyal View Post
[url]should take care of it when the manual is rebuilt for the next release.
Thanks a lot
Divingduck is offline   Reply With Quote
Old 09-17-2018, 04:31 AM   #12
Divingduck
Wizard
Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.
 
Posts: 1,161
Karma: 1404241
Join Date: Nov 2010
Location: Germany
Device: Sony PRS-650
Quote:
If I can create a whole bunch of templates, does that mean that I can create a lot of different versions based on the libaries I have?
Yes. This is something where you use the general program mode within the template language like I show in post #7

Quote:
I would much prefer a option like I posted yesterday with counting and then adding them to a folder called: Multiple Crossovers, that would make them much easier to find.
You can use the "Template program mode" - something like this:
Code:
program: 

tmp1 = template('{#fandom_main:sublist(0,2,\,)} - {#fandom_secondary:sublist(0,2,\,)}/{author}/{title} ({#story_id})');
tmp2 = template('Multiple Crossovers/{author}/{title} ({#story_id})');

	cmp(
		count(
			field('#fandom_main'), 
			','), 
		2, 
		tmp1, 
		tmp2, 
		tmp2)
tmp1 and tmp2 are two different templates (you can adust it like you need it). cmp compares two values and give in this case two different templates depending on count back. You need to use the function field() to use the values of the metadata. ',' is the separator for the values (change it to what you need, e.g. '&'). In this example the template 1 is used if count is less than 2.

Reference:
https://manual.calibre-ebook.com/gen...p-x-y-lt-eq-gt
https://manual.calibre-ebook.com/tem...l-program-mode

Last edited by Divingduck; 09-17-2018 at 04:46 AM.
Divingduck is offline   Reply With Quote
Old 09-17-2018, 04:42 AM   #13
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
I've made a small change to what you posted since it had to be 3 fandoms or more instead of 2, I've also deleted the - because it added it to the end of the folder names whenever there was only 1 or 2 fandoms Can you add a string for when it's only 2 fandoms it needs to add them to a folder named Crossovers but it needs to keep the fandoms?

Code:
program: 

tmp1 = template('{#fandom_main:sublist(0,2,\,)}{#fandom_secondary:sublist(0,2,\,)}/{author}/{title} ({#story_id})');
tmp2 = template('Multiple Crossovers/{author}/{title} ({#story_id})');

	cmp(
		count(
			field('#fandom_main'), 
			','), 
		3, 
		tmp1, 
		tmp2, 
		tmp2)
Tanjamuse is offline   Reply With Quote
Old 09-17-2018, 06:49 AM   #14
Divingduck
Wizard
Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.
 
Posts: 1,161
Karma: 1404241
Join Date: Nov 2010
Location: Germany
Device: Sony PRS-650
Not sure if I get your request correct. a example could help for each variant

When you need more differentiation than less, equal, greater then the function switch() is maybe more suitable for your task. Something like:

Code:
program: 
tmp0 = template('No Crossovers/{author}/{title} ({#story_id})');
tmp1 = template('{#fandom_main:sublist(0,2,\,)}{#fandom_secondary:sublist(0,2,\,)}/{author}/{title} ({#story_id})');
tmp2 = template('Crossovers/{#fandom_main:sublist(0,2,\,)}{#fandom_secondary:sublist(0,2,\,)}/{author}/{title} ({#story_id})');
tmp3 = template('Multiple Crossovers/{author}/{title} ({#story_id})');

## old version check if count is lt, eq,gr
#	cmp(
#		count(
#			field('#fandom_main'), 
#			','), 
#		3, 
#		tmp1, 
#		tmp2, 
#		tmp2);

## new version as "case of count =x"
switch(
		count(field('#fandom_main'), ','),
				0, tmp0,
				1, tmp1,
				2, tmp2,
				3, tmp3,
				tmp3);
# in first position of a line means it is a comment, you can delete them if you want. The mechanism works like "if count = 0 use template 0, if count = 1 use template 1 up to count =3 and if count different to 0,1,2,3 use template 3 (or what ever else you want to do


Regarding the '-', you can use as well |-|, || or |-|- for a prefix and/or suffix
Divingduck is offline   Reply With Quote
Old 09-17-2018, 07:12 AM   #15
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
I'll try to be more specific:

I would like them sorted like this:

3 or more fandoms in Multiple Crossovers

only 2 fandoms in Crossovers

The one below only creates the Crossover and no longer the Multiple Crossovers, instead it creates a folder with only the first 2 fandoms in the long list from the multiple crossovers.

Code:
program: 
tmp0 = template('No Crossovers/{author}/{title} ({#story_id})');
tmp1 = template('{#fandom_main:sublist(0,2,\,)}{#fandom_secondary:sublist(0,2,\,)}/{author}/{title} ({#story_id})');
tmp2 = template('Crossovers/{#fandom_main:sublist(0,2,\,)}{#fandom_secondary:sublist(0,2,\,)}/{author}/{title} ({#story_id})');
tmp3 = template('Multiple Crossovers/{author}/{title} ({#story_id})');

## old version check if count is lt, eq,gr
#	cmp(
#		count(
#			field('#fandom_main'), 
#			','), 
#		3, 
#		tmp1, 
#		tmp2, 
#		tmp2);

## new version as "case of count =x"
switch(
		count(field('#fandom_main'), ','),
				0, tmp0,
				1, tmp1,
				2, tmp2,
				3, tmp3,
				tmp3);
I need help for another version of the template as well.

Last edited by Tanjamuse; 09-17-2018 at 02:43 PM.
Tanjamuse is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving ebooks problems Tanjamuse Calibre 12 07-15-2018 08:37 PM
Help with a 'Saving Books to Disk' Template Vortex Calibre 5 12-04-2014 09:18 AM
help with saving template having multiple authors? miquele Library Management 2 04-16-2013 04:49 PM
Save template problem antoon Library Management 12 08-17-2012 12:47 PM
Saving to Disk Template hurricane51 Conversion 2 07-07-2011 01:22 AM


All times are GMT -4. The time now is 10:20 PM.


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