MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   Writing to the content.opf (https://www.mobileread.com/forums/showthread.php?t=264763)

CalibUser 09-02-2015 05:18 PM

Writing to the content.opf
 
I want to correct errors that sometimes occur in the content.opf file. I can read this file using bk.readotherfile("OEBPS/content.opf"). However, I cannot write to this file using bk.writeotherfile("OEBPS/content.opf", opf2) where opf2 is the updated file to write back to the ePub.

Is it possible to amend the content.opf file without having to unzip the ePub, amend the unzipped file, and then zip it back up again?

Thanks.

theducks 09-02-2015 06:46 PM

Dou you need to do this from a PI?
Content.opf is selectable from the file browser list and opens just like any other file.
Caution, there are no bullet proof vests while editing. WYSIWYD (what you did :eek:)

KevinH 09-02-2015 08:05 PM

Hi,

As designed, the content.opf is properly changed and maintained by all of the other calls in the bookcontainer interface. So if you could explain exactly what you are trying to change in the opf, I can explain how you might go about it with interface calls.
If what you want to do is not possible via the interface, you can get total control by unzipping a copy. See the epub_utils code available on this site for some utility routines if you end up having to do that,

KevinH

Quote:

Originally Posted by CalibUser (Post 3163114)
I want to correct errors that sometimes occur in the content.opf file. I can read this file using bk.readotherfile("OEBPS/content.opf"). However, I cannot write to this file using bk.writeotherfile("OEBPS/content.opf", opf2) where opf2 is the updated file to write back to the ePub.

Is it possible to amend the content.opf file without having to unzip the ePub, amend the unzipped file, and then zip it back up again?

Thanks.


DiapDealer 09-02-2015 08:06 PM

The content of the opf file is not directly editable through the plugin interface. This is by design. I'm not going to say this will never change, but that's the way it is right now.

The opf file is always rebuilt by the plugin interface to automatically incorporate all the changes to the various files that a plugin may have made.

Depending on what changes you need to make, there are workarounds to accomplish some things. For instance deleting a manifested file and recreating a new one (from saved data) will allow you to "rename" a manifested file.

EDIT: Scooped by 60 seconds! :D

CalibUser 09-03-2015 03:02 PM

The media files in the content .opf file should be media-type="application/xhtml+xml". However, sometimes my PDF converter produces ePub files that are of type "text/html" and this generates an error. I wanted to add something to the plugin that I am developing (see https://www.mobileread.com/forums/sho...d.php?t=264378) so that I can do a search and replace for these errors.

KevinH 09-03-2015 07:49 PM

Hi,
That is not easy to do in the current plugin interface without deleting and re-adding the file specifying the correct media-type. That said, text/html is not a valid media-type in an epub so, it may be possible to change the launcher code to auto-correct that type of failure.

Your plugin might be something better done as an input plugin that fixes things it needs to on the way into Sigil.

Let me think about it. We have already added spell checking via hunspell to the plugin interface for the next release so adding even more should not be an issue.

Kevin

CalibUser 09-05-2015 11:45 AM

Thanks, that would be useful.


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

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.