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 02-01-2015, 12:07 PM   #1
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,534
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Can I access the database from a metadata source plugin?

I know this is not the intended use for a metadata source plugin, but I'd like a plugin to pick up information from a custom column in the database. The identifier I rely on should be unique in the database, so in the "identify" method I can easily select the book record to get information from... if I can access the calibre database. (Any fast and easy way to get a book id from an identifier other than a search, too?)
Jellby is offline   Reply With Quote
Old 02-01-2015, 06:50 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: 44,391
Karma: 23798586
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You really should not be doing that. It is unsupported and quite likely to break in future versions, but if you really, really want to:

from calibre.gui2.ui import get_gui

db = get_gui().current_db.new_api

Of course, this will break in horrible ways if someone runs the fetch-ebook-metadata command line tool to download metadata without a GUI
kovidgoyal is offline   Reply With Quote
Advert
Old 02-02-2015, 05:24 AM   #3
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,534
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Thanks. This is only intended for internal management of the MR library, so it will not be published. I expect the database access can be tested and gracefully fail if it cannot be found.
Jellby is offline   Reply With Quote
Old 02-02-2015, 08:19 AM   #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,950
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Jellby View Post
(Any fast and easy way to get a book id from an identifier other than a search, too?)
If you are doing many books at one time then I would consider getting all these "identifiers" and storing them in a dict with identifier as key and the book id as data. It might even be faster to do this even if you are doing only two or three books, given that search must scan all the records.

You can get all the values for a column using all_field_for() with book_ids == all_book_ids() then inverting the resulting dict.
chaley is offline   Reply With Quote
Old 02-02-2015, 01:38 PM   #5
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,534
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Quote:
Originally Posted by kovidgoyal View Post
from calibre.gui2.ui import get_gui

db = get_gui().current_db.new_api
I put these inside the "identify" method of the plugin, and when I call it (using the download metadata button in the GUI) I get:

Code:
Traceback (most recent call last):
  File "site-packages/calibre/ebooks/metadata/sources/identify.py", line 44, in run
  File "calibre_plugins.dummy1.__init__", line 53, in identify
AttributeError: 'NoneType' object has no attribute 'current_db'
and of course "get_gui()" returns "None".
Jellby is offline   Reply With Quote
Advert
Old 02-02-2015, 10:38 PM   #6
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: 44,391
Karma: 23798586
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Yes, in the identify() method it wont work, since that is run in a worker process. Because of your previous questions, I somewhat sloppily assumed you meant the url_from_identifier() method.

You can just directly read for the database, with something like this,

Code:
import apsw
conn = apsw.Connection('/path/to/calibre/metadata.db', apsw.SQLITE_OPEN_READONLY)
apsw is multi-process/thread safe so it should be fine.
kovidgoyal is offline   Reply With Quote
Old 02-03-2015, 03:28 AM   #7
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,534
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
I must hardcode the library path then? I hoped I could get it from the GUI (at least in the cases where the method is triggered from the GUI)
Jellby is offline   Reply With Quote
Old 02-03-2015, 03:29 AM   #8
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: 44,391
Karma: 23798586
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
from calibre.utils.config import prefs
library_path = prefs['library_path']
kovidgoyal is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Metadata Source Plugin] BOL.com (DE) Pr.BarnArt Plugins 52 06-01-2023 04:50 PM
[Metadata Source Plugin] Amazon.CN fated Plugins 0 11-20-2014 04:59 PM
[Metadata Source Plugin] catawiki drMerry Plugins 0 06-28-2011 08:42 PM
[Metadata Source Plugin] Amazon.it nandocuci Plugins 2 05-18-2011 02:36 AM
Update Metadata in database from Plugin DokaMax Plugins 0 05-22-2010 05:58 AM


All times are GMT -4. The time now is 02:04 PM.


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