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 12-16-2020, 05:15 PM   #1
chris33
Enthusiast
chris33 began at the beginning.
 
Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
Lightbulb New to plugin: need help on reference guide

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.
chris33 is offline   Reply With Quote
Old 12-16-2020, 05:55 PM   #2
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,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.
jackie_w is offline   Reply With Quote
Advert
Old 12-16-2020, 08:38 PM   #3
JimmXinu
Plugin Developer
JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.
 
JimmXinu's Avatar
 
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.
JimmXinu is offline   Reply With Quote
Old 12-19-2020, 12:48 PM   #4
chris33
Enthusiast
chris33 began at the beginning.
 
Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
Thumbs up

@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
chris33 is offline   Reply With Quote
Old 12-21-2020, 12:21 PM   #5
chris33
Enthusiast
chris33 began at the beginning.
 
Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
Question

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
chris33 is offline   Reply With Quote
Advert
Old 12-21-2020, 01:07 PM   #6
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
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')
DaltonST is offline   Reply With Quote
Old 12-21-2020, 04:50 PM   #7
chris33
Enthusiast
chris33 began at the beginning.
 
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.
chris33 is offline   Reply With Quote
Old 12-22-2020, 10:50 AM   #8
chris33
Enthusiast
chris33 began at the beginning.
 
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"
Last line returns the book id as expected in searchId.
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()
But data needs to be copied first and copy_metadata() copies from a selected book entry.
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)?
chris33 is offline   Reply With Quote
Old 12-22-2020, 11:31 AM   #9
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
Quote:
Even if I initially planned to do this without GUI (I don't know if it's feasable)
Are you doing a GUI Plugin or some other type of plugin? That will determine what and how you do things.

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.
DaltonST is offline   Reply With Quote
Old 12-22-2020, 12:24 PM   #10
chris33
Enthusiast
chris33 began at the beginning.
 
Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
Quote:
Originally Posted by DaltonST View Post
Are you doing a GUI Plugin or some other type of plugin? That will determine what and how you do things.

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
Actually I based my plugin on the interface_demo_plugin code.
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.
chris33 is offline   Reply With Quote
Old 12-22-2020, 12:46 PM   #11
chris33
Enthusiast
chris33 began at the beginning.
 
Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
Question Help on modifying metadata

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()....
but cannot put a hand on the fields.

What do you recommend ?
Thank you
chris33 is offline   Reply With Quote
Old 12-22-2020, 01:49 PM   #12
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: 12,409
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by DaltonST View Post
Also, a moderator should have moved your thread to the Development subforum many posts ago.
Moderator Notice
Moved to Development forum
chaley is offline   Reply With Quote
Old 12-22-2020, 01:55 PM   #13
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: 12,409
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by chris33 View Post
AFAIK there is no opf import, so I need to import metadata values one by one.
Does calibre.ebooks.metadata.opf.set_metadata do what you want?

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.
chaley is offline   Reply With Quote
Old 12-22-2020, 04:36 PM   #14
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: 12,409
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by chris33 View Post
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()....
but cannot put a hand on the fields.

What do you recommend ?
Thank you
Does calibre.db.cache.set_field() (gui.library_view.model().db.new_api.set_field()) do what you want?
chaley is offline   Reply With Quote
Old 12-23-2020, 09:52 AM   #15
chris33
Enthusiast
chris33 began at the beginning.
 
Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
Quote:
Originally Posted by chaley View Post
Does calibre.ebooks.metadata.opf.set_metadata do what you want?

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.
It sounds good. I guess I can reuse the code found in function update_metadata
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 ?
chris33 is offline   Reply With Quote
Reply

Tags
plugin development


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 07:08 AM.


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