Just FYI, you can write python scripts to process epub and azw3 files using the same infrastructure the calibre editor uses, like this:
Code:
import sys
from calibre.ebooks.oeb.polish.container import get_container, OEB_STYLES
c = get_container(sys.argv[-1], tweak_mode=True)
# now for example to make changes to css files
for name, mt in c.mime_map.iteritems():
if mt in OEB_STYLES:
raw = c.open(name).read()
# do some processing on raw
c.open(name, 'wb').write(raw)
# Alternately if you wish to work witha parsed representation of the CSS
stylesheet = c.parsed(name)
# do something with stylesheet
c.dirty(name) # indicates the stylesheet has been modified, needed only if you work with the parsed representation
# Now save your changes to the epub/azw3 file (you can pass an alternate file path tocommit() to save a copy instead
c.commit()
And you run this like this
calibre-debug myscript.py file.epub
Look at polish/container.py for the various API methods of the container object as well as the other files in the polish directory to see how you can achieve various things the editor does.