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-19-2014, 01:44 PM   #586
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by DMee View Post
My bad re comples_series - I had forgotten we went for a manual Y/N re complex series

I was thinking of the code

https://www.mobileread.com/forums/sho...&postcount=552

To set the correct format.

I thought the code before the latest tweak took care of leading spaces later on - yours adds brackets and then original adds 2 more brackets later on :-)
Whoopsie.

PHP Code:
program:
#       compute the equivalent of the composite fields and store them in local variables
stripped re(field('series'), '^(A|The|An)\s+''');
shortened shorten(stripped4'-' ,4);
initials re(list_re(stripped' ''[\s]?([^\s]{1,3})[^\s]*(\s|$)''\1'), ' ''-');

#       Format the series index. Ends up as empty if there is no series index.
#       Note that leading and trailing spaces will be removed by the formatter,
#       so we cannot add them here. We will do that in the strcat below.
#       Also note that because we are in 'program' mode, we can freely use
#       curly brackets in strings, something we cannot do in template mode.
#
#       Using the new ser_num calculation from https://www.mobileread.com/forums/showpost.php?p=2916022&postcount=548
s_index test(
    
field('#complex_series'),
    
finish_formatting(
        
field('series_index'),
        
'_>7.2f',
        
'',
        
''
    
),
    
finish_formatting(
        
field('series_index'),
        
'_>4d',
        
'',
        
''
    
),
);

#       print(stripped, shortened, initials, s_index);

#       Now concatenate all the bits together. The switch picks between
#       initials and shortened, depending on whether there is a space
#       in stripped. We then add the brackets around s_index if it is
#       not empty. Finally, add the title. As this is the last function in
#       the program, its value will be returned.
strcat(
    switch(
        
stripped,
        
'.\s',
        
initials,
        
'.',
        
shortened,
        
field('series')
    ),
    
test(
        
s_index,
        
strcat(' ['s_index'] '),
        
''
    
),
    
field('title')
); 
If we are using chaley's script, it's even easier. Just plug in "#complex_series" as the actual value of s_index.

PHP Code:
program:
#       compute the equivalent of the composite fields and store them in local variables
stripped re(field('series'), '^(A|The|An)\s+''');
shortened shorten(stripped4'-' ,4);
initials re(list_re(stripped' ''[\s]?([^\s]{1,3})[^\s]*(\s|$)''\1'), ' ''-');

#       Format the series index. Ends up as empty if there is no series index.
#       Note that leading and trailing spaces will be removed by the formatter,
#       so we cannot add them here. We will do that in the strcat below.
#       Also note that because we are in 'program' mode, we can freely use
#       curly brackets in strings, something we cannot do in template mode.
#
#       s_index is now a manually set value using field "#complex_series"
s_index field('#complex_series');

#       print(stripped, shortened, initials, s_index);

#       Now concatenate all the bits together. The switch picks between
#       initials and shortened, depending on whether there is a space
#       in stripped. We then add the brackets around s_index if it is
#       not empty. Finally, add the title. As this is the last function in
#       the program, its value will be returned.
strcat(
    switch(
        
stripped,
        
'.\s',
        
initials,
        
'.',
        
shortened,
        
field('series')
    ),
    
test(
        
s_index,
        
strcat(' ['s_index'] '),
        
''
    
),
    
field('title')
); 

Last edited by eschwartz; 09-19-2014 at 01:54 PM.
eschwartz is offline   Reply With Quote
Old 09-19-2014, 04:21 PM   #587
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
FWIW: the complexity of this is starting to call for a custom template function.

I have somewhere a python script that scans the database, computes the minimum format to represent the largest series numbers and the minimum number of fractional digits, and stores the format in a custom column. I can post it tomorrow if anyone is interested and if I can find it.
chaley is offline   Reply With Quote
Advert
Old 09-19-2014, 05:13 PM   #588
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Do you mean the one linked from post #585?
eschwartz is offline   Reply With Quote
Old 09-20-2014, 12:44 AM   #589
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by eschwartz View Post
Do you mean the one linked from post #585?
Yes.
chaley is offline   Reply With Quote
Old 09-20-2014, 07:43 AM   #590
DMee
Zealot
DMee began at the beginning.
 
Posts: 116
Karma: 10
Join Date: Jun 2011
Location: Stockport, UK
Device: ipad, iphone, kindle
Quote:
Originally Posted by chaley View Post
Yes.
I just tried running the code

I copied and pasted to a file I called complex-series.txt and saved in my user directory

I then ran

calibre-debug -e complex-series.txt

It did nothing for a few minutes and then I was back at command line

I opened calibre but couldn't spot anything new anywhere

i) am I doing it right?
ii) is that the full code you posted
iii) where should data end up?
DMee is offline   Reply With Quote
Advert
Old 09-20-2014, 08:47 AM   #591
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by DMee View Post
I just tried running the code

I copied and pasted to a file I called complex-series.txt and saved in my user directory

I then ran

calibre-debug -e complex-series.txt

It did nothing for a few minutes and then I was back at command line

I opened calibre but couldn't spot anything new anywhere

i) am I doing it right?
ii) is that the full code you posted
iii) where should data end up?
You must change two things in the script:
1) change line 12 so that 'path-to-your-library' is the real path to your library.
2) change '#text' on line 34 to a lookup name of a text-type (not tags) custom column in your library.

After you run the script you should see the number format in the text column for books with a series, similar to the screen capture below. You would use that format in the template when you generate series strings.
Attached Thumbnails
Click image for larger version

Name:	Capture.PNG
Views:	309
Size:	11.0 KB
ID:	128605  
chaley is offline   Reply With Quote
Old 09-20-2014, 03:13 PM   #592
DMee
Zealot
DMee began at the beginning.
 
Posts: 116
Karma: 10
Join Date: Jun 2011
Location: Stockport, UK
Device: ipad, iphone, kindle
Now where's the blush icon......

Cheers :-)
DMee is offline   Reply With Quote
Old 09-21-2014, 07:14 AM   #593
DMee
Zealot
DMee began at the beginning.
 
Posts: 116
Karma: 10
Join Date: Jun 2011
Location: Stockport, UK
Device: ipad, iphone, kindle
OK, chaley's script ran fine - eventually

But produces

Leg-of-Eli-Mon [{0:01.0f}] The Spirit Thief

when plugged into scrip??
DMee is offline   Reply With Quote
Old 09-21-2014, 07:52 AM   #594
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by DMee View Post
OK, chaley's script ran fine - eventually

But produces

Leg-of-Eli-Mon [{0:01.0f}] The Spirit Thief

when plugged into scrip??
The script produces a number format string, not a formatted series number. I think you want
Code:
s_index = format_number(field('series_index'), field('#complex_series'));
chaley is offline   Reply With Quote
Old 09-21-2014, 08:43 AM   #595
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by chaley View Post
The script produces a number format string, not a formatted series number.
Really? Why doesn't it just have the formatted number?
I jumped to the assumption that your script would produce the actual number, it seemed like a more obvious result.
eschwartz is offline   Reply With Quote
Old 09-21-2014, 09:32 AM   #596
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by eschwartz View Post
Really? Why doesn't it just have the formatted number?
I jumped to the assumption that your script would produce the actual number, it seemed like a more obvious result.
Because that would require writing every book with a different value, meaning a transaction per book in series. As it is, I use the write_many API so there is a transaction per series. I wanted the script to be as fast as possible, and didn't care about any extra work to use the format.

The scheme permits you to copy the format instead of running the script if you know that the existing format is correct. It also permits you to change the format manually in one bulk edit if you change the series structure for a book.

Feel free to change it if you want.
chaley is offline   Reply With Quote
Old 09-21-2014, 10:44 AM   #597
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Ah, Okay. That makes sense. I like your way.

I just didn't realize at first what you were doing.
eschwartz is offline   Reply With Quote
Old 09-21-2014, 06:59 PM   #598
DMee
Zealot
DMee began at the beginning.
 
Posts: 116
Karma: 10
Join Date: Jun 2011
Location: Stockport, UK
Device: ipad, iphone, kindle
Chaley

I tried to be clever and amend your code so it produces {_>7.2f}

which I thought would replicate the

{series_index:_>7.2f}

I used to use

but it doesn't work.......
DMee is offline   Reply With Quote
Old 09-22-2014, 02:40 AM   #599
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by DMee View Post
Chaley

I tried to be clever and amend your code so it produces {_>7.2f}

which I thought would replicate the

{series_index:_>7.2f}

I used to use

but it doesn't work.......
It should be
Code:
{0:_>7.2f}
chaley is offline   Reply With Quote
Old 09-22-2014, 10:57 PM   #600
crissman
Connoisseur
crissman could sell banana peel slippers to a Deveel.crissman could sell banana peel slippers to a Deveel.crissman could sell banana peel slippers to a Deveel.crissman could sell banana peel slippers to a Deveel.crissman could sell banana peel slippers to a Deveel.crissman could sell banana peel slippers to a Deveel.crissman could sell banana peel slippers to a Deveel.crissman could sell banana peel slippers to a Deveel.crissman could sell banana peel slippers to a Deveel.crissman could sell banana peel slippers to a Deveel.crissman could sell banana peel slippers to a Deveel.
 
Posts: 77
Karma: 3090
Join Date: Apr 2013
Location: California
Device: Kobo Aura One, Kobo Aura H20,Kindle PW1
Now that I have been able to configure the plugboards for specific outputs with all your excellent help, I was wondering how to create a regex in search and replace to clean up the title fields in my library.
I would like to remove the series and series_index from the title field:
Examples I have found in the library are:

The Alexander Cipher - Daniel Knox [1]

Hidden Empire: The Saga of Seven Suns, Book 1

The Alexandria Link - Cotton Malone - 2

I would like to strip this down to the title alone and completely remove the series and series numbers

Also there are a few entries that have other info that I would like to remove such as the ": A Novel"

The Charlemagne Pursuit: A Novel
but keeping in mind that there are titles that have the colon and extra title information that I would like to keep like:

The Balkan Escape: A Cassiopeia Vitt Adventure - Cotton Malone [5.50]

and the extra dashes from the title:

The Amber Room - -

I have colored the parts that I would like to remove

Thanks
crissman

Last edited by crissman; 09-22-2014 at 11:24 PM.
crissman is offline   Reply With Quote
Reply

Tags
custom column, tag, tags


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
custom column i need a little help shinken Calibre 3 09-15-2010 03:41 AM
Using Custom Metadata in Save Template EJvdH Calibre 1 07-02-2010 06:06 AM
Accessories Decalgirl Kindle 2 custom skin template srmalloy Amazon Kindle 6 04-09-2010 09:55 PM
Donations for Custom Recipes ddavtian Calibre 5 01-23-2010 04:54 PM
Help understanding custom recipes andersent Calibre 0 12-17-2009 02:37 PM


All times are GMT -4. The time now is 09:22 PM.


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