View Single Post
Old 06-30-2016, 01:02 PM   #5
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,399
Karma: 27756918
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You can just do

Code:
for name, lin in container.spine_names:
   Do something with name
Although you should not rely on the fact that all html files will be in the spine, there exist books where that is not true. It's better to iterate over all items that have a mimetype in OEB_DOCS. See below:

For ToC you dont want to be using NCX/nav, instead use the functions in polish.toc, like find_existing_toc etc. Similarly for covers, you should use the functions in polish.cover


For the general request for iterating over "types of files", I can easily add an fucntion

Code:
def names_that_match_type(self, predicate):
    where predicate is an arbitrary function that takes a single argument, the media-type
To get HTML documents, you do

container.names_that_match_type(OEB_DOCS.__contain s__)

To get raster images you do

container.names_that_match_type(OEB_RASTER_IMAGES. __contains__)

for style sheets

container.names_that_match_type(OEB_STYLES.__conta ins__)


and so on...
kovidgoyal is offline   Reply With Quote