![]() |
#1 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
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) |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,345
Karma: 27182818
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 | |
|
![]() |
#3 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
I didn't realise that. That makes life much easier. Thanks
![]() |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,444
Karma: 8012886
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(): ..... |
![]() |
![]() |
![]() |
#5 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
@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 | |
|
![]() |
#6 | ||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,444
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
![]() ![]() |
||
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[GUI Plugin] Zotero Metadata Importer | DaltonST | Plugins | 295 | 03-22-2025 09:47 AM |
[GUI Plugin] Consolidate All Library Metadata (CALM) | DaltonST | Plugins | 334 | 02-02-2025 02:28 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 |