Mobileread
Edit epub2 .opf file through calibre plug-in...?
#1  carmenchu 05-05-2020, 05:04 AM
I wish to know if it is possible to do the following modifications to the <metadata> section of content.opf through a calibre plug-in, to be run automatically after conversion and/or
polish book -> update metadata in book file

1. retrieve the 'value' (integer) from field #custom_date and
* add it as <dc:date opf:event="creation">'value'</dc:date>
* delete any existing <dc:date>...</dc:date> (no opf:event)

2. for all existing <dc:subject>...</dc:subject>, coming from my calibre tags or already in the original epub:
* if of the form <dc:subject>[item_in_list1]</dc:subject>, change to <dc:source>item_in_list1</dc:source>
* delete the rest if not of the form <dc:subject>item_in_list2</dc:subject> (my genres)

3. delete all <<meta name="calibre:user_ .../>

I am currently doing this through a (personal) sigil plug-in: chiefly a magnified search&replace along the beautiful soup 'meta tag', but I cannot see how to do the same 'at source' in calibre.
The 'mi' object doesn't seem to provide the ability to substitute/delete <tag>...</tag>, and I haven't seen in the documentation any other way likely to work.

Any help would be appreciated--even if it is on the lines 'you cannot do that'.
Reply 

#2  JSWolf 05-05-2020, 07:28 AM
There is no plugin to do all this. But you can do it all manually using Calibre's eBook editor.
Reply 

#3  carmenchu 05-06-2020, 04:28 AM
Of course there isn't such a plugin--that's why I ask for help towards making one.
As I make those changes to every single book, I am slightly feed up with the manual procedure--thus the sigil plugin, which already works--and the wish for a calibre one, which I hoped would be simpler, besides avoiding fishing among 'calibre:user_...' tags and providing for changes between old/new conversions (I have spotted already two different ways in which my custom field gets into the .opf file).
My notion was rather to get the fields/tags values directly from calibre and fit them into the opf meta, deleting all the information I don't want in the epub--a kind of 'customized polishing', in fact.
Very grateful for any hints...
Reply 

#4  kovidgoyal 05-06-2020, 05:30 AM
Look at the quality check plug in for an example of modifying epub files in bulk.
Reply 

#5  carmenchu 05-06-2020, 07:42 AM
Quote kovidgoyal
Look at the quality check plug in for an example of modifying epub files in bulk.
Thanks! Looking into it.
BTW, I assume you mean the 'Modify epub' plugin?
Reply 

#6  kovidgoyal 05-06-2020, 09:37 AM
IIRC both do modifications to EPUB but yeah modify epub is probably a better place to start
Reply 

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