Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 03-25-2013, 10:28 PM   #1
Gelina
Junior Member
Gelina began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Mar 2013
Device: Nook
Variable Series Index Field

Currently I'm using two different templates when I Save Books to Disk. The only difference between the two is that I use {series_index:0>2s||. } if the series has all whole numbers for the index # and {series_index:0>4.1f||. } if the series has partial numbers for the index #.

What I would like is for an automatic way to do this without having to manual adjust the template each time.

Examples:

If the series goes
SomeSeries 1
SomeSeries 2
SomeSeries 3

I want the index to be:
01.
02.
03.



However, if the series goes
SomeSeries 1
SomeSeries 1.5
SomeSeries 2
SomeSeries 3

I want the index to be:
01.0.
01.5.
02.0
03.0.


Is this possible?
Gelina is offline   Reply With Quote
Old 03-25-2013, 11:05 PM   #2
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,047
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
I use
Code:
series_index:0>5.2s
theducks is offline   Reply With Quote
Advert
Old 03-26-2013, 03:52 AM   #3
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,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Gelina View Post
Is this possible?
No. To do what you ask, a template would need information about other books being "processed", something that the template system does not support.

You can, of course, do it with a plugin that preprocesses the selection to determine the necessary width of the output field.
chaley is offline   Reply With Quote
Old 03-26-2013, 07:42 AM   #4
Gelina
Junior Member
Gelina began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Mar 2013
Device: Nook
Quote:
Originally Posted by theducks View Post
I use
Code:
series_index:0>5.2s
That doesn't come anywhere close to what I'm looking for.

Is it possible to set up a regex that only adds the decimal point if it's there without doing a plugin?

So SomeSeries 1, SomeSeries 2, SomeSeries 3 would still do exactly the same thing, but:


SomeSeries 1
SomeSeries 1.5
SomeSeries 2
SomeSeries 3

would go:
01.
01.5.
02.
03.
Gelina is offline   Reply With Quote
Old 03-26-2013, 08:03 AM   #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,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Use a general program mode template.

The following template shows one way to do variable formatting.
Code:
program:
	si = field('series_index');
	index_val = test(
			field('series'),
			contains(si, '\.', 
				format_number(si, '{0:04.1f}'), 
				format_number(si, '{0:02d}')), 
			'');
	finish_formatting(index_val, '', '', '.')
You will of course need to add the rest of the template to the result value, probably using the template function.

An alternate way to do it would be to generate the template string you want depending on the value of series and series_index, then return the result of evaluating that template. Which is easier for you depends on how you think.
chaley is offline   Reply With Quote
Advert
Old 03-26-2013, 09:03 PM   #6
Gelina
Junior Member
Gelina began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Mar 2013
Device: Nook
I apologize for being an idiot - but I can't get that to work. I went into "Template Functions" and put the function name as my_seriesindex and your code as the program code, but I keep getting a compile error.

NameError: name 'field' is not defined


The entire template I've been using is:

Code:
{#booktype}/{author_sort:re([.]$,)}/{series}/{series_index:0>2s||. }{title} - {authors}
or

Code:
{#booktype}/{author_sort:re([.]$,)}/{series}/{series_index:0>4.1f||. }{title} - {authors}
If anyone has the patience to explain step by step what I need to do, I would really appreciate it. Thank you.
Gelina is offline   Reply With Quote
Old 03-27-2013, 07:44 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,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Gelina View Post
I apologize for being an idiot - but I can't get that to work. I went into "Template Functions" and put the function name as my_seriesindex and your code as the program code, but I keep getting a compile error.
A general program mode template is a template, not a function. It is a complete template written in the template programming language. It must be the only thing in the template box.
Quote:
The entire template I've been using is:

Code:
{#booktype}/{author_sort:re([.]$,)}/{series}/{series_index:0>2s||. }{title} - {authors}
or

Code:
{#booktype}/{author_sort:re([.]$,)}/{series}/{series_index:0>4.1f||. }{title} - {authors}
You are currently using single function mode templates. They are not the same as template program mode templates or general program mode templates.

The following GPM template should do what you want. It is not a particularly elegant solution, but it should be understandable.
Code:
program:
	t_dot =   '{#booktype}/{author_sort:re([.]$,)}/{series}/{series_index:0>4.1f||. }{title} - {authors}';
	t_nodot = '{#booktype}/{author_sort:re([.]$,)}/{series}/{series_index:0>2s||. }{title} - {authors}';
	t_noseries = t_nodot;
	template = test(field('series'),
			contains(field('series_index'), 
				'\.', 
				t_dot, 
				t_nodot), 
			t_noseries);
	template(template)
You put the above into the box that currently contains the {...} stuff. You can define t_noseries to be a different template, the one that is used when the book does not have a series.
chaley is offline   Reply With Quote
Old 03-27-2013, 06:36 PM   #8
Gelina
Junior Member
Gelina began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Mar 2013
Device: Nook
Thank you SO much. That works perfectly
Gelina is offline   Reply With Quote
Old 06-03-2013, 06:09 AM   #9
darkul
Junior Member
darkul began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Sep 2011
Device: none
Strange compiler errors

Using version 0.9.33.

What am I doing wrong?
I always get a compiler error saying Nameerror: "test" is not defined.
Usually I know how to code, but here I'm stuck.
If I add program: as first line it says: SyntaxError: invalid syntax.

It seems the GPM mode is not working?
Am I missing something here, some Preferences not correctly set?
darkul is offline   Reply With Quote
Old 06-03-2013, 06:25 AM   #10
darkul
Junior Member
darkul began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Sep 2011
Device: none
Ok, edit: error exists in 32/64-bit version

Last edited by darkul; 06-03-2013 at 06:32 AM.
darkul is offline   Reply With Quote
Old 06-03-2013, 11:54 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,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by darkul View Post
Using version 0.9.33.

What am I doing wrong?
I always get a compiler error saying Nameerror: "test" is not defined.
Usually I know how to code, but here I'm stuck.
If I add program: as first line it says: SyntaxError: invalid syntax.

It seems the GPM mode is not working?
Am I missing something here, some Preferences not correctly set?
As far as I know GPM works fine. Post your template so I can see what is going wrong.
chaley is offline   Reply With Quote
Old 06-04-2013, 01:54 AM   #12
darkul
Junior Member
darkul began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Sep 2011
Device: none
It's your template, just with t_nodot replaced.
Even used an empty string there.

Tried this
Code:
program:
	t_dot = '';
	t_nodot = ''
and it stops with a syntax error on "program:"

Could it be that I have to install calibre from scratch, deleting every single trace it left anywhere on my machine? I try that first before we have to think too much.
-> Ok, done that ... same problem as before

Last edited by darkul; 06-04-2013 at 02:18 AM.
darkul is offline   Reply With Quote
Old 06-04-2013, 04:27 AM   #13
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,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by darkul View Post
It's your template, just with t_nodot replaced.
Even used an empty string there.

Tried this
Code:
program:
	t_dot = '';
	t_nodot = ''
and it stops with a syntax error on "program:"
That text works fine for me, as shown in the attached screen capture. Where exactly are you putting it when you get the syntax error?
Attached Thumbnails
Click image for larger version

Name:	Clipboard02.png
Views:	318
Size:	24.1 KB
ID:	106585  
chaley is offline   Reply With Quote
Old 06-04-2013, 05:58 AM   #14
darkul
Junior Member
darkul began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Sep 2011
Device: none
Ah, ok, maybe that's not working at all if I enter it in the wrong windows, though to me this seems illogical. Why is there a posibility to add GPMs in "Template functions" if it is not compiling ok?

Under Preferences - Template functions
Though window looks different.

Click image for larger version

Name:	pic1.png
Views:	329
Size:	92.6 KB
ID:	106587

Last edited by darkul; 06-04-2013 at 06:19 AM.
darkul is offline   Reply With Quote
Old 06-04-2013, 06:53 AM   #15
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,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by darkul View Post
Ah, ok, maybe that's not working at all if I enter it in the wrong windows, though to me this seems illogical. Why is there a posibility to add GPMs in "Template functions" if it is not compiling ok?

Under Preferences - Template functions
Though window looks different.
User-defined template functions are not GPM templates. They are real python programs that are used to create new GPM functions. You would use them to add new functionality to the template language. For example, some people have used them to parse annotations from books to get the percentage of the book read.

You enter GPM templates in any box that can accept a "{ ... }" style template, such as for save-to-disk or send-to-device, or when creating or editing composite custom columns.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Increment Series Index Tweak penguinaka Calibre 16 07-30-2011 07:17 PM
Series Index Auto Increment lgladen Calibre 4 04-14-2011 09:14 AM
Variable Search, Replace & Transfer to a new field flopis Library Management 10 03-09-2011 11:41 AM
Command Line problems: ebook-convert, ebook-meta with tags: --series, --series-index omnivorous Calibre 4 11-07-2010 02:42 PM
Series index Save to Disk problem Dopedangel Calibre 6 08-27-2009 04:54 PM


All times are GMT -4. The time now is 04:28 AM.


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