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 05-01-2020, 11:57 PM   #1
dxcore35
Member
dxcore35 began at the beginning.
 
Posts: 22
Karma: 10
Join Date: Mar 2018
Device: Kindle Voyage
Simple plugin reading / writing custom metadata

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.
dxcore35 is offline   Reply With Quote
Old 05-02-2020, 12:39 AM   #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
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.
davidfor is offline   Reply With Quote
Old 05-02-2020, 01:23 AM   #3
dxcore35
Member
dxcore35 began at the beginning.
 
Posts: 22
Karma: 10
Join Date: Mar 2018
Device: Kindle Voyage
Below is function I have trouble with. This is one of the variation of command I tired, but which failed.

Code:
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)
dxcore35 is offline   Reply With Quote
Old 05-02-2020, 03:18 AM   #4
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
Firstly, what is the error?

But, what I actually have problems with:

Code:
{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.
davidfor is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Metadata Source Plugin] Empty Plugin? (Fake Identifier) mneimeyer Plugins 3 11-11-2019 08:07 PM
Write to a custom column from a Metadata Source Plugin thiago.eec Development 12 07-13-2019 04:13 PM
Read custom fields from metadata plugin Manitu80 Development 3 10-26-2016 10:59 PM
Getting custom metadata field in GUI plugin SauliusP. Development 7 02-11-2012 01:31 AM


All times are GMT -4. The time now is 08:49 PM.


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