Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 07-17-2016, 01:41 PM   #1
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
Querying Metadata from outside the GUI?

I'd like to understand the calibre metadata structure better. If I know the path/to/library and a book's id within that library, is it possible to access metadata (read only) via a simple script using the Windows commandline method:
Code:
calibre-debug path/to/myscript.py
I've used some commands under the GUI in plugins, e.g.
Code:
db = self.gui.current_db
my_title = db.new_api.field_for('title', my_bookid)
but I don't know how to use those in a simple script.
jackie_w is offline   Reply With Quote
Old 07-17-2016, 01:51 PM   #2
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,857
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You can always load a db, like this:

from calibre.library import db

db = db('path/to/library/folder')

that will give you the same object as gui.current_db
kovidgoyal is online now   Reply With Quote
Advert
Old 07-17-2016, 01:57 PM   #3
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
I didn't realise that. That makes life much easier. Thanks
jackie_w is offline   Reply With Quote
Old 07-17-2016, 02:04 PM   #4
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
@jackie_w: if you normally use the new DB interface then you can get a new db handle with something like the following function
Code:
def init_cache(library_path):
	from calibre.db.backend import DB
	from calibre.db.cache import Cache
	backend = DB(library_path)
	cache = Cache(backend)
	cache.init()
	return cache
You would use it in some way like the following, of course depending on what you are doing
Code:
cache = init_cache(sys.argv[1])

# Loop through all the books in the library
for id_ in cache.all_book_ids():
    .....
chaley is offline   Reply With Quote
Old 07-17-2016, 02:49 PM   #5
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
@chaley,

Thanks for the info - I'll squirrel it away. At the moment I'm just interested in seeing what fields/methods are available for querying metadata for a single book in the database.

It all came about because I wanted to tweak the Count Pages plugin more to my liking and I realised I didn't really have a clue about the metadata processing in there. FWIW it turns out I didn't really need to know much to achieve what I wanted ... but now I'm aware of my ignorance I feel the need to do something about it

P.S. Hope you're well. France seems to be having some bad times recently.
jackie_w is offline   Reply With Quote
Advert
Old 07-17-2016, 03:17 PM   #6
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 jackie_w View Post
@chaley,

Thanks for the info - I'll squirrel it away. At the moment I'm just interested in seeing what fields/methods are available for querying metadata for a single book in the database.
Take a look at get_metadata(), or my preferred method get_proxy_metadata(). These give you an MI object containing all the metadata for a given book, including custom columns. The "proxy" method is nice because it only fetches the metadata when you ask for it, something that can help with performance if you don't care about composite custom columns.
Quote:
P.S. Hope you're well. France seems to be having some bad times recently.
Thanks for the good wishes. Yes, we are. Yesterday for the first time my wife hesitated before going out to shop at the street market.

But then, so is the UK, what with brexit. I know I shouldn't get into this here, but BoJo as foreign secretary? Really? (No need to answer. )
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[GUI Plugin] Consolidate All Library Metadata (CALM) DaltonST Plugins 333 12-15-2023 08:40 PM
[GUI Plugin] Zotero Metadata Importer DaltonST Plugins 291 08-07-2023 12:38 PM
GUI Ideas for ePub3 MetaData Editor KevinH Sigil 3 12-02-2015 01:58 PM
Getting custom metadata field in GUI plugin SauliusP. Development 7 02-11-2012 01:31 AM
Problem updating metadata (using mobi2mobi command line and gui) whitearrow Kindle Formats 3 12-05-2009 07:07 PM


All times are GMT -4. The time now is 12:56 AM.


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