![]() |
#1 |
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
![]()
Hello,
I'm starting to write a plugin based on the existing example interface_demo_plugin. So far I made some python additions but I'm not sure how to find documentation about the different existing usable classes. Is the documentation located here : https://manual.calibre-ebook.com/plugins.html ? For instance I would like to retrieve the current library name in use, but couldn't find the information (db.something ?) Also I would like to be able to reimport a book file (pdf, cbr...) to an existing book Id record and also an opf file to the same book Id record (or at least chnage record properties (annotations)). Can someone please point me to a good start point. Thank you for helping. ![]() |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
This is a link to calibre's API documentation for the database interface. Maybe you'll find some useful stuff.
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Plugin Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,936
Karma: 4604435
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
|
The nice thing about open source is you can always look at the source.
In this case, new_api is the Cache class in https://github.com/kovidgoyal/calibr...re/db/cache.py It appears to only have library_id and dbpath properties. dbpath contains the library name, but as part of the full abspath to 'metadata.db' for that library. The other approach is to look at the code for something that already has what you want. In this case, the Choose Library action knows about library names. I keep a fork of calibre checkouted and used find grep on 'Switch/create library' to find it in: https://github.com/kovidgoyal/calibr...ose_library.py That action has a method library_name(), which you can call from your plugin as self.gui.iactions['Choose Library'].library_name(), or you can look at the code and find that what it really does it give you the basename of the self.gui.current_db.libary_path. |
![]() |
![]() |
![]() |
#4 |
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
![]()
@JimmXinu
Thank you for your tips. Actually this is what I did more or less and ended with using : class InterfacePlugin(InterfaceAction): and overloading : def library_changed(self, db): To get a LibraryDatabase object. Unfortunately it doesn't seem to have a way to get the name from it. After trying to use the self.gui.iactions method I didn't see before, I added this and it works perfectly. Thank you very much for your help |
![]() |
![]() |
![]() |
#5 |
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
![]()
Hello,
I have tried to find a way to search for a book entry by its id. This needs to happen in the background, no GUI to be shown. Looking at the code it seems its done using search_pool.add_task() with a query like: query['id']. Then results are given through search_pool.get_results(). I'm not sure I can use this and wondering if there is no simpler way. Is there a way to search with id:"123" and get the book object that can be edited (ie change comments?) Thank you in advance for sharing your experience |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Deviser
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
|
self.gui.search.clear()
self.gui.search.set_search_string('id:12345') |
![]() |
![]() |
![]() |
#7 |
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
@DaltonST
I was trying this so far: book_action = Source(None) logger = logging.getLogger('book_actions') abortStatus = None result_queue = Queue() #book_action.identify(logger, result_queue, abortStatus, title=None, authors=None, identifiers={'id':'123'}, timeout=30) popuptext += "Found: "+result_queue.get()+".\n" But it doesn't seem to work. I'll try your suggestion and let you know. |
![]() |
![]() |
![]() |
#8 |
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
@DaltonST
Even if I initially planned to do this without GUI (I don't know if it's feasable) I used your code snippet and it worked as it shows the result in the GUI. Code:
self.gui.search.clear() self.gui.search.set_search_string('id:'+searchId) rows = self.gui.library_view.selectionModel().selectedRows() if not rows or len(rows) == 0: popuptext += "ERROR: No book found for id: "+searchId+"\n" elif len(rows) > 1: popuptext += "ERROR: multiple books found for id: "+searchId+"\n" else: popuptext += "Found 1 matching row ID " + str(list(map(self.gui.library_view.model().id, rows))[0]) + "\n" Next step is to be able to change the metadata from an external opf file (on disk) or from field values in it. I guess I need to use Code:
self.gui.iactions['Edit Metadata'].paste_metadata() There is a download_metadata() method, but no upload_metadata(). Do you recommend to overload this class and create an upload_metadata(opf_file) or is there an existing/better way (I haven't found so far)? |
![]() |
![]() |
![]() |
#9 | |
Deviser
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
|
Quote:
Use AstroGrep for Windows to search Calibre's source code to see how it does things. You appear to be overworking things. Do what Calibre does in the same situation. Also, a moderator should have moved your thread to the Development subforum many posts ago. DaltonST Last edited by DaltonST; 12-22-2020 at 11:42 AM. |
|
![]() |
![]() |
![]() |
#10 | |
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
Quote:
So I can try to mimic what Calibre does via the GUI. AFAIK there is no opf import, so I need to import metadata values one by one. |
|
![]() |
![]() |
![]() |
#11 |
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
![]()
Hi all,
This is following thread: Calibre > Plugins > Reload this Page New to plugin: need help on reference guide Which should be moved here as DaltonST suggests. I would like to update the metadata field values from a modifed exported opf file. I don't feel I can reimport that opf as a single import/update. I can parse it and update fields one by one. I'm not sure how to access the resources probably with something like: Code:
self.gui.iactions['Edit Metadata'].edit_metadata().... What do you recommend ? Thank you |
![]() |
![]() |
![]() |
#12 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,409
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#13 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,409
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Also, calibre.db.cache.get_metadata() returns the metadata for a given book id. You can get a db object using gui.library_view.model().db, which gives you access to the methods in db.legacy. You probably want to use gui.library_view.model().db.new_api so you can use the newer methods in db.cache. |
|
![]() |
![]() |
![]() |
#14 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,409
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
|
|
![]() |
![]() |
![]() |
#15 | |
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
Quote:
in ../calibre-src/src/calibre/ebooks/oeb/polish/main.py. It looks like it will do the job. But how can I get the book/container object from the current GUI selection ? |
|
![]() |
![]() |
![]() |
Tags |
plugin development |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
TOC reference in Guide section of OPF fails | Jeff L | Calibre | 0 | 10-20-2011 04:04 AM |
Multiple reference elements with the same type in the <guide> | Valloric | ePub | 8 | 04-25-2010 11:18 AM |
Adding a <reference> item to <guide> in OPF file | GRiker | Sigil | 2 | 04-12-2010 01:06 PM |
Reference Guide: How to Prepare Images for EPUB (and other) Formats | Zorba | ePub | 13 | 11-22-2009 08:28 AM |
Free PDF: Ubuntu Pocket Guide and Reference | TadW | Deals and Resources (No Self-Promotion or Affiliate Links) | 4 | 01-30-2009 11:22 PM |