Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 03-28-2016, 08:28 AM   #736
JJanssen
Member
JJanssen began at the beginning.
 
Posts: 16
Karma: 24
Join Date: Jun 2009
Device: Kindle Paperwhite 1
Quote:
Originally Posted by eschwartz View Post
Sure.
It's a trick I saw used elsewhere, which makes for much more reusable code (and which I should've used back when someone was having a lot of trouble editing an attached python script ).
I've changed the bits around a little. It now uses the current library as the default, but you can also pass it an explicit path if you want to.
Code:
def init_cache(library_path = None):
	from calibre.db.backend import DB
	from calibre.db.cache import Cache
	from calibre.utils.config import prefs
	if library_path == None:
		library_path = prefs['library_path']
	backend = DB(library_path)
	cache = Cache(backend)
	cache.init()
	return cache

cache = init_cache()
#cache = init_cache('/Users/jasper/Documents/Calibre Main Library/')
#cache = init_cache(library_path = '/Users/jasper/Documents/Calibre Test Library/')
#
# The parameter can be empty, for the currently opened library, 
# or you can pass a specific Library's path if you wish.
#
#-------------------- Usage specific code starts here ------------------

import math
from collections import defaultdict

series_info = defaultdict(dict)
fract_ids = []
[.... etc ....]
Putting the prefs import inside the init_cache function is just more elegant, to my mind, and it also makes the thing even more reusable/readable. Putting the imports for math and defaultdict after the initialisation of the cache object is not *strictly* Python best practice, but in this case I think it's warranted because those are imports for the specific code we're writing in this go-around, and when ordered like this, everything up to line 19 is a straight copy/paste over to any script that wants to work with a calibre DB.

Last edited by JJanssen; 03-28-2016 at 08:31 AM.
JJanssen is offline   Reply With Quote
Old 04-20-2016, 07:38 PM   #737
saluli
Connoisseur
saluli began at the beginning.
 
Posts: 55
Karma: 10
Join Date: Jul 2015
Location: Curitiba - Brazil
Device: Kindle Paperwhite 3,
Question Adding brackets and pharenteses

Hi! I am testing how to make a plugboard that results in something like this:

When there is a series:
[CUSTOMCOLUMN] (series [01]) - Title

When there is no series
[CUSTOMCOLUMN] - Title


But I am not sure how to do it.

For now, I managed to get
customcolumn - series [01] - Title
and
customcolunm - Title,
using
{#customcolumn} - {series}{series_index:0>2s| [|] - }{}{title}

What can I change to get my Uppercase and put the brackets and parentheses where I want them?

Last edited by saluli; 04-20-2016 at 07:42 PM. Reason: better formating
saluli is offline   Reply With Quote
Advert
Old 04-20-2016, 09:28 PM   #738
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)
Code:
[{#customcolumn:uppercase()}]{series:| (|}{series_index:0>2s| [|])} - {title}
eschwartz is offline   Reply With Quote
Old 04-22-2016, 08:48 AM   #739
amely
Junior Member
amely began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Oct 2015
Device: none
save to disk and switching templates for it

hi

I searched forum and read this whole thread and even though question was asked few times but answers aren't really what I need.

when saving to disk if series index has decimal point (I don't know technical term) I need to switch to different template to save it the way I like or to rename when saved.

How I like series to look is series 01 , series 02 , series 02.10 etc...

to achieve that I use
Code:
{authors}/{series}/{authors} - {series} {series_index:0>2s|   | - }{title}
for regular numbers
and
Code:
{authors}/{series}/{authors} - {series} {series_index:0>5.2f|   | - }{title}
for decimal ones.


Is there a way to tell calibre to recognise that series index has decimal point and to use second template?

I don't know if it is possible nor how to write that command so any help would be appreciated, even if it is just to say it isn't possible at all.

amely is offline   Reply With Quote
Old 04-22-2016, 09:24 AM   #740
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,728
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by amely View Post
hi

I searched forum and read this whole thread and even though question was asked few times but answers aren't really what I need.

when saving to disk if series index has decimal point (I don't know technical term) I need to switch to different template to save it the way I like or to rename when saved.

How I like series to look is series 01 , series 02 , series 02.10 etc...

to achieve that I use
Code:
{authors}/{series}/{authors} - {series} {series_index:0>2s|   | - }{title}
for regular numbers
and
Code:
{authors}/{series}/{authors} - {series} {series_index:0>5.2f|   | - }{title}
for decimal ones.


Is there a way to tell calibre to recognise that series index has decimal point and to use second template?

I don't know if it is possible nor how to write that command so any help would be appreciated, even if it is just to say it isn't possible at all.

Post 550 gives you the clue -- how to determine if a number (a series index) is an integer or has a decimal point. However, after some thought I came up with a more efficient way to do it. Here is an example template in General Program Mode:
Code:
program:
	no_decimal = template('{authors}/{series}/{authors} - {series} {series_index:0>2s|   | - }{title}');
	has_decimal = template('{authors}/{series}/{authors} - {series} {series_index:0>5.2f|   | - }{title}');
	contains(
		field('series_index'),
		'\.',
		has_decimal, 
		no_decimal)
chaley is offline   Reply With Quote
Advert
Old 04-22-2016, 11:38 AM   #741
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)
chaley,

The simple answer is always the one we don't see.
Does it contain a period.
eschwartz is offline   Reply With Quote
Old 04-22-2016, 01:49 PM   #742
amely
Junior Member
amely began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Oct 2015
Device: none
Quote:
Originally Posted by chaley View Post
Post 550 gives you the clue -- how to determine if a number (a series index) is an integer or has a decimal point. However, after some thought I came up with a more efficient way to do it. Here is an example template in General Program Mode:
Code:
program:
	no_decimal = template('{authors}/{series}/{authors} - {series} {series_index:0>2s|   | - }{title}');
	has_decimal = template('{authors}/{series}/{authors} - {series} {series_index:0>5.2f|   | - }{title}');
	contains(
		field('series_index'),
		'\.',
		has_decimal, 
		no_decimal)

I'm sorry I missed it, I'll concentrate better next time when reading
I'm grateful you took time to make this more efficient way
amely is offline   Reply With Quote
Old 07-28-2016, 03:08 AM   #743
Penny_Dreadful
She/Her
Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.
 
Penny_Dreadful's Avatar
 
Posts: 86
Karma: 142774
Join Date: Aug 2009
Location: Perth, Australia
Device: Kindle PW5 (G001PX) PW3 PW1
Custom Column for Amazon Identifier

I want to make a custom column that will show an icon when the amazon identifier is a Kindle ASIN which is 10 characters starting with "B" eg. amazon:B018E7HFDA or amazon:B01ARSC61U but not amazon:0451460715 or when there is no amazon identifier.

Thanks for any help
Penny_Dreadful is offline   Reply With Quote
Old 07-29-2016, 01:38 AM   #744
Penny_Dreadful
She/Her
Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.
 
Penny_Dreadful's Avatar
 
Posts: 86
Karma: 142774
Join Date: Aug 2009
Location: Perth, Australia
Device: Kindle PW5 (G001PX) PW3 PW1
I've got as far as this
Code:
program: test(select(field('identifiers'),'amazon'),'1 ','')
which is how my goodreads identifier column works, but it's a simple yes or no query, either there is a goodreads identifier (an icon appears) or there isn't. It's the next bit, where I think I'll need a regex where I'm stumped.
Penny_Dreadful is offline   Reply With Quote
Old 07-29-2016, 07:43 AM   #745
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,728
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Penny_Dreadful View Post
I've got as far as this
Code:
program: test(select(field('identifiers'),'amazon'),'1 ','')
which is how my goodreads identifier column works, but it's a simple yes or no query, either there is a goodreads identifier (an icon appears) or there isn't. It's the next bit, where I think I'll need a regex where I'm stumped.
Use an advanced column icon rule so you can use a GPM template. Here is one rule (template) that adds a wizard wand icon to the title column if an identifier matches my understanding of the pattern you specify. It uses re_group in an odd way to return a value only if the pattern matches.

You can of course put everything onto one line, making the select the first parameter to re_group. I didn't because assigning to "a" doesn't cost much (if anything) and makes the template much more readable.
Attached Thumbnails
Click image for larger version

Name:	Clipboard01.jpg
Views:	435
Size:	51.5 KB
ID:	150570  
chaley is offline   Reply With Quote
Old 07-30-2016, 12:40 AM   #746
Penny_Dreadful
She/Her
Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.Penny_Dreadful is my North, my South, my East and West.
 
Penny_Dreadful's Avatar
 
Posts: 86
Karma: 142774
Join Date: Aug 2009
Location: Perth, Australia
Device: Kindle PW5 (G001PX) PW3 PW1
Thank you so much, this is perfect!
Penny_Dreadful is offline   Reply With Quote
Old 08-15-2016, 04:19 AM   #747
Schuhsohle
Junior Member
Schuhsohle began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Aug 2016
Device: Kindle Paperwhite (1st Edition)
Hi i am new to the organisation with Calibre and i need some advice to get some custom columns to work.

i want two custom colums on the top so i can sort my ebook to this preference.
Spoiler:


The first column should be the reading order like 1, 2, 3 . . .etc.
and the second should be the time where the story plays.
Spoiler:


so i dont know what i have to put in the spaces for the creation of an custom column to get this working.
oh and there are two different times XXXVSY and XXXNSY with NSY comes after VSY (it is the Timeline from Star Wars in German like BBY(Before the Battle of Yavin) and ABY (After the Battle of Yavin))

Spoiler:


I hope someone can help me

sorry for my bad english
Schuhsohle is offline   Reply With Quote
Old 08-25-2016, 03:02 PM   #748
famewolf
Member
famewolf began at the beginning.
 
Posts: 12
Karma: 10
Join Date: Jan 2013
Device: Kindle Paperwhite (10th Gen)
I have read and attempted various posts/tutorials on how to get the series and book number into the title for my kindle paperwhite. I have created a metadata plugboard specifying ANY Format (originally just mobi) for device KINDLE2 (which is what calibre tells me is connected when I plug my kindle paperwhite up) with the following being used for title: {series}{series_index:0>2s| – | – }{title}

However when I view the book on the device and in calibre's device view the series info is not present.

Any suggestions?
famewolf is offline   Reply With Quote
Old 08-25-2016, 03:50 PM   #749
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)
Plugboards are not supported for dual-MOBI ebooks. Make sure you are converting to AZW3.
eschwartz is offline   Reply With Quote
Old 08-25-2016, 05:44 PM   #750
famewolf
Member
famewolf began at the beginning.
 
Posts: 12
Karma: 10
Join Date: Jan 2013
Device: Kindle Paperwhite (10th Gen)
Quote:
Originally Posted by eschwartz View Post
Plugboards are not supported for dual-MOBI ebooks. Make sure you are converting to AZW3.
Thanks for the reply. I tried opening one of the books in question on the kindle and it told me it wasn't there even though I had sent it and it was displaying so I rebooted the kindle...when I did, all the files were displaying the way they should so I'll just write this one off as a gremlin.

Can you or anyone else suggest the best filter to use to get author, title, series and series # displayed? I ask because some books with long titles are scrolling off the screen when at the end. Perhaps it should be Book #, Book title, author, series?
famewolf is offline   Reply With Quote
Reply

Tags
custom column, tag, tags

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 02:21 AM.


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