07-17-2016, 01:41 PM | #1 |
Grand Sorcerer
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 Code:
db = self.gui.current_db my_title = db.new_api.field_for('title', my_bookid) |
07-17-2016, 01:51 PM | #2 |
creator of calibre
Posts: 43,858
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 |
Advert | |
|
07-17-2016, 01:57 PM | #3 |
Grand Sorcerer
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
|
07-17-2016, 02:04 PM | #4 |
Grand Sorcerer
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 Code:
cache = init_cache(sys.argv[1]) # Loop through all the books in the library for id_ in cache.all_book_ids(): ..... |
07-17-2016, 02:49 PM | #5 |
Grand Sorcerer
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. |
Advert | |
|
07-17-2016, 03:17 PM | #6 | ||
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
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. ) |
||
|
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 |