02-01-2015, 12:07 PM | #1 |
frumious Bandersnatch
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?)
|
02-01-2015, 06:50 PM | #2 |
creator of calibre
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 |
Advert | |
|
02-02-2015, 05:24 AM | #3 |
frumious Bandersnatch
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.
|
02-02-2015, 08:19 AM | #4 | |
Grand Sorcerer
Posts: 11,950
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
You can get all the values for a column using all_field_for() with book_ids == all_book_ids() then inverting the resulting dict. |
|
02-02-2015, 01:38 PM | #5 | |
frumious Bandersnatch
Posts: 7,534
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
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' |
|
Advert | |
|
02-02-2015, 10:38 PM | #6 |
creator of calibre
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) |
02-03-2015, 03:28 AM | #7 |
frumious Bandersnatch
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)
|
02-03-2015, 03:29 AM | #8 |
creator of calibre
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'] |
|
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 |