-->

How to get ISBN number from .mobi file with python

2019-04-02 13:35发布

问题:

Is there any way of fetching the ISBN number from a .mobi book using python?

Maybe there is a way of reading the .mobi files directely with python and search for 10 ints which is the ISBN number? if I open the mobi file with notepad i can find the number, but when i try to read the file I get a encoding error.

回答1:

Yes.

Basically, you just need to parse the PalmDB file format. The ISBN is stored in the EXTH header field of type 104.

The Python PalmDB module I have linked above was somewhat immature when I wrote my Kindle collections manager, so I ended up implementing the relevant parts myself, see kiehinen source code for details.

If it is OK for you to use my code (It has non-contagious MIT License, should not be a problem, right?) you can just do:

>>> from kiehinen.ebook import Book
>>> b = Book("hobbit.mobi")
>>> b.exth['isbn'][0]
'9780618260300'

If not, please see the code linked above.