Simple plugin reading / writing custom metadata
#1  dxcore35 05-01-2020, 11:57 PM
Hello friends,

I spend few hours researching API, and reverse engineer the code from other plugins. But Im unable to recreate simple plugin for bulk editing of multiple files and reading and writing CUSTOM METADATA FILED. There is always some error when writing this metadata....

Can somebody post complete code for archiving this? The code can be well posted in User manual: Writing your own plugins to extend calibre’s functionality.

#2  davidfor 05-02-2020, 12:39 AM
I'll go the other way and suggest you post your code and the error. If I was to post code to do this, I'd just be posting a copy of the code in one of the plugins that you probably looked at.

If you want to look at a plugin, I suggest looking at Count Pages. From memory, it is up to date with the best way to update a custom column.

#3  dxcore35 05-02-2020, 01:23 AM
Below is function I have trouble with. This is one of the variation of command I tired, but which failed.

def _do_add_custom_text (self, book_ids):	from calibre.utils.html2text import html2text # Queue all the books and kick off the job dbA = self.gui.current_db db = self.gui.current_db.new_api cust_col_name = "#summarize" for id in book_ids: miA = dbA.get_metadata (id, index_is_id=True, get_cover=False) summary_text_old = miA.get (cust_col_name)	text_to_write = "WRITING THIS TEXT"	text_to_write = text_to_write.decode('utf-8')	lis_aux_id.append (text_to_write) dbA.new_api.set_field(cust_col_name, {id:id_aux[id] for id in lis_aux_id}) self.gui.iactions['Edit Metadata'].refresh_gui(book_ids, covers_changed=False)

#4  davidfor 05-02-2020, 03:18 AM
Firstly, what is the error?

But, what I actually have problems with:

{id:id_aux[id] for id in lis_aux_id}
Firstly, I can't see where and hence what "id_aux".

Then, "lis_aux_id" appears to be a list of strings. It was created in the loop immediately above with append. It looks like it is just a collection of the string "WRITING THIS TEXT" which doesn't make sense to use it as an index above.

And there are some indentation problems. Mixing tabs and spaces can work in Python 2, but, isn't valid in Python 3. And personally, I find it confuses things enough so that I'm not exactly sure what is at what level of indentation above.

The calibre related stuff seems to be correct. It matches with what I have used.

It would probably easiest if you post the plugin. That gives the full context. And we can run it if we want to.

Today's Posts | Search this Thread | Login | Register