aerkalov/ebooklib

How to get EPUB version number

gregoriopellegrino opened this issue · 1 comments

I am currently working on a project that involves processing EPUB files and I am using the EbookLib library to do so. I am trying to extract the version number of the EPUB file (EPUB 2 or EPUB 3, etc.), but I am not sure how to do it using this library.

Is there a specific method?

If you look at epub.py there's an attribute of the EpubBook class called EPUB_VERSION (line 549) and another one called version (line 1434). I don't know if it's a bug, but apparently EPUB_VERSION it's always set to None, therefore if you do something like

from ebooklib import epub

book = epub.read_epub("tsb.epub")
print(book.version)
print(book.EPUB_VERSION)

the output is

3.0
None

I think book.version is created after loading the file, because if you do it on a book created with the library, it throws AttributeError: 'EpubBook' object has no attribute 'version' but if you save that EPUB and then load the file created it works