View Single Post
Old 09-08-2024, 06:18 AM   #1
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,730
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
Bulk updating metadata from a plugin?

Hi - I'm looking at some (ancient) code in the Extract ISBN plugin.

The code just wants to update a batch of books to set the .isbn property of the Metadata. For reasons I have long since got no idea on (likely written 12+ years ago), the code appears to steal some behaviour from the Edit Metadata plugin back then. It currently looks like this:

Code:
        # At this point we want to re-use code in edit_metadata to go ahead and
        # apply the changes. So we will replace the Metadata objects with some
        # empty ones with only the isbn field set so only that field gets updated
        id_map = {}
        for i, title, last_modified, isbn in extracted_ids:
            mi = Metadata(_('Unknown'))
            mi.isbn = isbn
            id_map[i] = mi
        edit_metadata_action = self.gui.iactions['Edit Metadata']
        edit_metadata_action.apply_metadata_changes(id_map,
                                                    callback=self._mark_and_display_results)
As you can see fairly straightforward of only setting one property on the Metadata object and relying on magic inside apply_metadata_changes() to ensure only that property gets updated on the books.

It is entirely possibly that in "current" calibre this is a terrible approach and there is a better way of doing this. Thoughts/suggestions welcomed - it still seems to work perfectly fine for me but two users now are saying their titles are being reset to "unknown". I havent touched any of this code, the only change my latest plugin release made is to increase the likelihood of an ISBN being found (which would then invoke this code)...

Last edited by kiwidude; 09-08-2024 at 06:20 AM.
kiwidude is offline   Reply With Quote