View Single Post
Old 07-04-2014, 10:56 AM   #1
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,648
Karma: 205022288
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Add books programatically from plugin

GUI plugin.

Having trouble getting the parameters right for the add_books() method (database2.py). I'm using advice from an older post to the effect of:

Code:
gui = get_gui()
db = gui.library_view.model().db
db.add_books(...)
I have a file object (PersistentTemporaryFile) representing a valid ePub called "result"

I have a metadata object ('mi'); retrieved using
Code:
mi = get_metadata(result, 'epub')
I'm able to successfully use 'import_book' to add the book:
Code:
db.import_book(mi, [result.name])
with all the correct metadata, so I'm assuming my get_metadata call is working(?), but I can't seem to get the add_books() call to work without the following error:
Spoiler:
Code:
calibre, version 1.40.0
ERROR: Unhandled exception: <b>AttributeError</b>:'str' object has no attribute 'tags'

calibre 1.40  isfrozen: True is64bit: False
Windows-Vista-6.0.6002-SP2 Windows ('32bit', 'WindowsPE')
('Windows', 'Vista', '6.0.6002')
Python 2.7.5
Windows: ('Vista', '6.0.6002', 'SP2', 'Multiprocessor Free')
Traceback (most recent call last):
  File "calibre_plugins.obok_dedrm.dialogs", line 76, in _ok_clicked
  File "site-packages\calibre\gui2\library\models.py", line 306, in add_books
  File "site-packages\calibre\db\legacy.py", line 218, in add_books
  File "site-packages\calibre\db\cache.py", line 1409, in add_books
  File "site-packages\calibre\db\cache.py", line 57, in call_func_with_lock
  File "site-packages\calibre\db\cache.py", line 1363, in create_book_entry
AttributeError: 'str' object has no attribute 'tags'

I can't seem to nail down what is needed in the 'paths' and 'formats' parameters of the add_book() method.

Can someone clue me in to how to pass the correct parameters to the add_books method (based on my file object and my metadata object)?

I'm wanting to use the "add_books" method instead of "import_book" simply because it has the "add_duplicates" flag that I'm assuming that I can set to false in order to prevent adding a duplicate book (or at least honor the library settings for dealing with duplicates). If there's a better way to achieve that, I'm all ears, too.

Thanks in advance
DiapDealer is online now   Reply With Quote