mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
GwR revisions
This commit is contained in:
parent
f7108d173b
commit
9ec2940174
@ -127,7 +127,6 @@ class BookHeader(object):
|
|||||||
self.length, self.type, self.codepage, self.unique_id, \
|
self.length, self.type, self.codepage, self.unique_id, \
|
||||||
self.version = struct.unpack('>LLLLL', raw[20:40])
|
self.version = struct.unpack('>LLLLL', raw[20:40])
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.codec = {
|
self.codec = {
|
||||||
1252: 'cp1252',
|
1252: 'cp1252',
|
||||||
@ -154,24 +153,31 @@ class BookHeader(object):
|
|||||||
sublangid = (langcode >> 10) & 0xFF
|
sublangid = (langcode >> 10) & 0xFF
|
||||||
self.language = main_language.get(langid, 'ENGLISH')
|
self.language = main_language.get(langid, 'ENGLISH')
|
||||||
self.sublanguage = sub_language.get(sublangid, 'NEUTRAL')
|
self.sublanguage = sub_language.get(sublangid, 'NEUTRAL')
|
||||||
self.mobi_version = struct.unpack('>I', raw[0x68:0x6c])[0]
|
|
||||||
self.first_image_index = struct.unpack('>L', raw[0x6c:0x6c + 4])[0]
|
|
||||||
|
|
||||||
self.exth_flag, = struct.unpack('>L', raw[0x80:0x84])
|
if ident == 'TEXTREAD':
|
||||||
self.exth = None
|
self.mobi_version = 1
|
||||||
if not isinstance(self.title, unicode):
|
self.first_image_index = -1
|
||||||
self.title = self.title.decode(self.codec, 'replace')
|
self.exth_flag = 0
|
||||||
if self.exth_flag & 0x40:
|
self.exth = None
|
||||||
try:
|
else:
|
||||||
self.exth = EXTHHeader(raw[16 + self.length:], self.codec, self.title)
|
self.mobi_version = struct.unpack('>I', raw[0x68:0x6c])[0]
|
||||||
self.exth.mi.uid = self.unique_id
|
self.first_image_index = struct.unpack('>L', raw[0x6c:0x6c + 4])[0]
|
||||||
|
self.exth_flag, = struct.unpack('>L', raw[0x80:0x84])
|
||||||
|
|
||||||
|
self.exth = None
|
||||||
|
if not isinstance(self.title, unicode):
|
||||||
|
self.title = self.title.decode(self.codec, 'replace')
|
||||||
|
if self.exth_flag & 0x40:
|
||||||
try:
|
try:
|
||||||
self.exth.mi.language = mobi2iana(langid, sublangid)
|
self.exth = EXTHHeader(raw[16 + self.length:], self.codec, self.title)
|
||||||
|
self.exth.mi.uid = self.unique_id
|
||||||
|
try:
|
||||||
|
self.exth.mi.language = mobi2iana(langid, sublangid)
|
||||||
|
except:
|
||||||
|
self.log.exception("'%s': Unknown language code" % getattr(stream, 'name', 'Unnamed stream'))
|
||||||
except:
|
except:
|
||||||
self.log.exception("'%s': Unknown language code" % getattr(stream, 'name', 'Unnamed stream'))
|
self.log.exception("'%s': Invalid EXTH header" % getattr(stream, 'name', 'Unnamed stream'))
|
||||||
except:
|
self.exth_flag = 0
|
||||||
self.log.exception("'%s': Invalid EXTH header" % getattr(stream, 'name', 'Unnamed stream'))
|
|
||||||
self.exth_flag = 0
|
|
||||||
|
|
||||||
|
|
||||||
class MetadataHeader(BookHeader):
|
class MetadataHeader(BookHeader):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user