This commit is contained in:
Kovid Goyal 2012-03-25 08:46:34 +05:30
parent 7a9e2050f9
commit bd4ee5c3e9
2 changed files with 16 additions and 3 deletions

View File

@ -205,7 +205,10 @@ class EXTHHeader(object):
@property
def kf8_header_index(self):
return self.get(121, None)
ans = self.get(121, None)
if ans == NULL_INDEX:
ans = None
return ans
def __str__(self):
ans = ['*'*20 + ' EXTH Header '+ '*'*20]
@ -467,9 +470,15 @@ class MOBIFile(object):
if mh.file_version >= 8:
self.kf8_type = 'standalone'
elif mh.has_exth and mh.exth.kf8_header_index is not None:
self.kf8_type = 'joint'
kf8i = mh.exth.kf8_header_index
mh8 = MOBIHeader(self.records[kf8i], kf8i)
try:
rec = self.records[kf8i-1]
except IndexError:
pass
else:
if rec.raw == b'BOUNDARY':
self.kf8_type = 'joint'
mh8 = MOBIHeader(self.records[kf8i], kf8i)
self.mobi8_header = mh8
if 'huff' in self.mobi_header.compression.lower():

View File

@ -75,6 +75,8 @@ class EXTHHeader(object): # {{{
self.mi.author_sort = au.strip()
elif idx == 101:
self.mi.publisher = content.decode(codec, 'ignore').strip()
if self.mi.publisher in {'Unknown', _('Unknown')}:
self.mi.publisher = None
elif idx == 103:
self.mi.comments = content.decode(codec, 'ignore')
elif idx == 104:
@ -98,6 +100,8 @@ class EXTHHeader(object): # {{{
self.start_offset, = struct.unpack(b'>L', content)
elif idx == 121:
self.kf8_header, = struct.unpack(b'>L', content)
if self.kf8_header == NULL_INDEX:
self.kf8_header = None
#else:
# print 'unhandled metadata record', idx, repr(content)
# }}}