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 10-21-2018, 07:39 PM   #1
Einix
Junior Member
Einix began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Oct 2018
Device: Moonreader+
Problems with Plugin Demo

Hi all,
I am using calibre for a while now. Love it, Thanks for all the good work. Also thanks for the many plugins.
There are a few things I would like to get done. So I looked into the plugin development. Downloaded the demo code. And voila: It didn't work ?
I tried the simple hello_world __init__.py demo, it seems to update the publisher temporarily, but some doesn't save it permanently.

Then I tried the interface demo. Same effect here.
I added some prints for debugging, I am running under Linux, I changed the demo:

def update_title(self):
'''
Set the metadata in the files in the selected book's record to
match the current metadata in the database.
'''
from calibre.ebooks.metadata.meta import set_metadata, get_metadata
from calibre.gui2 import error_dialog, info_dialog

# Get currently selected books
rows = self.gui.library_view.selectionModel().selectedRow s()
if not rows or len(rows) == 0:
return error_dialog(self.gui, 'Cannot update metadata', 'No books selected', show=True)
# Map the rows to book ids
ids = list(map(self.gui.library_view.model().id, rows))
db = self.db.new_api
for book_id in ids:
# Get the current metadata for this book from the db
mi = db.get_metadata(book_id, get_cover=True, cover_as_data=True)
fmts = db.formats(book_id)
if not fmts:
continue
for fmt in fmts:
# Get a python file object for the format. This will be either
# an in memory file or a temporary on disk file
ffile = db.format(book_id, fmt, as_file=True)
ffile.seek(0)
print ("Original Publisher: ", mi.publisher)


#change value
mi.publisher = "Test Publisher"

# Set metadata in the format
set_metadata(ffile, mi, fmt)
ffile.seek(0)
print ("Updated Publisher: ", mi.publisher)

# Now replace the file in the calibre library with the updated
# file. We dont use add_format_with_hooks as the hooks were
# already run when the file was first added to calibre.
db.add_format(book_id, fmt, ffile, run_hooks=False)

print ("Refreshed Publisher: ", mi.publisher)

info_dialog(self, 'Updated files', 'Updated the metadata in the files of %d book(s)'%len(ids), show=True)

the debug output is:
einix@Eva:~/workspace/interface_demo_plugin> calibre-customize -b . & calibre-debug -g
[1] 20151
calibre 3.27.1 embedded-python: False is64bit: True
Linux-4.12.14-lp150.12.22-default-x86_64-with-glibc2.2.5 Linux ('64bit', '')
('Linux', '4.12.14-lp150.12.22-default', '#1 SMP Sat Oct 13 05:05:16 UTC 2018 (09415e8)')
Python 2.7.14
Linux: ('', '', '')
Interface language: en_GB
Plugin updated: Interface Plugin Demo (1, 0, 0)
Successfully initialized third party plugins: Quality Check (1, 9, 11) && EpubSplit (2, 4, 0) && Interface Plugin Demo (1, 0, 0) && Find Duplicates (1, 6, 3)
Not controlling automatic hidpi scaling
devicePixelRatio: 1.0
logicalDpi: 96.3794466403 x 96.4556962025
physicalDpi: 93.7846153846 x 95.25
Using calibre Qt style: True
[0.00] Starting up...
[0.03] Showing splash screen...
[2.06] splash screen shown
[2.06] Initializing db...
[2.08] db initialized
[2.08] Constructing main UI...
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Looking for desktop notifier support from: org.freedesktop.Notifications
org.freedesktop.Notifications found in 0.0 seconds
[4.76] main UI initialized...
[4.76] Hiding splash screen
[5.11] splash screen hidden
[5.11] Started up in 5.11 seconds with 1 books

"First run"
Original Publisher: Blackmore Dennett
Updated Publisher: Test Publisher
Refreshed Publisher: Test Publisher
Original Publisher: Test Publisher
Updated Publisher: Test Publisher
Refreshed Publisher: Test Publisher

Also why would the print be repeated twice?

"and if I press the button again":

Original Publisher: Blackmore Dennett
Updated Publisher: Test Publisher
Refreshed Publisher: Test Publisher
Original Publisher: Test Publisher
Updated Publisher: Test Publisher
Refreshed Publisher: Test Publisher

So it reads the old metadata back, not the new one? Is there any switch I need to flip to get changes actually written?
And would that write to the opf file or the database? (I checked both no updates)
Thanks guys
Einix is offline   Reply With Quote
Old 10-21-2018, 08:48 PM   #2
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Your code is reading the publisher from the database. Then it is writing the publisher to the actual book file. The second time you run it, it does the same thing. Nothing in there has updated the database that calibre uses for the interface. You probably should be writing to the database with "db.get_metadata". That mirrors how you got the publisher. You then have to decide whether to embed the changes in the formats.

And the reason you are seeing it twice is that you are looping over the formats available for that book. The book must have two formats for this to happen. And "Original Publisher" changes from one loop to the next as you are not fetching it at the start of the loop.

It might be a good idea to state what you are trying to do. From this, I don't know if you are trying to update the metadata in the library, or put it in the actual file.
davidfor is offline   Reply With Quote
Advert
Old 10-21-2018, 10:48 PM   #3
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 20,553
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Moderator Notice
This appears to be a Development Issue

BR
BetterRed is offline   Reply With Quote
Old 10-23-2018, 02:31 AM   #4
Einix
Junior Member
Einix began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Oct 2018
Device: Moonreader+
Thanks davidfor

Cheers mate,

I got it running. Your explanation is much better than the demo code.
Maybe those examples should be updated ;-)
Einix is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with Plugin Demo Einix Introduce Yourself 1 10-19-2018 10:23 PM
Kindle Fire Demo Unit...Remove Demo 'Software'? JayOf72 Kindle Fire 23 11-11-2016 09:41 PM
Got a Demo Kindle (k5) from work, need to remove demo software. Stea1th Kindle Developer's Corner 71 09-02-2014 02:46 PM
Demo Kindle Keyboard USB Problems tommytomtom Kindle Developer's Corner 1 01-25-2013 03:42 AM
Problems with MobiDeDrm 0.16 plugin boothy Plugins 4 08-30-2010 08:48 AM


All times are GMT -4. The time now is 03:22 PM.


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